1 |
commit: 9b3c6b3190df328d8a72e6cb6833b13a6819dbbb |
2 |
Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Feb 4 17:55:25 2015 +0000 |
4 |
Commit: Devan Franchini <twitch153 <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Feb 4 17:55:27 2015 +0000 |
6 |
URL: http://sources.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=9b3c6b31 |
7 |
|
8 |
reposconf.py: Rewrites enable() and disable() functions |
9 |
|
10 |
The enable() function was cleaned up and the doc string was improved to |
11 |
reflect what the function actually does. The previous behavior of the |
12 |
disable function was completely replaced in favor of being a wrapper for |
13 |
the delete() function. The reasoning behind this is that previously the |
14 |
function would simply "comment" out the section and its lines. This lead |
15 |
to an issue where the config manager would no longer list the sections, |
16 |
causing them to no longer be in the repos.conf file if the file was |
17 |
rewritten to by layman for any reason. So commenting the sections out |
18 |
was more work than needed anyway. |
19 |
|
20 |
--- |
21 |
layman/config_modules/reposconf/reposconf.py | 40 +++++----------------------- |
22 |
1 file changed, 6 insertions(+), 34 deletions(-) |
23 |
|
24 |
diff --git a/layman/config_modules/reposconf/reposconf.py b/layman/config_modules/reposconf/reposconf.py |
25 |
index cdf5dba..4cb27f8 100644 |
26 |
--- a/layman/config_modules/reposconf/reposconf.py |
27 |
+++ b/layman/config_modules/reposconf/reposconf.py |
28 |
@@ -116,46 +116,22 @@ class ConfigHandler: |
29 |
|
30 |
def disable(self, overlay): |
31 |
''' |
32 |
- Disables a repos.conf entry. |
33 |
+ A wrapper for the delete() function to comply with RepoConfManager class. |
34 |
|
35 |
@param overlay: layman.overlay.Overlay instance. |
36 |
@rtype boolean: reflects a successful/failed write to the config file. |
37 |
''' |
38 |
- if not self.repo_conf.has_section(overlay.name): |
39 |
- self.output.error('ReposConf: ConfigHandler.disable(); failed '\ |
40 |
- 'to disable "%(repo)s". Section does not exist.'\ |
41 |
- % ({'repo': overlay.name})) |
42 |
- return False |
43 |
- self.repo_conf.remove_section(overlay.name) |
44 |
- current_date = time.strftime('%x') + ' | ' + time.strftime('%X') |
45 |
- |
46 |
- self.repo_conf.add_section(overlay.name) |
47 |
- self.repo_conf.set(overlay.name, '#date disabled', current_date) |
48 |
- self.repo_conf.set(overlay.name, '#priority', str(overlay.priority)) |
49 |
- self.repo_conf.set(overlay.name, '#location', path((self.storage, overlay.name))) |
50 |
- self.repo_conf.set(overlay.name, '#layman-type', overlay.sources[0].type_key) |
51 |
- if sync_type: |
52 |
- self.repo_conf.set(overlay.name, '#sync_type', sync_type) |
53 |
- self.repo_conf.set(overlay.name, '#sync-uri', overlay.sources[0].src) |
54 |
- if overlay.sources[0].branch: |
55 |
- self.repo_conf.set(overlay.name, '#branch', overlay.sources[0].branch) |
56 |
- if sync_type: |
57 |
- self.repo_conf.set(overlay.name, '#auto-sync', self.config['auto_sync']) |
58 |
- |
59 |
- return self.write(disable=overlay.name) |
60 |
+ return self.delete(overlay) |
61 |
|
62 |
|
63 |
def enable(self, overlay): |
64 |
''' |
65 |
- Enables a disabled repos.conf entry. |
66 |
+ A wrapper for the add() function to comply with RepoConfManager class. |
67 |
|
68 |
@param overlay: layman.overlay.Overlay instance. |
69 |
@rtype boolean: reflects a successful/failed write to the config file. |
70 |
''' |
71 |
- self.repo_conf.remove_section(overlay.name) |
72 |
- success = self.add(overlay) |
73 |
- |
74 |
- return success |
75 |
+ return self.add(overlay) |
76 |
|
77 |
|
78 |
def update(self, overlay): |
79 |
@@ -170,11 +146,11 @@ class ConfigHandler: |
80 |
return self.write() |
81 |
|
82 |
|
83 |
- def write(self, delete=None, disable=None): |
84 |
+ def write(self, delete=None): |
85 |
''' |
86 |
Writes changes from ConfigParser to /etc/portage/repos.conf/layman.conf. |
87 |
|
88 |
- @params disable: overlay name to be disabled. |
89 |
+ @params delete: overlay name to be delete from the config. |
90 |
@return boolean: represents a successful write. |
91 |
''' |
92 |
try: |
93 |
@@ -186,10 +162,6 @@ class ConfigHandler: |
94 |
if not i == delete: |
95 |
self.add(self.overlays[i]) |
96 |
self.repo_conf.write(laymanconf) |
97 |
- if disable: |
98 |
- # comments out section header of the overlay. |
99 |
- subprocess.call(['sed', '-i', 's/^\[%(ovl)s\]/#[%(ovl)s]/'\ |
100 |
- % {'ovl': disable}, self.path]) |
101 |
return True |
102 |
except IOError as error: |
103 |
self.output.error('ReposConf: ConfigHandler.write(); Failed to write "'\ |