Package magma :: Package magma
[hide private]
[frames] | no frames]

Package magma

source code

MAGnet MAnifest Management - Readout and create lists of magnets in yaml format.

Magma lists are lists of files which can be downloaded via magnet links.

They are written in yaml format to be easily readable as well as flexible and powerful.

A simple Magma file looks like the following:

   #MAGMAv0.4
   files:
   - filename: input_file.txt
     urn:
       sha1: 3UJCLAOIZVCNAIT7TQYFLAP7ZNFW6G2G
   - filename: input_file2.txt
     urn:
       sha1: 3UJCLAOIZVCNAIT7TQYFLAP7ZNFW6G2G

This script parses the basic features of MAGMAv0.4, which is being specified at the moment. It doesn't parse the current MAGMAv0.2 files!

Use it only, if you want to take a peek at what the updated specification will bring.

It depends on pyyaml, tagpy and IPy.

An example magma file is example-0.4.magma.

This API documentation is avaible from http://gnuticles.gnufu.net/pymagma/, and the code is avaible from a Mercurial repository.

The module can also be found in the Python Package Index (PyPI). It is available under the GPL-3 or later.

It is being written by Arne Babenhauserheide. If you wish to contribute, please drop me a mail with the word "tunnel" somewhere in the subject line (to get past my spamfilter). My email: arne_bab at web de .

Usage of this module

>>> # from magma import *
>>> magma = open_file("example-0.4.magma")

or

>>> magma = create_from_input_files(["input_file.txt", "input_file2.txt"])

API / usage

Creating magma lists from input files

Create a list from input files.

>>> magma = create_from_input_files(["input_file.txt"])

Output the list, showing the empty entries, which could be filled with data.

>>> print magma
#MAGMAv0.4
files:
- filename: input_file.txt
  gnutella:
    alt-locs: []
  urls: []
  urn:
    sha1: 3UJCLAOIZVCNAIT7TQYFLAP7ZNFW6G2G
<BLANKLINE>
# Magmav0.2 compatibility section
list:
 - "magnet:?xt=urn%3Asha1%3A3UJCLAOIZVCNAIT7TQYFLAP7ZNFW6G2G&dn=input_file.txt"
<BLANKLINE>

And save it to a file with the empty entries cleaned away.

>>> magma.save(path="example.magma")

Or just return a list of its files as MagmaFiles.

>>> files = magma.files

Or output all magnet links inside the magma list.

>>> print magma.magnets
['magnet:?xt=urn%3Asha1%3A3UJCLAOIZVCNAIT7TQYFLAP7ZNFW6G2G&dn=input_file.txt']

Reading from magma lists

Readout the data from a file.

>>> magma = open_file("example.magma")

Now get the files inside the list.

>>> files = magma.files
>>> for i in files: print i
input_file.txt 3UJCLAOIZVCNAIT7TQYFLAP7ZNFW6G2G

Get the first file from the list.

>>> one_file = files[0]
>>> print one_file
input_file.txt 3UJCLAOIZVCNAIT7TQYFLAP7ZNFW6G2G

And output its magnet.

>>> print one_file.magnet
magnet:?xt=urn%3Asha1%3A3UJCLAOIZVCNAIT7TQYFLAP7ZNFW6G2G&dn=input_file.txt

Or output all its (meta-) data.

>>> print one_file.data
{'urn': {'sha1': '3UJCLAOIZVCNAIT7TQYFLAP7ZNFW6G2G'}, 'gnutella': {'alt-locs': []}, 'urls': [], 'filename': 'input_file.txt'}

Output all magnet links inside the magma list.

>>> print magma.magnets
['magnet:?xt=urn%3Asha1%3A3UJCLAOIZVCNAIT7TQYFLAP7ZNFW6G2G&dn=input_file.txt']

Load a Magma object from a string containing Magma data via magma.load(). As test, load a minimal Magma file, containing nothing but the header.

>>> magma = load("#MAGMAv0.4")

And cry out, if the string doesn't begin with the Magma header (isn't Magma data!).

>>> magma = load("a:b")
Traceback (most recent call last):
...
AssertionError: Doesn't begin with Magma v0.4 header #MAGMAv0.4

Also dump yaml data via magma.dump()

>>> print dump(magma)
#MAGMAv0.4
{}
<BLANKLINE>
# Magmav0.2 compatibility section
list:
<BLANKLINE>

Or just print the Magma data.

>>> print magma
#MAGMAv0.4
{}
<BLANKLINE>
# Magmav0.2 compatibility section
list:
<BLANKLINE>

Plans: Gnutella

Ideas:


Version: 0.3.9

Date: 2008-05-09

Author: Arne Babenhauserheide

Copyright: Copyright (C) 2008 Arne Babenhauserheide

Submodules [hide private]

Functions [hide private]
 
parse_dependencies(init_depends)
Aggregate the dependencies from all submodules.
source code
 
open_file(filepath)
Open a file as Magma list and produce the corresponding Python object.
source code
 
create_from_input_files(files)
Create a magma file from given input files.
source code
 
load(yaml_data)
Parse a Magma list and produce the corresponding Python object.
source code
 
dump(magma)
Return the string representation of the Magma file.
source code
 
_test()
Do all doctests.
source code
Variables [hide private]
  __licence__ = 'GPL-3 or later'
  __program__ = 'MAGnet MAnifest Management'
  __depends__ = 'yaml, hashlib, base64, os'
Function Details [hide private]

parse_dependencies(init_depends)

source code 

Aggregate the dependencies from all submodules.

Parameters:
  • init_depends (String) - The dependencies of the __init__ file.
Returns:
A string with dependencies, seperated by ', '.

open_file(filepath)

source code 

Open a file as Magma list and produce the corresponding Python object.

Parameters:
  • filepath (String) - The path to a Magma file.
Returns:
A Magma Object.

create_from_input_files(files)

source code 

Create a magma file from given input files.

Parameters:
  • files (List of Strings) - A list of file paths
Returns:
A Magma Object.

load(yaml_data)

source code 

Parse a Magma list and produce the corresponding Python object.

Parameters:
  • yaml_data (String) - Data read from a yaml file
Returns:
A Magma Object.

dump(magma)

source code 

Return the string representation of the Magma file.

Parameters:
  • magma (magma.Magma) - A Magma object.
Returns:
A String represenation of the Magma file (in yaml format).

_test()

source code 

Do all doctests.

Returns:
None