Merge lp:~torkvemada/quickly/templatetools into lp:quickly

Proposed by Vsevolod Velichko
Status: Needs review
Proposed branch: lp:~torkvemada/quickly/templatetools
Merge into: lp:quickly
Diff against target: 65 lines (+39/-9)
1 file modified
quickly/templatetools.py (+39/-9)
To merge this branch: bzr merge lp:~torkvemada/quickly/templatetools
Reviewer Review Type Date Requested Status
Quickly Developers Pending
Review via email: mp+114156@code.launchpad.net

Description of the change

Fix for the update_file_contents method, since it is buggy and sometimes creates corrupted files (I faced it when quickly was generating my debian/control depends line).

To post a comment you must log in.
lp:~torkvemada/quickly/templatetools updated
677. By Vsevolod Velichko

templatetools.update_file_content fix for it to set the file coding comment if needed

Unmerged revisions

677. By Vsevolod Velichko

templatetools.update_file_content fix for it to set the file coding comment if needed

676. By Vsevolod Velichko

Fixed update_file_contents.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'quickly/templatetools.py'
--- quickly/templatetools.py 2011-06-06 10:14:40 +0000
+++ quickly/templatetools.py 2012-07-13 19:00:30 +0000
@@ -108,23 +108,53 @@
108108
109 skip_until_end_found = False109 skip_until_end_found = False
110 marker_found = False110 marker_found = False
111 prepend_coding_comment = False
112 if filename.endswith('.py'):
113 try:
114 replacing_content.decode('ascii')
115 except UnicodeDecodeError:
116 prepend_coding_comment = True
117
111 try:118 try:
112 filename = os.path.abspath(filename)119 filename = os.path.abspath(filename)
113 ftarget_file_name = file(filename, 'r')120 ftarget_file_name = file(filename, 'r')
114 ftarget_file_name_out = file(ftarget_file_name.name + '.new', 'w')121 ftarget_file_name_out = file(ftarget_file_name.name + '.new', 'w')
122 linenum = 0
115 for line in ftarget_file_name:123 for line in ftarget_file_name:
124 # If we already have some coding sign, don't add
125 if prepend_coding_comment:
126 linenum += 1
127 if line.startswith('# -*- ') and 'coding: ' in line:
128 prepend_coding_comment = False
129 # If we have initial hashbang instruction, add on second line
130 elif linenum == 1 and line.startswith('#!'):
131 pass
132 else:
133 ftarget_file_name_out.write('# -*- coding: utf-8 -*-\n')
134 prepend_coding_comment = False
135
116 # seek if we have to add something136 # seek if we have to add something
117 if start_marker in line:137 if skip_until_end_found or not marker_found:
118 skip_until_end_found = True138 try:
119 marker_found = True139 i = line.index(start_marker)
120 ftarget_file_name_out.write(replacing_content)140 skip_until_end_found = True
121141 marker_found = True
122 if end_marker in line:142 ftarget_file_name_out.write(line[:i])
123 skip_until_end_found = False143 ftarget_file_name_out.write(replacing_content)
124144 except ValueError:
125 if not skip_until_end_found:145 pass
146 try:
147 i = line.index(end_marker)
148 if skip_until_end_found:
149 ftarget_file_name_out.write(line[i:])
150 skip_until_end_found = False
151 except ValueError:
152 if not skip_until_end_found:
153 ftarget_file_name_out.write(line)
154 else:
126 ftarget_file_name_out.write(line)155 ftarget_file_name_out.write(line)
127156
157
128 ftarget_file_name.close()158 ftarget_file_name.close()
129 ftarget_file_name_out.close()159 ftarget_file_name_out.close()
130160

Subscribers

People subscribed via source and target branches