1 |
commit: d42aeffc50fdee5f835b06910f0792ba079e4ddc |
2 |
Author: Andre Erdmann <dywi <AT> mailerd <DOT> de> |
3 |
AuthorDate: Wed May 30 10:56:32 2012 +0000 |
4 |
Commit: André Erdmann <dywi <AT> mailerd <DOT> de> |
5 |
CommitDate: Wed May 30 10:58:23 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=d42aeffc |
7 |
|
8 |
roverlay, ebuildjob: fix imports, run () creates an ebuild now |
9 |
|
10 |
--- |
11 |
roverlay/ebuildjob.py | 105 ++++++++++++++++++++++++++++++++++++++++++------- |
12 |
1 files changed, 90 insertions(+), 15 deletions(-) |
13 |
|
14 |
diff --git a/roverlay/ebuildjob.py b/roverlay/ebuildjob.py |
15 |
index 0861b22..171150c 100644 |
16 |
--- a/roverlay/ebuildjob.py |
17 |
+++ b/roverlay/ebuildjob.py |
18 |
@@ -2,11 +2,12 @@ |
19 |
# Copyright 2006-2012 Gentoo Foundation |
20 |
# Distributed under the terms of the GNU General Public License v2 |
21 |
|
22 |
-from roverlay import ebuildcreator.EbuildCreator |
23 |
-from roverlay import fileio.DescriptionReader |
24 |
-from roverlay import ebuild.Ebuild |
25 |
+from roverlay.fileio import DescriptionReader |
26 |
+from roverlay.ebuild import Ebuild |
27 |
|
28 |
class EbuildJob: |
29 |
+ STATUS_LIST = [ 'INIT', 'BUSY', 'WAIT', 'SUCCESS', 'FAIL' ] |
30 |
+ STATUS_MAP = dict ( ( name, code ) for code, name in enumerate ( STATUS_LIST ) ) |
31 |
|
32 |
@classmethod |
33 |
def __init__ ( self, package_file, dep_resolver=None ): |
34 |
@@ -14,10 +15,26 @@ class EbuildJob: |
35 |
self.dep_resolver = dep_resolver |
36 |
# get description reader from args? |
37 |
self.description_reader = DescriptionReader() |
38 |
- self.ebuild = Ebuild() |
39 |
|
40 |
- self.status = 0 # todo |
41 |
+ self.ebuild = None |
42 |
|
43 |
+ self._status = 0 # todo |
44 |
+ |
45 |
+ # --- end of __init__ (...) --- |
46 |
+ |
47 |
+ @staticmethod |
48 |
+ def get_statuscode ( status_id ): |
49 |
+ if status_id == 'ALL': |
50 |
+ return EbuildJob.STATUS_LIST |
51 |
+ elif isinstance ( status_id, int ): |
52 |
+ if status_id > 0 and status_id < len ( STATUS_LIST ): |
53 |
+ return EbuildJob.STATUS_LIST [status_id] |
54 |
+ elif status_id in EbuildJob.STATUS_MAP: |
55 |
+ return EbuildJob.STATUS_MAP [status_id] |
56 |
+ |
57 |
+ return None |
58 |
+ |
59 |
+ # --- end of get_statuscode (...) --- |
60 |
|
61 |
@classmethod |
62 |
def status ( self, expected_status=None ): |
63 |
@@ -28,18 +45,35 @@ class EbuildJob: |
64 |
* expected_status -- if not None: check if this job's state is expected_status |
65 |
""" |
66 |
if expected_status: |
67 |
- return self.status |
68 |
- else: |
69 |
- return bool ( self.status == expected_status ) |
70 |
+ if isinstance ( expected_status, int ): |
71 |
+ return bool ( self._status == expected_status ) |
72 |
+ elif expected_status in EbuildJob.STATUS_MAP: |
73 |
+ return bool ( self._status == EbuildJob.STATUS_MAP [expected_status] ) |
74 |
+ else: |
75 |
+ return False |
76 |
+ |
77 |
+ return self._status |
78 |
+ |
79 |
+ # --- end of status (...) --- |
80 |
|
81 |
@classmethod |
82 |
def get_ebuild ( self ): |
83 |
"""Returns the Ebuild that is created by this object. Note that you should |
84 |
check the status with status ( $TODO::EBUILD_READY ) before trying to use |
85 |
the Ebuild. |
86 |
+ ##fixme: it is guaranteed that self.ebuild is None unless the Ebuild is successfully created## |
87 |
""" |
88 |
return self.ebuild |
89 |
|
90 |
+ # --- end of get_ebuild (...) --- |
91 |
+ |
92 |
+ @classmethod |
93 |
+ def _set_status ( self, new_status ): |
94 |
+ self._status = EbuildJob.get_statuscode ( new_status ) |
95 |
+ return True |
96 |
+ |
97 |
+ # --- end of _set_status (...) --- |
98 |
+ |
99 |
|
100 |
@classmethod |
101 |
def run ( self ): |
102 |
@@ -49,17 +83,58 @@ class EbuildJob: |
103 |
""" |
104 |
|
105 |
# check status |
106 |
- ## |
107 |
+ if not self.status ( 'INIT' ): |
108 |
+ return |
109 |
+ |
110 |
+ if not self._set_status ( 'BUSY' ): |
111 |
+ return False |
112 |
|
113 |
read_data = self.description_reader.readfile ( self.package_file ) |
114 |
|
115 |
- if read_data is None |
116 |
+ if read_data is None: |
117 |
# set status accordingly |
118 |
- return None |
119 |
+ self._set_status ( 'FAIL' ) |
120 |
+ return False |
121 |
|
122 |
- # transfer data from read_data to self.ebuild |
123 |
- # have to resolve deps here |
124 |
- # <TODO> |
125 |
+ fileinfo = read_data ['fileinfo'] |
126 |
+ desc = read_data ['description_data'] |
127 |
+ |
128 |
+ ebuild = Ebuild() |
129 |
+ |
130 |
+ have_description = False |
131 |
+ |
132 |
+ print ( str ( desc ) ) |
133 |
+ |
134 |
+ if 'Title' in desc: |
135 |
+ have_description = True |
136 |
+ ebuild.add ( 'DESCRIPTION', desc ['Title'] ) |
137 |
+ |
138 |
+ if 'Description' in desc: |
139 |
+ have_description = True |
140 |
+ ebuild.add ( 'DESCRIPTION', ( '// ' if have_description else '' ) + desc ['Description'] ) |
141 |
+ |
142 |
+ if not have_description: |
143 |
+ ebuild.add ( 'DESCRIPTION', '<none>' ) |
144 |
+ del have_description |
145 |
+ |
146 |
+ # origin is todo (sync module knows the package origin) |
147 |
+ ebuild.add ( 'PKG_ORIGIN', 'CRAN' ) |
148 |
+ |
149 |
+ ebuild.add ( 'PKG_FILE', fileinfo ['package_file'] ) |
150 |
+ |
151 |
+ ebuild.add ( 'ebuild_header', [ '# test header' ], False ) |
152 |
+ |
153 |
+ ## have to resolve deps here |
154 |
+ |
155 |
+ # enter status that allows transferring ebuild -> self.ebuild |
156 |
+ if self._set_status ( 'WAIT' ): |
157 |
+ # finalize self.ebuild: forced text creation + make it readonly |
158 |
+ if ebuild.prepare ( True, True ): |
159 |
+ self.ebuild = ebuild |
160 |
+ return self._set_status ( 'SUCCESS' ) |
161 |
+ |
162 |
+ self._set_status ( 'FAIL' ) |
163 |
+ return False |
164 |
|
165 |
- return None |
166 |
|
167 |
+ # --- end of run (...) --- |