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
=== modified file 'license_protected_downloads/render_text_files.py'
--- license_protected_downloads/render_text_files.py 2012-10-16 14:26:32 +0000
+++ license_protected_downloads/render_text_files.py 2012-10-18 19:24:18 +0000
@@ -1,14 +1,30 @@
1import os1import os
2import re2import re
3from textile.textilefactory import TextileFactory3from textile.textilefactory import TextileFactory
4from collections import OrderedDict
45
56
6UBUNTU_FILES = ('README',7UBUNTU_FILES = ('README',
7 'INSTALL',8 'INSTALL',
8 'HACKING')9 'HACKING',
9ANDROID_FILES = ('HOWTO_install.txt',10 'FIRMWARE',
11 'RTSM')
12ANDROID_FILES = ('HOWTO_releasenotes.txt',
13 'HOWTO_install.txt',
10 'HOWTO_getsourceandbuild.txt',14 'HOWTO_getsourceandbuild.txt',
11 'HOWTO_flashfirmware.txt')15 'HOWTO_flashfirmware.txt',
16 'HOWTO_rtsm.txt')
17
18FILES_MAP = {'HOWTO_releasenotes.txt': 'Release Notes',
19 'HOWTO_install.txt': 'Binary Image Installation',
20 'HOWTO_getsourceandbuild.txt': 'Building From Source',
21 'HOWTO_flashfirmware.txt': 'Firmware Update',
22 'HOWTO_rtsm.txt': 'RTSM',
23 'README': 'Release Notes',
24 'INSTALL': 'Binary Image Installation',
25 'HACKING': 'Building From Source',
26 'FIRMWARE': 'Firmware Update',
27 'RTSM': 'RTSM'}
1228
1329
14class MultipleFilesException(Exception):30class MultipleFilesException(Exception):
@@ -33,7 +49,7 @@
33 @classmethod49 @classmethod
34 def find_and_render(cls, path):50 def find_and_render(cls, path):
3551
36 result = {}52 result = OrderedDict()
3753
38 try:54 try:
39 filepaths = sorted(cls.find_relevant_files(path),55 filepaths = sorted(cls.find_relevant_files(path),
@@ -46,7 +62,8 @@
46 for filepath in filepaths:62 for filepath in filepaths:
47 try:63 try:
48 file_obj = open(filepath, 'r')64 file_obj = open(filepath, 'r')
49 title, formatted = cls.render_file(file_obj)65 formatted = cls.render_file(file_obj)
66 title = FILES_MAP[os.path.basename(filepath)]
50 result[title] = formatted67 result[title] = formatted
51 except:68 except:
52 # TODO: log error or something.69 # TODO: log error or something.
@@ -60,9 +77,8 @@
60 def render_file(cls, file_obj):77 def render_file(cls, file_obj):
61 # TODO: introduce special options to textile factory if necessary.78 # TODO: introduce special options to textile factory if necessary.
62 textile_factory = TextileFactory()79 textile_factory = TextileFactory()
63 title = file_obj.readline()80 file_obj.readline()
64 file_obj.seek(0)81 return textile_factory.process(file_obj.read())
65 return title, textile_factory.process(file_obj.read())
6682
67 @classmethod83 @classmethod
68 def find_relevant_files(cls, path):84 def find_relevant_files(cls, path):
@@ -70,13 +86,9 @@
70 # If there are more of the same type then one, throw custom error as86 # If there are more of the same type then one, throw custom error as
71 # written above.87 # written above.
72 multiple = 088 multiple = 0
73 filepaths = cls.dirEntries(path, True, UBUNTU_FILES, ANDROID_FILES)89 filepaths = cls.dirEntries(path, True, FILES_MAP.keys())
74 if len(filepaths) > 0:90 if len(filepaths) > 0:
75 for filepath in UBUNTU_FILES:91 for filepath in FILES_MAP.keys():
76 if len(cls.findall(filepaths,
77 lambda x: re.search(filepath, x))) > 1:
78 multiple += 1
79 for filepath in ANDROID_FILES:
80 if len(cls.findall(filepaths,92 if len(cls.findall(filepaths,
81 lambda x: re.search(filepath, x))) > 1:93 lambda x: re.search(filepath, x))) > 1:
82 multiple += 194 multiple += 1
8395
=== modified file 'license_protected_downloads/tests/test_render_text_files.py'
--- license_protected_downloads/tests/test_render_text_files.py 2012-10-16 12:00:29 +0000
+++ license_protected_downloads/tests/test_render_text_files.py 2012-10-18 19:24:18 +0000
@@ -65,8 +65,8 @@
65 full_android_files = []65 full_android_files = []
66 for file in ANDROID_FILES:66 for file in ANDROID_FILES:
67 full_android_files.append(os.path.join(path, file))67 full_android_files.append(os.path.join(path, file))
68 self.assertEqual(full_android_files,68 self.assertEqual(sorted(full_android_files),
69 RenderTextFiles.find_relevant_files(path))69 sorted(RenderTextFiles.find_relevant_files(path)))
7070
71 def test_find_relevant_files_android_subdir(self):71 def test_find_relevant_files_android_subdir(self):
72 path = self.make_temp_dir()72 path = self.make_temp_dir()
@@ -75,10 +75,10 @@
75 full_android_files = []75 full_android_files = []
76 for file in ANDROID_FILES:76 for file in ANDROID_FILES:
77 full_android_files.append(os.path.join(full_path, file))77 full_android_files.append(os.path.join(full_path, file))
78 self.assertEqual(full_android_files,78 self.assertEqual(sorted(full_android_files),
79 RenderTextFiles.find_relevant_files(path))79 sorted(RenderTextFiles.find_relevant_files(path)))
80 self.assertEqual(full_android_files,80 self.assertEqual(sorted(full_android_files),
81 RenderTextFiles.find_relevant_files(full_path))81 sorted(RenderTextFiles.find_relevant_files(full_path)))
8282
83 def test_find_relevant_files_android_several_subdirs(self):83 def test_find_relevant_files_android_several_subdirs(self):
84 path = self.make_temp_dir()84 path = self.make_temp_dir()
@@ -93,10 +93,10 @@
93 full_android_files2.append(os.path.join(full_path2, file))93 full_android_files2.append(os.path.join(full_path2, file))
94 with self.assertRaises(MultipleFilesException):94 with self.assertRaises(MultipleFilesException):
95 RenderTextFiles.find_relevant_files(path)95 RenderTextFiles.find_relevant_files(path)
96 self.assertEqual(full_android_files1,96 self.assertEqual(sorted(full_android_files1),
97 RenderTextFiles.find_relevant_files(full_path1))97 sorted(RenderTextFiles.find_relevant_files(full_path1)))
98 self.assertEqual(full_android_files2,98 self.assertEqual(sorted(full_android_files2),
99 RenderTextFiles.find_relevant_files(full_path2))99 sorted(RenderTextFiles.find_relevant_files(full_path2)))
100100
101 def test_find_relevant_files_android_and_ubuntu_samedir(self):101 def test_find_relevant_files_android_and_ubuntu_samedir(self):
102 flist = ANDROID_FILES + UBUNTU_FILES102 flist = ANDROID_FILES + UBUNTU_FILES

Subscribers

People subscribed via source and target branches