Merge lp:~gesha/linaro-license-protection/1146220 into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Georgy Redkozubov
Status: Merged
Approved by: Stevan Radaković
Approved revision: 186
Merged at revision: 184
Proposed branch: lp:~gesha/linaro-license-protection/1146220
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 131 lines (+85/-0)
2 files modified
scripts/publish_to_snapshots.py (+31/-0)
tests/test_publish_to_snapshots.py (+54/-0)
To merge this branch: bzr merge lp:~gesha/linaro-license-protection/1146220
Reviewer Review Type Date Requested Status
Stevan Radaković Approve
Review via email: mp+160352@code.launchpad.net

Description of the change

This branch reinstates BUILD-INFO.txt support for publishing service.
Publishing script checks if BUILD-INFO.txt is present among artifacts being published or among already published artifacts for the same build. Otherwise publishing is aborted with an error.

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

Nice work gesha, thanks!

Only thing I dislike here is having return values(PASS, FAIL) in the method instead of using the exceptions as this is a very good example on when they should be used. That way you don't need to return anything at all, just catch exception if the method throws it. Tests would need to go through a little change as well because of it.

review: Needs Fixing (code)
184. By Georgy Redkozubov

Rewritten code to use exceptions.

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

46 @@ -387,6 +408,7 @@
47 if build_dir_path is None or target_dir_path is None:
48 print "Problem with build/target path, move failed"
49 return FAIL
50 + publisher.check_buildinfo(build_dir_path, target_dir_path)

Think we should have here something like:

try:
    publisher.check_buildinfo(build_dir_path, target_dir_path)
except as e:
    print e.strerror
    return FAIL

185. By Georgy Redkozubov

Rewrite exception handling.

186. By Georgy Redkozubov

Fix pep8

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

Looks good.
Approve +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'scripts/publish_to_snapshots.py'
--- scripts/publish_to_snapshots.py 2013-02-26 08:38:32 +0000
+++ scripts/publish_to_snapshots.py 2013-04-25 19:33:24 +0000
@@ -15,6 +15,7 @@
15product_dir_path = 'target/product'15product_dir_path = 'target/product'
16PASS = 016PASS = 0
17FAIL = 117FAIL = 1
18buildinfo = 'BUILD-INFO.txt'
18acceptable_job_types = [19acceptable_job_types = [
19 'android',20 'android',
20 'prebuilt',21 'prebuilt',
@@ -61,6 +62,16 @@
61 pass62 pass
6263
6364
65class BuildInfoException(Exception):
66 """BUILD-INFO.txt is absent."""
67
68 def __init__(self, value):
69 self.value = value
70
71 def __str__(self):
72 return repr(self.value)
73
74
64class SnapshotsPublisher(object):75class SnapshotsPublisher(object):
6576
66 # Files that need no sanitization even when publishing to staging.77 # Files that need no sanitization even when publishing to staging.
@@ -367,6 +378,21 @@
367 print "Failed to move files destination path", target_dir_path378 print "Failed to move files destination path", target_dir_path
368 return FAIL379 return FAIL
369380
381 def check_buildinfo(self, build_dir_path, target_dir_path):
382 bi_dirs = []
383 for path, subdirs, files in os.walk(build_dir_path):
384 for filename in files:
385 if buildinfo in filename:
386 bi_dirs.append(path)
387 for path, subdirs, files in os.walk(target_dir_path):
388 for filename in files:
389 if buildinfo in filename:
390 bi_dirs.append(path)
391
392 if not bi_dirs:
393 raise BuildInfoException(
394 "BUILD-INFO.txt is not present for build being published.")
395
370396
371def main():397def main():
372 global uploads_path398 global uploads_path
@@ -387,6 +413,11 @@
387 if build_dir_path is None or target_dir_path is None:413 if build_dir_path is None or target_dir_path is None:
388 print "Problem with build/target path, move failed"414 print "Problem with build/target path, move failed"
389 return FAIL415 return FAIL
416 try:
417 publisher.check_buildinfo(build_dir_path, target_dir_path)
418 except BuildInfoException as e:
419 print e.value
420 return FAIL
390 ret = publisher.move_artifacts(args, build_dir_path, target_dir_path)421 ret = publisher.move_artifacts(args, build_dir_path, target_dir_path)
391 if ret != PASS:422 if ret != PASS:
392 print "Move Failed"423 print "Move Failed"
393424
=== modified file 'tests/test_publish_to_snapshots.py'
--- tests/test_publish_to_snapshots.py 2013-02-26 08:38:32 +0000
+++ tests/test_publish_to_snapshots.py 2013-04-25 19:33:24 +0000
@@ -11,6 +11,8 @@
11 SnapshotsPublisher,11 SnapshotsPublisher,
12 setup_parser,12 setup_parser,
13 product_dir_path,13 product_dir_path,
14 BuildInfoException,
15 buildinfo
14 )16 )
1517
1618
@@ -726,3 +728,55 @@
726 self.assertEqual(content, open(resulting_file).read())728 self.assertEqual(content, open(resulting_file).read())
727 self.assertEqual(howto_content, open(resulting_howto_file).read())729 self.assertEqual(howto_content, open(resulting_howto_file).read())
728 shutil.rmtree(source_dir)730 shutil.rmtree(source_dir)
731
732 def test_check_buildinfo_upload_dir(self):
733 self.publisher = SnapshotsPublisher()
734 param = self.parser.parse_args(
735 ['-t', 'prebuilt', '-j', 'precise-armhf-ubuntu-desktop',
736 '-n', '1'])
737 self.publisher.validate_args(param)
738 build_dir = '/'.join([param.job_name, str(param.build_num)])
739 build_path = os.path.join(self.uploads_path, build_dir)
740 os.makedirs(build_path)
741 www_path = os.path.join(self.target_path, build_dir)
742 os.makedirs(www_path)
743
744 file_name = os.path.join(build_path, buildinfo)
745 file = open(file_name, "w")
746 file.close()
747
748 self.assertIsNone(self.publisher.check_buildinfo(build_path, www_path))
749
750 def test_check_buildinfo_target_dir(self):
751 self.publisher = SnapshotsPublisher()
752 param = self.parser.parse_args(
753 ['-t', 'prebuilt', '-j', 'precise-armhf-ubuntu-desktop',
754 '-n', '1'])
755 self.publisher.validate_args(param)
756 build_dir = '/'.join([param.job_name, str(param.build_num)])
757 build_path = os.path.join(self.uploads_path, build_dir)
758 os.makedirs(build_path)
759 www_path = os.path.join(self.target_path, build_dir)
760 os.makedirs(www_path)
761
762 file_name = os.path.join(www_path, buildinfo)
763 file = open(file_name, "w")
764 file.close()
765
766 self.assertIsNone(self.publisher.check_buildinfo(build_path, www_path))
767
768 def test_check_buildinfo_no_file(self):
769 self.publisher = SnapshotsPublisher()
770 param = self.parser.parse_args(
771 ['-t', 'prebuilt', '-j', 'precise-armhf-ubuntu-desktop',
772 '-n', '1'])
773 self.publisher.validate_args(param)
774 build_dir = '/'.join([param.job_name, str(param.build_num)])
775 build_path = os.path.join(self.uploads_path, build_dir)
776 os.makedirs(build_path)
777 www_path = os.path.join(self.target_path, build_dir)
778 os.makedirs(www_path)
779
780 self.assertRaises(
781 BuildInfoException,
782 self.publisher.check_buildinfo, build_path, www_path)

Subscribers

People subscribed via source and target branches