Home | Trees | Indices | Help |
|
---|
|
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 .
>>> # from magma import * >>> magma = open_file("example-0.4.magma")
or
>>> magma = create_from_input_files(["input_file.txt", "input_file2.txt"])
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
|
|||
|
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
|||
__licence__ =
|
|||
__program__ =
|
|||
__depends__ =
|
|
Aggregate the dependencies from all submodules.
|
Open a file as Magma list and produce the corresponding Python object.
|
Create a magma file from given input files.
|
Parse a Magma list and produce the corresponding Python object.
|
Return the string representation of the Magma file.
|
Do all doctests.
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Jan 7 11:36:57 2009 | http://epydoc.sourceforge.net |