Merge lp:~gesha/linaro-license-protection/non-recursive-search into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Georgy Redkozubov
Status: Merged
Approved by: Stevan Radaković
Approved revision: 141
Merged at revision: 141
Proposed branch: lp:~gesha/linaro-license-protection/non-recursive-search
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 176 lines (+40/-67)
2 files modified
license_protected_downloads/render_text_files.py (+16/-6)
license_protected_downloads/tests/test_render_text_files.py (+24/-61)
To merge this branch: bzr merge lp:~gesha/linaro-license-protection/non-recursive-search
Reviewer Review Type Date Requested Status
Stevan Radaković Approve
Linaro Infrastructure Pending
Review via email: mp+130979@code.launchpad.net

Description of the change

This branch adds non-recursive search for README, INSTALL, etc. and for howto/HOWTO_* These files will be rendered only if found in current dir.
Made flash firmware instructions non-mandatory. Updated tests to reflect current state.

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

Hey gesha, this looks good.

One comment though, I don't think we should make flashfirmware non-mandatory so easy.
It should be put under discussion first in the email thread we had, I already told fabo about this.
This effects only android, and it was determined previously that it should have fallback links.
Let's remove it for now, it doesn't have to do anything with the bug were're fixing here.

review: Needs Fixing
141. By Georgy Redkozubov

Revert back HOWTO_flashfirmware.txt

Revision history for this message
Stevan Radaković (stevanr) wrote :

