Merge lp:~gesha/linaro-license-protection/change-tabs-names into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Georgy Redkozubov
Status: Merged
Approved by: Stevan Radaković
Approved revision: 134
Merged at revision: 134
Proposed branch: lp:~gesha/linaro-license-protection/change-tabs-names
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 129 lines (+36/-24)
2 files modified
license_protected_downloads/render_text_files.py (+26/-14)
license_protected_downloads/tests/test_render_text_files.py (+10/-10)
To merge this branch: bzr merge lp:~gesha/linaro-license-protection/change-tabs-names
Reviewer Review Type Date Requested Status
Stevan Radaković Approve
Review via email: mp+130418@code.launchpad.net

Description of the change

This branch adds new files to render, adds tab names mapping.

To post a comment you must log in.
Revision history for this message
Stevan Radaković (stevanr) wrote :

Looking good. Great work gesha!

One thing only

+ file_obj.readline()

should be removed. What Fathi meant was to remove this line from the source files themself because it was used as a workaround. So we don't have to strap the line out.
Approving.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'license_protected_downloads/render_text_files.py'
2--- license_protected_downloads/render_text_files.py 2012-10-16 14:26:32 +0000
3+++ license_protected_downloads/render_text_files.py 2012-10-18 19:24:18 +0000
4@@ -1,14 +1,30 @@
5 import os
6 import re
7 from textile.textilefactory import TextileFactory
8+from collections import OrderedDict
9
10
11 UBUNTU_FILES = ('README',
12 'INSTALL',
13- 'HACKING')
14-ANDROID_FILES = ('HOWTO_install.txt',
15+ 'HACKING',
16+ 'FIRMWARE',
17+ 'RTSM')
18+ANDROID_FILES = ('HOWTO_releasenotes.txt',
19+ 'HOWTO_install.txt',
20 'HOWTO_getsourceandbuild.txt',
21- 'HOWTO_flashfirmware.txt')
22+ 'HOWTO_flashfirmware.txt',
23+ 'HOWTO_rtsm.txt')
24+
25+FILES_MAP = {'HOWTO_releasenotes.txt': 'Release Notes',
26+ 'HOWTO_install.txt': 'Binary Image Installation',
27+ 'HOWTO_getsourceandbuild.txt': 'Building From Source',
28+ 'HOWTO_flashfirmware.txt': 'Firmware Update',
29+ 'HOWTO_rtsm.txt': 'RTSM',
30+ 'README': 'Release Notes',
31+ 'INSTALL': 'Binary Image Installation',
32+ 'HACKING': 'Building From Source',
33+ 'FIRMWARE': 'Firmware Update',
34+ 'RTSM': 'RTSM'}
35
36
37 class MultipleFilesException(Exception):
38@@ -33,7 +49,7 @@
39 @classmethod
40 def find_and_render(cls, path):
41
42- result = {}
43+ result = OrderedDict()
44
45 try:
46 filepaths = sorted(cls.find_relevant_files(path),
47@@ -46,7 +62,8 @@
48 for filepath in filepaths:
49 try:
50 file_obj = open(filepath, 'r')
51- title, formatted = cls.render_file(file_obj)
52+ formatted = cls.render_file(file_obj)
53+ title = FILES_MAP[os.path.basename(filepath)]
54 result[title] = formatted
55 except:
56 # TODO: log error or something.
57@@ -60,9 +77,8 @@
58 def render_file(cls, file_obj):
59 # TODO: introduce special options to textile factory if necessary.
60 textile_factory = TextileFactory()
61- title = file_obj.readline()
62- file_obj.seek(0)
63- return title, textile_factory.process(file_obj.read())
64+ file_obj.readline()
65+ return textile_factory.process(file_obj.read())
66
67 @classmethod
68 def find_relevant_files(cls, path):
69@@ -70,13 +86,9 @@
70 # If there are more of the same type then one, throw custom error as
71 # written above.
72 multiple = 0
73- filepaths = cls.dirEntries(path, True, UBUNTU_FILES, ANDROID_FILES)
74+ filepaths = cls.dirEntries(path, True, FILES_MAP.keys())
75 if len(filepaths) > 0:
76- for filepath in UBUNTU_FILES:
77- if len(cls.findall(filepaths,
78- lambda x: re.search(filepath, x))) > 1:
79- multiple += 1
80- for filepath in ANDROID_FILES:
81+ for filepath in FILES_MAP.keys():
82 if len(cls.findall(filepaths,
83 lambda x: re.search(filepath, x))) > 1:
84 multiple += 1
85
86=== modified file 'license_protected_downloads/tests/test_render_text_files.py'
87--- license_protected_downloads/tests/test_render_text_files.py 2012-10-16 12:00:29 +0000
88+++ license_protected_downloads/tests/test_render_text_files.py 2012-10-18 19:24:18 +0000
89@@ -65,8 +65,8 @@
90 full_android_files = []
91 for file in ANDROID_FILES:
92 full_android_files.append(os.path.join(path, file))
93- self.assertEqual(full_android_files,
94- RenderTextFiles.find_relevant_files(path))
95+ self.assertEqual(sorted(full_android_files),
96+ sorted(RenderTextFiles.find_relevant_files(path)))
97
98 def test_find_relevant_files_android_subdir(self):
99 path = self.make_temp_dir()
100@@ -75,10 +75,10 @@
101 full_android_files = []
102 for file in ANDROID_FILES:
103 full_android_files.append(os.path.join(full_path, file))
104- self.assertEqual(full_android_files,
105- RenderTextFiles.find_relevant_files(path))
106- self.assertEqual(full_android_files,
107- RenderTextFiles.find_relevant_files(full_path))
108+ self.assertEqual(sorted(full_android_files),
109+ sorted(RenderTextFiles.find_relevant_files(path)))
110+ self.assertEqual(sorted(full_android_files),
111+ sorted(RenderTextFiles.find_relevant_files(full_path)))
112
113 def test_find_relevant_files_android_several_subdirs(self):
114 path = self.make_temp_dir()
115@@ -93,10 +93,10 @@
116 full_android_files2.append(os.path.join(full_path2, file))
117 with self.assertRaises(MultipleFilesException):
118 RenderTextFiles.find_relevant_files(path)
119- self.assertEqual(full_android_files1,
120- RenderTextFiles.find_relevant_files(full_path1))
121- self.assertEqual(full_android_files2,
122- RenderTextFiles.find_relevant_files(full_path2))
123+ self.assertEqual(sorted(full_android_files1),
124+ sorted(RenderTextFiles.find_relevant_files(full_path1)))
125+ self.assertEqual(sorted(full_android_files2),
126+ sorted(RenderTextFiles.find_relevant_files(full_path2)))
127
128 def test_find_relevant_files_android_and_ubuntu_samedir(self):
129 flist = ANDROID_FILES + UBUNTU_FILES

Subscribers

People subscribed via source and target branches