1 |
commit: 87eefca1205a1952abedba2ab8c8b0cbe7b35842 |
2 |
Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Jun 17 03:08:29 2014 +0000 |
4 |
Commit: Devan Franchini <twitch153 <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Jun 19 03:49:57 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=87eefca1 |
7 |
|
8 |
layman.py: Moves API initialization to separate function |
9 |
|
10 |
Also adds new() function for subprocess variant of layman plugin |
11 |
module. |
12 |
|
13 |
--- |
14 |
layman/sync/layman.py | 77 ++++++++++++++++++++++++++++++++++++--------------- |
15 |
1 file changed, 55 insertions(+), 22 deletions(-) |
16 |
|
17 |
diff --git a/layman/sync/layman.py b/layman/sync/layman.py |
18 |
index 7adf8c6..dac9569 100644 |
19 |
--- a/layman/sync/layman.py |
20 |
+++ b/layman/sync/layman.py |
21 |
@@ -33,29 +33,59 @@ class Layman(SyncBase): |
22 |
SyncBase.__init__(self, 'layman', 'app-portage/layman') |
23 |
|
24 |
|
25 |
+ def _get_optargs(self, args): |
26 |
+ if self.settings: |
27 |
+ if self.settings.get('NOCOLOR'): |
28 |
+ args.append('-N') |
29 |
+ if self.settings.get('PORTAGE_QUIET'): |
30 |
+ args.append('-q') |
31 |
+ |
32 |
def new(self, **kwargs): |
33 |
'''Do the initial download and install of the repository''' |
34 |
- pass |
35 |
+ if kwargs: |
36 |
+ self._kwargs(kwargs) |
37 |
+ emerge_config = self.options.get('emerge_config', None) |
38 |
+ portdb = self.options.get('portdb', None) |
39 |
+ args = [] |
40 |
+ msg = '>>> Starting to add new layman overlay %(repo)s' % ({'repo': self.repo.name}) |
41 |
+ self.logger(self.xterm_titles, msg) |
42 |
+ writemsg_level(msg + '\n') |
43 |
|
44 |
+ args.append('layman -n') |
45 |
+ self._get_optargs(args) |
46 |
+ args.append('-a') |
47 |
+ args.append(self.repo.name) |
48 |
+ |
49 |
+ command = ' '.join(args) |
50 |
+ |
51 |
+ exitcode = portage.process.spawn_bash("%(command)s" % \ |
52 |
+ ({'command': command}), |
53 |
+ **portage._native_kwargs(self.spawn_kwargs)) |
54 |
+ if exitcode != os.EX_OK: |
55 |
+ msg = "!!! layman sync error in %(repo)s" % ({'repo': self.repo.name}) |
56 |
+ self.logger(self.xterm_titles, msg) |
57 |
+ writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1) |
58 |
+ return (exitcode, False) |
59 |
+ msg = ">>> Addition of layman repo succeeded: %(repo)s" % ({'repo': self.repo.name}) |
60 |
+ self.logger(self.xterm_titles, msg) |
61 |
+ writemsg_level(msg + "\n") |
62 |
+ |
63 |
+ return (exitcode, True) |
64 |
|
65 |
def _sync(self): |
66 |
''' Update existing repository''' |
67 |
emerge_config = self.options.get('emerge_config', None) |
68 |
portdb = self.options.get('portdb', None) |
69 |
args = [] |
70 |
- msg = '>>> Starting layman sync for %s...' % self.repo.location |
71 |
+ msg = '>>> Starting layman sync for %s...' % self.repo.name |
72 |
self.logger(self.xterm_titles, msg) |
73 |
writemsg_level(msg + '\n') |
74 |
- args.append('layman -n') |
75 |
- |
76 |
- if self.settings: |
77 |
- if self.settings.get('NOCOLOR'): |
78 |
- args.append('-N') |
79 |
- if self.settings.get('PORTAGE_QUIET'): |
80 |
- args.append('-q') |
81 |
|
82 |
+ args.append('layman -n') |
83 |
+ self._get_optargs(args) |
84 |
args.append('-s') |
85 |
args.append(self.repo.name) |
86 |
+ |
87 |
exitcode = portage.process.spawn_bash("%s" % \ |
88 |
(' '.join(args)), |
89 |
**portage._native_kwargs(self.spawn_kwargs)) |
90 |
@@ -81,30 +111,33 @@ class PyLayman(SyncBase): |
91 |
return "Layman" |
92 |
|
93 |
def __init__(self): |
94 |
+ SyncBase.__init__(self, 'layman', 'app-portage/layman') |
95 |
|
96 |
- SyncBase.__init__(self, '', 'app-portage/layman') |
97 |
+ |
98 |
+ def _get_layman_api(self): |
99 |
|
100 |
config = BareConfig() |
101 |
self.message = Message(out=sys.stdout, err=sys.stderr) |
102 |
- |
103 |
+ |
104 |
options = { |
105 |
'config': config.get_option('config'), |
106 |
- 'quiet': portage.settings.get('PORTAGE_QUIET'), |
107 |
+ 'quiet': self.settings.get('PORTAGE_QUIET'), |
108 |
'quietness': config.get_option('quietness'), |
109 |
'output': self.message, |
110 |
- 'nocolor': portage.settings.get('NOCOLOR'), |
111 |
- 'root': portage.settings.get('EROOT'), |
112 |
- 'verbose': portage.settings.get('PORTAGE_VERBOSE'), |
113 |
- 'width': portage.settings.get('COLUMNWIDTH'), |
114 |
+ 'nocolor': self.settings.get('NOCOLOR'), |
115 |
+ 'root': self.settings.get('EROOT'), |
116 |
+ 'verbose': self.settings.get('PORTAGE_VERBOSE'), |
117 |
+ 'width': self.settings.get('COLUMNWIDTH'), |
118 |
|
119 |
} |
120 |
|
121 |
self.config = OptionConfig(options=options) |
122 |
- |
123 |
- LaymanAPI.__init__(self, self.config, |
124 |
- report_errors=True, |
125 |
- output=self.config['output'] |
126 |
- ) |
127 |
+ |
128 |
+ layman_api = LaymanAPI(self.config, |
129 |
+ report_errors=True, |
130 |
+ output=self.config['output'] |
131 |
+ ) |
132 |
+ return layman_api |
133 |
|
134 |
def new(self, **kwargs): |
135 |
'''Do the initial download and install of the repository''' |
136 |
@@ -113,4 +146,4 @@ class PyLayman(SyncBase): |
137 |
|
138 |
def _sync(self): |
139 |
''' Update existing repository''' |
140 |
- pass |
141 |
+ layman_inst = self._get_layman_api() |