Gentoo Archives: gentoo-commits

From: Jauhien Piatlicki <piatlicki@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/g-sorcery:master commit in: g_sorcery/
Date: Thu, 01 Aug 2013 12:39:39
Message-Id: 1375357335.12987b9b5b0e24af55a7fe27816db605a3bd578e.jauhien@gentoo
1 commit: 12987b9b5b0e24af55a7fe27816db605a3bd578e
2 Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
3 AuthorDate: Thu Aug 1 11:42:15 2013 +0000
4 Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
5 CommitDate: Thu Aug 1 11:42:15 2013 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=12987b9b
7
8 g_sorcery/fileutils: Docstrings added
9
10 ---
11 g_sorcery/fileutils.py | 41 +++++++++++++++++++++++++++++++++++++++++
12 1 file changed, 41 insertions(+)
13
14 diff --git a/g_sorcery/fileutils.py b/g_sorcery/fileutils.py
15 index 7a096b1..ab42ff2 100644
16 --- a/g_sorcery/fileutils.py
17 +++ b/g_sorcery/fileutils.py
18 @@ -139,6 +139,9 @@ def get_pkgpath(root = None):
19 return os.path.dirname(os.path.abspath(root))
20
21 class ManifestEntry:
22 + """
23 + A manifest entry for a file.
24 + """
25 def __init__(self, directory, name, ftype):
26 self.directory = directory
27 self.name = name
28 @@ -146,6 +149,9 @@ class ManifestEntry:
29 self.digest()
30
31 def digest(self):
32 + """
33 + Digest a file associated with a manifest entry.
34 + """
35 h_sha256 = hashlib.new('SHA256')
36 h_sha512 = hashlib.new('SHA512')
37 h_whirlpool = hashlib.new('whirlpool')
38 @@ -161,6 +167,14 @@ class ManifestEntry:
39
40
41 def fast_manifest(directory):
42 + """
43 + Digest package directory.
44 + This function is intended to be used in place of repoman manifest,
45 + as it is to slow.
46 +
47 + Args:
48 + directory: Directory.
49 + """
50 manifest = []
51 metadata = os.path.join(directory, "metadata.xml")
52
53 @@ -181,6 +195,19 @@ def fast_manifest(directory):
54
55
56 def _call_parser(f_name, parser, open_file = True, open_mode = 'r'):
57 + """
58 + Call parser on a given file.
59 +
60 + Args:
61 + f_name: File name.
62 + parser: Parser function.
63 + open_file: Whether parser accepts a file descriptor.
64 + open_mode: Open mode for a file.
65 +
66 + Returns:
67 + A dictionary with one entry. Key if a file name, content is
68 + content returned by parser.
69 + """
70 data = None
71 if open_file:
72 with open(f_name, open_mode) as f:
73 @@ -191,6 +218,20 @@ def _call_parser(f_name, parser, open_file = True, open_mode = 'r'):
74
75
76 def load_remote_file(uri, parser, open_file = True, open_mode='r', output=""):
77 + """
78 + Load files from an URI.
79 +
80 + Args:
81 + uri: URI.
82 + parser: Parser that will be applied to downloaded files.
83 + open_file: Whether parser accepts a file descriptor.
84 + open_mode: Open mode for a file.
85 + output: What output name should downloaded file have
86 + (it will be a key identifying data loaded from this file)
87 +
88 + Returns:
89 + Dictionary with a loaded data. Key is filename, content is data returned by parser.
90 + """
91 download_dir = TemporaryDirectory()
92 loaded_data = {}
93 if wget(uri, download_dir.name, output):