Thanks. Approve +1.

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-22 17:00:23 +0000
+++ license_protected_downloads/render_text_files.py 2012-10-23 12:13:28 +0000
@@ -4,6 +4,8 @@
4from collections import OrderedDict4from collections import OrderedDict
5from django.conf import settings5from django.conf import settings
66
7HOWTO_PATH = 'howto/'
8
7UBUNTU_FILES = ('README',9UBUNTU_FILES = ('README',
8 'INSTALL',10 'INSTALL',
9 'HACKING',11 'HACKING',
@@ -100,18 +102,24 @@
100 # If there are more of the same type then one, throw custom error as102 # If there are more of the same type then one, throw custom error as
101 # written above.103 # written above.
102 multiple = 0104 multiple = 0
103 filepaths = cls.dirEntries(path, True, FILES_MAP.keys())105 howtopath = os.path.join(path, HOWTO_PATH)
104 if len(filepaths) > 0:106 androidpaths = cls.dirEntries(howtopath, False, ANDROID_FILES)
105 for filepath in FILES_MAP.keys():107 ubuntupaths = cls.dirEntries(path, False, UBUNTU_FILES)
106 if len(cls.findall(filepaths,108 if len(androidpaths) > 0 and len(ubuntupaths) > 0:
109 raise MultipleFilesException
110 if len(androidpaths) > 0:
111 for filepath in ANDROID_FILES:
112 if len(cls.findall(androidpaths,
107 lambda x: re.search(filepath, x))) > 1:113 lambda x: re.search(filepath, x))) > 1:
108 multiple += 1114 multiple += 1
109 if multiple == 0:115 if multiple == 0:
110 return filepaths116 return androidpaths
111 else:117 else:
112 raise MultipleFilesException118 raise MultipleFilesException
119 elif len(ubuntupaths) > 0:
120 return ubuntupaths
113 else:121 else:
114 return filepaths122 return []
115123
116 @classmethod124 @classmethod
117 def flatten(cls, l, ltypes=(list, tuple)):125 def flatten(cls, l, ltypes=(list, tuple)):
@@ -140,6 +148,8 @@
140 directory are added to the list.148 directory are added to the list.
141 '''149 '''
142 fileList = []150 fileList = []
151 if not os.path.exists(path):
152 return fileList
143 for file in os.listdir(path):153 for file in os.listdir(path):
144 dirfile = os.path.join(path, file)154 dirfile = os.path.join(path, file)
145 if os.path.isfile(dirfile):155 if os.path.isfile(dirfile):
146156
=== modified file 'license_protected_downloads/tests/test_render_text_files.py'
--- license_protected_downloads/tests/test_render_text_files.py 2012-10-22 17:00:23 +0000
+++ license_protected_downloads/tests/test_render_text_files.py 2012-10-23 12:13:28 +0000
@@ -8,7 +8,7 @@
8 import MultipleFilesException8 import MultipleFilesException
9from license_protected_downloads.render_text_files import ANDROID_FILES9from license_protected_downloads.render_text_files import ANDROID_FILES
10from license_protected_downloads.render_text_files import UBUNTU_FILES10from license_protected_downloads.render_text_files import UBUNTU_FILES
1111from license_protected_downloads.render_text_files import HOWTO_PATH
1212
13THIS_DIRECTORY = os.path.dirname(os.path.abspath(__file__))13THIS_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
1414
@@ -35,87 +35,50 @@
35 self.assertEqual([],35 self.assertEqual([],
36 RenderTextFiles.findall(l, lambda x: re.search(r'1', x)))36 RenderTextFiles.findall(l, lambda x: re.search(r'1', x)))
3737
38 def make_temp_dir(self, empty=True, file_list=None, dir=None):38 def make_temp_dir(self, empty=True, file_list=None, dir=None, subdir=None):
39 path = tempfile.mkdtemp(dir=dir)39 path = tempfile.mkdtemp(dir=dir)
40 if not empty:40 if not empty:
41 if file_list:41 if file_list:
42 if subdir:
43 movepath = os.path.join(path, HOWTO_PATH)
44 os.makedirs(movepath)
45 else:
46 movepath = path
42 for file in file_list:47 for file in file_list:
43 handle, fname = tempfile.mkstemp(dir=path)48 handle, fname = tempfile.mkstemp(dir=movepath)
44 shutil.move(fname, os.path.join(path, file))49 shutil.move(fname, os.path.join(movepath, file))
45 return path50 return path
4651
47 def test_find_relevant_files_multiple_files(self):
48 path = tempfile.mkdtemp()
49 handle, fname = tempfile.mkstemp(dir=path)
50 shutil.move(fname, os.path.join(path, 'README'))
51 path1 = tempfile.mkdtemp(dir=path)
52 handle, fname = tempfile.mkstemp(dir=path1)
53 shutil.move(fname, os.path.join(path1, 'README'))
54 with self.assertRaises(MultipleFilesException):
55 RenderTextFiles.find_relevant_files(path)
56
57 def test_find_relevant_files_android(self):52 def test_find_relevant_files_android(self):
58 path = self.make_temp_dir(empty=False, file_list=ANDROID_FILES)53 path = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,
54 subdir=HOWTO_PATH)
59 full_android_files = []55 full_android_files = []
60 for file in ANDROID_FILES:56 for file in ANDROID_FILES:
61 full_android_files.append(os.path.join(path, file))57 full_android_files.append(os.path.join(path, HOWTO_PATH, file))
62 self.assertEqual(sorted(full_android_files),58 self.assertEqual(sorted(full_android_files),
63 sorted(RenderTextFiles.find_relevant_files(path)))59 sorted(RenderTextFiles.find_relevant_files(path)))
6460
65 def test_find_relevant_files_android_subdir(self):61 def test_find_relevant_files_android_subdir(self):
66 path = self.make_temp_dir()62 path = self.make_temp_dir()
67 full_path = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,63 full_path = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,
68 dir=path)64 dir=path, subdir=HOWTO_PATH)
69 full_android_files = []65 full_android_files = []
70 for file in ANDROID_FILES:66 for file in ANDROID_FILES:
71 full_android_files.append(os.path.join(full_path, file))67 full_android_files.append(os.path.join(full_path, HOWTO_PATH,
72 self.assertEqual(sorted(full_android_files),68 file))
69 self.assertEqual([],
73 sorted(RenderTextFiles.find_relevant_files(path)))70 sorted(RenderTextFiles.find_relevant_files(path)))
74 self.assertEqual(sorted(full_android_files),71 self.assertEqual(sorted(full_android_files),
75 sorted(RenderTextFiles.find_relevant_files(full_path)))72 sorted(RenderTextFiles.find_relevant_files(full_path)))
7673
77 def test_find_relevant_files_android_several_subdirs(self):
78 path = self.make_temp_dir()
79 full_path1 = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,
80 dir=path)
81 full_path2 = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,
82 dir=path)
83 full_android_files1 = []
84 full_android_files2 = []
85 for file in ANDROID_FILES:
86 full_android_files1.append(os.path.join(full_path1, file))
87 full_android_files2.append(os.path.join(full_path2, file))
88 with self.assertRaises(MultipleFilesException):
89 RenderTextFiles.find_relevant_files(path)
90 self.assertEqual(sorted(full_android_files1),
91 sorted(RenderTextFiles.find_relevant_files(full_path1)))
92 self.assertEqual(sorted(full_android_files2),
93 sorted(RenderTextFiles.find_relevant_files(full_path2)))
94
95 def test_find_relevant_files_android_and_ubuntu_samedir(self):74 def test_find_relevant_files_android_and_ubuntu_samedir(self):
96 flist = ANDROID_FILES + UBUNTU_FILES75 path = self.make_temp_dir(empty=False, file_list=UBUNTU_FILES)
97 path = self.make_temp_dir(empty=False, file_list=flist)76 os.makedirs(os.path.join(path, HOWTO_PATH))
98 full_files = []77 full_files = []
99 for file in flist:78 for file in ANDROID_FILES:
79 full_files.append(os.path.join(path, HOWTO_PATH, file))
80 open(os.path.join(path, HOWTO_PATH, file), 'w').close()
81 for file in UBUNTU_FILES:
100 full_files.append(os.path.join(path, file))82 full_files.append(os.path.join(path, file))
101 self.assertListEqual(sorted(full_files),83 with self.assertRaises(MultipleFilesException):
102 sorted(RenderTextFiles.find_relevant_files(path)))84 RenderTextFiles.find_relevant_files(path)
103
104 def test_find_relevant_files_android_and_ubuntu_different_subdirs(self):
105 path = self.make_temp_dir()
106 android_path = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,
107 dir=path)
108 ubuntu_path = self.make_temp_dir(empty=False, file_list=UBUNTU_FILES,
109 dir=path)
110 full_android_files = []
111 full_ubuntu_files = []
112 for file in ANDROID_FILES:
113 full_android_files.append(os.path.join(android_path, file))
114 for file in UBUNTU_FILES:
115 full_ubuntu_files.append(os.path.join(ubuntu_path, file))
116 self.assertEqual(sorted(full_android_files + full_ubuntu_files),
117 sorted(RenderTextFiles.find_relevant_files(path)))
118 self.assertEqual(sorted(full_android_files),
119 sorted(RenderTextFiles.find_relevant_files(android_path)))
120 self.assertEqual(sorted(full_ubuntu_files),
121 sorted(RenderTextFiles.find_relevant_files(ubuntu_path)))

Subscribers

People subscribed via source and target branches