1 |
commit: 3768929c2b516df97e7d3d45ed41a44487f81790 |
2 |
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com> |
3 |
AuthorDate: Thu Aug 1 12:33:52 2013 +0000 |
4 |
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com> |
5 |
CommitDate: Thu Aug 1 12:33:52 2013 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=3768929c |
7 |
|
8 |
g_sorcery/g_sorcery: Docstrings added |
9 |
|
10 |
--- |
11 |
g_sorcery/package_db.py | 156 +++++++++++++++++++++++++++++++++++++++++++++--- |
12 |
1 file changed, 148 insertions(+), 8 deletions(-) |
13 |
|
14 |
diff --git a/g_sorcery/package_db.py b/g_sorcery/package_db.py |
15 |
index 35bad48..3f2993a 100644 |
16 |
--- a/g_sorcery/package_db.py |
17 |
+++ b/g_sorcery/package_db.py |
18 |
@@ -38,8 +38,6 @@ class PackageDB(object): |
19 |
~~~~~~~~~~~~~~~~~ |
20 |
db dir |
21 |
manifest.json: database manifest |
22 |
- uri.json: URIes |
23 |
- info.json: information about database |
24 |
categories.json: information about categories |
25 |
category1 |
26 |
packages.json: list of packages |
27 |
@@ -113,8 +111,6 @@ class PackageDB(object): |
28 |
""" |
29 |
Args: |
30 |
directory: database directory. |
31 |
- repo_uri: Repository URI. |
32 |
- db_uri: URI for synchronization with remote database. |
33 |
""" |
34 |
self.CATEGORIES_NAME = 'categories.json' |
35 |
self.PACKAGES_NAME = 'packages.json' |
36 |
@@ -462,6 +458,12 @@ class PackageDB(object): |
37 |
return res |
38 |
|
39 |
def list_catpkg_names(self): |
40 |
+ """ |
41 |
+ List category/package entries. |
42 |
+ |
43 |
+ Returns: |
44 |
+ List with category/package entries. |
45 |
+ """ |
46 |
return list(self.database) |
47 |
|
48 |
def list_package_versions(self, category, name): |
49 |
@@ -498,13 +500,13 @@ class PackageDB(object): |
50 |
|
51 |
def get_package_description(self, package): |
52 |
""" |
53 |
- Get package description. |
54 |
+ Get package ebuild data. |
55 |
|
56 |
Args: |
57 |
package: package_db.Package instance. |
58 |
|
59 |
Returns: |
60 |
- Dictionary with package description. |
61 |
+ Dictionary with package ebuild data. |
62 |
""" |
63 |
#a possible exception should be catched in the caller |
64 |
return self.database[package.category + '/' + package.name][package.version] |
65 |
@@ -544,6 +546,29 @@ class DBGenerator(object): |
66 |
self.package_db_class = package_db_class |
67 |
|
68 |
def __call__(self, directory, repository, common_config=None, config=None, generate=True): |
69 |
+ """ |
70 |
+ Get a package database. |
71 |
+ |
72 |
+ A directory layout looks like: |
73 |
+ backend directory |
74 |
+ config.json |
75 |
+ repo1 dir |
76 |
+ config.json |
77 |
+ db - directory with database |
78 |
+ repo2 dir |
79 |
+ config.json |
80 |
+ db - directory with database |
81 |
+ |
82 |
+ Args: |
83 |
+ directory: Directory for package databases (backend directory). |
84 |
+ repository: Repository name. |
85 |
+ common_config: Backend config. |
86 |
+ config: Repository config. |
87 |
+ generate: Whether package tree should be generated. |
88 |
+ |
89 |
+ Returns: |
90 |
+ Package database. |
91 |
+ """ |
92 |
db_path = os.path.join(directory, repository, "db") |
93 |
pkg_db = self.package_db_class(db_path) |
94 |
|
95 |
@@ -567,10 +592,28 @@ class DBGenerator(object): |
96 |
return pkg_db |
97 |
|
98 |
def generate_tree(self, pkg_db, common_config, config): |
99 |
+ """ |
100 |
+ Generate package entries. |
101 |
+ |
102 |
+ Args: |
103 |
+ pkg_db: Package database. |
104 |
+ common_config: Backend config. |
105 |
+ config: Repository config. |
106 |
+ """ |
107 |
data = self.download_data(common_config, config) |
108 |
self.process_data(pkg_db, data, common_config, config) |
109 |
|
110 |
def download_data(self, common_config, config): |
111 |
+ """ |
112 |
+ Obtain data for database generation. |
113 |
+ |
114 |
+ Args: |
115 |
+ common_config: Backend config. |
116 |
+ config: Repository config. |
117 |
+ |
118 |
+ Returns: |
119 |
+ Downloaded data. |
120 |
+ """ |
121 |
uries = self.get_download_uries(common_config, config) |
122 |
uries = self.decode_download_uries(uries) |
123 |
data = {} |
124 |
@@ -579,12 +622,47 @@ class DBGenerator(object): |
125 |
return data |
126 |
|
127 |
def process_uri(self, uri, data): |
128 |
+ """ |
129 |
+ Download and parse data from a given URI. |
130 |
+ |
131 |
+ Args: |
132 |
+ uri: URI. |
133 |
+ data: Data dictionary. |
134 |
+ """ |
135 |
data.update(load_remote_file(**uri)) |
136 |
|
137 |
def get_download_uries(self, common_config, config): |
138 |
+ """ |
139 |
+ Get uries to download from. |
140 |
+ |
141 |
+ Args: |
142 |
+ common_config: Backend config. |
143 |
+ config: Repository config. |
144 |
+ |
145 |
+ Returns: |
146 |
+ List with URI entries. |
147 |
+ Each entry has one of the following formats: |
148 |
+ 1. String with URI. |
149 |
+ 2. A dictionary with entries: |
150 |
+ - uri: URI. |
151 |
+ - parser: Parser to be applied to downloaded data. |
152 |
+ - open_file: Whether parser accepts file objects. |
153 |
+ - open_mode: Open mode for a downloaded file. |
154 |
+ The only mandatory entry is uri. |
155 |
+ """ |
156 |
return [config["repo_uri"]] |
157 |
|
158 |
def decode_download_uries(self, uries): |
159 |
+ """ |
160 |
+ Convert URI list with incomplete and string entries |
161 |
+ into list with complete dictionary entries. |
162 |
+ |
163 |
+ Args: |
164 |
+ uries: List of URIes. |
165 |
+ |
166 |
+ Returns: |
167 |
+ List of URIes with dictionary entries. |
168 |
+ """ |
169 |
decoded = [] |
170 |
for uri in uries: |
171 |
decuri = {} |
172 |
@@ -604,13 +682,45 @@ class DBGenerator(object): |
173 |
decoded.append(decuri) |
174 |
return decoded |
175 |
|
176 |
- def parse_data(self): |
177 |
- pass #todo: raise no implemeted or add some reasonable default |
178 |
+ def parse_data(self, data_file): |
179 |
+ """ |
180 |
+ Parse downloaded data. |
181 |
+ |
182 |
+ Args: |
183 |
+ data_file: File name of open file object. |
184 |
+ |
185 |
+ Returns: |
186 |
+ Parsed data. |
187 |
+ """ |
188 |
+ raise NotImplementedError |
189 |
|
190 |
def process_data(self, pkg_db, data, common_config, config): |
191 |
+ """ |
192 |
+ Process downloaded data and fill database. |
193 |
+ |
194 |
+ Args: |
195 |
+ pkg_db: Package database. |
196 |
+ data: Dictionary with data, keys are file names. |
197 |
+ common_config; Backend config. |
198 |
+ config: Repository config. |
199 |
+ """ |
200 |
pass |
201 |
|
202 |
def convert(self, configs, dict_name, value): |
203 |
+ """ |
204 |
+ Convert a value using configs. |
205 |
+ This function is aimed to be used for conversion |
206 |
+ of values such as license or package names. |
207 |
+ |
208 |
+ Args: |
209 |
+ configs: List of configs. |
210 |
+ dict_name: Name of a dictionary in config |
211 |
+ that should be used for conversion. |
212 |
+ value: Value to convert. |
213 |
+ |
214 |
+ Returns: |
215 |
+ Converted value. |
216 |
+ """ |
217 |
result = value |
218 |
for config in configs: |
219 |
if config: |
220 |
@@ -621,6 +731,18 @@ class DBGenerator(object): |
221 |
return result |
222 |
|
223 |
def convert_dependency(self, configs, dependency, external=True): |
224 |
+ """ |
225 |
+ Convert dependency. |
226 |
+ |
227 |
+ Args: |
228 |
+ configs: List of configs. |
229 |
+ dependency: Dependency to be converted. |
230 |
+ external: Whether external deps should be keeped. |
231 |
+ |
232 |
+ Returns: |
233 |
+ Right dependency name or None if dependency is external and |
234 |
+ external == False. |
235 |
+ """ |
236 |
external_dep = "" |
237 |
for config in configs: |
238 |
if config: |
239 |
@@ -637,12 +759,30 @@ class DBGenerator(object): |
240 |
return self.convert_internal_dependency(configs, dependency) |
241 |
|
242 |
def convert_internal_dependency(self, configs, dependency): |
243 |
+ """ |
244 |
+ Hook to convert internal dependencies. |
245 |
+ """ |
246 |
return dependency |
247 |
|
248 |
def convert_external_dependency(self, configs, dependency): |
249 |
+ """ |
250 |
+ Hook to convert external dependencies. |
251 |
+ """ |
252 |
return dependency |
253 |
|
254 |
def in_config(self, configs, list_name, value): |
255 |
+ """ |
256 |
+ Check whether value is in config. |
257 |
+ |
258 |
+ Args: |
259 |
+ configs: List of configs. |
260 |
+ list_name: Name of a list in config |
261 |
+ that should be used for checking. |
262 |
+ value: Value to look for. |
263 |
+ |
264 |
+ Returns: |
265 |
+ Boolean. |
266 |
+ """ |
267 |
result = False |
268 |
for config in configs: |
269 |
if config: |