Package magma ::
Package magma ::
Module create_simple_magma_list
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """
22 Returns a magma-list containing the file name. Takes the names as input.
23
24 # Test strip_dirname
25
26 >>> a = "blah/blubb/bangala/goi.gis"
27 >>> print strip_dirname(a)
28 goi.gis
29
30 >>> a = "/blah/blubb/bangala/goi.gis"
31 >>> print strip_dirname(a)
32 goi.gis
33
34 """
35
36 __depends__ = 'yaml, os'
37
38
39
40
41 FILE_LIST_NAME = "files"
42
43 URN_PARAMETER_NAME = "urn"
44
45 MAGMA_0_4_HEADER = "#MAGMAv0.4"
46
47
48 FILENAME_PARAMETER = "filename"
49
50
51
52 from sha1_gnutella import sha1_gnutella
53
54 from yaml import dump, load
55
56 from os.path import dirname
57
59 """Strip everything but the name of the file.
60
61 @param path: A path to a file.
62 @type path: String
63 @return: The name of the file, stripped of anything before it.
64
65 Example: /home/blah/blubb.magma becomes
66
67 blubb.magma
68 """
69
70 if len(dirname(path)) > 0:
71 filename = path[len(dirname(path)) + 1:]
72 else:
73 filename = path
74 return filename
75
77 """A Simple Magma object created from a list of input file paths."""
78 - def __init__(self, inputfilenames, *args, **kwds):
79 """A Simple Magma object created from a list of input file paths.
80
81 @param inputfilenames: The paths to the files to hash.
82 @type inputfilenames: List
83 """
84
85 self.filenames = inputfilenames
86
87 self.sha1 = {}
88
89 for i in self.filenames:
90 self.sha1[i] = sha1_gnutella(i)
91
92 self.data = self.data()
93
94 self.magma = self.magma()
95
110
112 """Dump the yaml representation of the file with a MAGMA header as string.
113
114 @return: A string representation of the Magma file (in yaml format). """
115 return MAGMA_0_4_HEADER + "\n" + dump(self.data, default_flow_style=False)
116
118 """Do all doctests
119
120 @return: None
121 """
122 from doctest import testmod
123 testmod()
124
125
126 if __name__ == '__main__':
127 from sys import argv
128 if len(argv) > 1:
129 filenames = argv[1:]
130 else:
131
132 filenames = [raw_input("Dateiname und Pfad eingeben: ")]
133 gnutella_client_ip = raw_input("Eigene IP oder dyndns-Adresse eingeben: ")
134 magma = Magma(filenames)
135 print magma.magma
136
137
138 _test()
139