Merge lp://staging/~nobled/startup-manager/change-config into lp://staging/startup-manager

Proposed by dn
Status: Needs review
Proposed branch: lp://staging/~nobled/startup-manager/change-config
Merge into: lp://staging/startup-manager
Diff against target: 112 lines (+24/-29)
4 files modified
bootconfig/grub.py (+4/-15)
bootconfig/splashy.py (+1/-8)
bootconfig/usplash.py (+7/-5)
bootconfig/utils.py (+12/-1)
To merge this branch: bzr merge lp://staging/~nobled/startup-manager/change-config
Reviewer Review Type Date Requested Status
Jimmy Rönnholm Pending
Review via email: mp+14784@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
dn (nobled) wrote :

Hi, I removed some duplicated code to make editing the config files more consistent--I didn't touch grub-legacy yet, though.

Unmerged revisions

12. By dn

Reuse the change_config function

11. By dn

Only completely rewrite usplash.conf if it needs initializing;
use the more recent default file description

10. By dn

Move code from private method __change_config into utils.py so it can be reused

9. By dn

Fix documentation for grammar and accuracy.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bootconfig/grub.py'
2--- bootconfig/grub.py 2009-10-15 07:30:16 +0000
3+++ bootconfig/grub.py 2009-11-12 13:05:20 +0000
4@@ -61,26 +61,15 @@
5 filename = self.config_file
6 identifier = 'GRUB_CMDLINE_LINUX_DEFAULT='
7 options = set(options)
8- new_line = 'GRUB_CMDLINE_LINUX_DEFAULT="'
9+ new_line = '"'
10 for option in options:
11 new_line += option + ' '
12- new_line = new_line[:-1] + '"\n' # Remove the last space
13- lines = utils.read_lines_from_file(filename)
14- line_number = utils.get_line_number(filename, identifier)
15- lines[line_number] = new_line
16- utils.write_lines_to_file(filename, lines)
17- self.is_changed = True
18+ new_line = new_line[:-1] + '"' # Remove the last space
19+ self.__change_config(filename, identifier, new_line)
20
21 def __change_config(self, filename, identifier, value):
22 """Change the configuration files based on the passed value."""
23- line_number = utils.get_line_number(filename, identifier)
24- lines = utils.read_lines_from_file(filename)
25- if line_number == -1:
26- lines.append('\n')
27- line_number = len(lines) - 1
28- new_line = identifier + str(value) + '\n'
29- lines[line_number] = new_line
30- utils.write_lines_to_file(filename, lines)
31+ utils.change_config(filename, identifier, value)
32 self.is_changed = True
33
34 def get_timeout(self):
35
36=== modified file 'bootconfig/splashy.py'
37--- bootconfig/splashy.py 2009-01-04 23:37:32 +0000
38+++ bootconfig/splashy.py 2009-11-12 13:05:20 +0000
39@@ -108,14 +108,7 @@
40 line_end = '1'
41 else:
42 line_end = '0'
43- lines = utils.read_lines_from_file(self.config_file)
44- line_number = utils.get_line_number(self.config_file, identifier)
45- if line_number == -1:
46- lines.append('\n')
47- line_number = len(lines) - 1
48- line = identifier + line_end + '\n'
49- lines[line_number] = line
50- utils.write_lines_to_file(self.config_file, lines)
51+ utils.change_config(self.config_file, identifier, line_end)
52 self.must_update_initramfs = True
53
54 def do_shutdown_tasks(self):
55
56=== modified file 'bootconfig/usplash.py'
57--- bootconfig/usplash.py 2009-01-04 23:37:32 +0000
58+++ bootconfig/usplash.py 2009-11-12 13:05:20 +0000
59@@ -40,6 +40,11 @@
60 if not os.path.isdir(self.themes_directory):
61 os.mkdir(self.themes_directory)
62 if not os.path.isfile(self.config_file):
63+ lines = []
64+ lines.append('# Usplash configuration file\n')
65+ lines.append('# These parameters will only apply after running update-initramfs.\n')
66+ lines.append('\n')
67+ utils.write_lines_to_file(self.config_file, lines)
68 self.set_resolution('1024x768')
69 self.update_initramfs = False
70
71@@ -67,11 +72,8 @@
72 resolution = resolution.split('x')
73 xres = resolution[0]
74 yres = resolution[1]
75- lines = []
76- lines.append('# Usplash configuration file\n')
77- lines.append('xres=' + xres + '\n')
78- lines.append('yres=' + yres + '\n')
79- utils.write_lines_to_file(self.config_file, lines)
80+ utils.change_config(self.config_file, 'xres=', xres)
81+ utils.change_config(self.config_file, 'yres=', yres)
82 self.update_initramfs = True
83
84 def get_active_theme(self):
85
86=== modified file 'bootconfig/utils.py'
87--- bootconfig/utils.py 2009-03-29 13:11:27 +0000
88+++ bootconfig/utils.py 2009-11-12 13:05:20 +0000
89@@ -41,7 +41,7 @@
90 return filename
91
92 def get_line_number(filename, identifier):
93- """Return the number of the line in filename that begin with identifier.
94+ """Return the number of the first line in filename that begins with identifier.
95
96 Return -1 if there is no match.
97
98@@ -160,3 +160,14 @@
99
100 def set_resolution(resolution):
101 os.system('xrandr --size ' + resolution)
102+
103+def change_config(filename, identifier, value):
104+ """Change the configuration files based on the passed value."""
105+ line_number = utils.get_line_number(filename, identifier)
106+ lines = utils.read_lines_from_file(filename)
107+ if line_number == -1:
108+ lines.append('\n')
109+ line_number = len(lines) - 1
110+ new_line = identifier + str(value) + '\n'
111+ lines[line_number] = new_line
112+ utils.write_lines_to_file(filename, lines)

Subscribers

People subscribed via source and target branches

to all changes: