Merge lp:~gesha/linaro-license-protection/flatten-android-artifacts into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Georgy Redkozubov
Status: Merged
Merged at revision: 153
Proposed branch: lp:~gesha/linaro-license-protection/flatten-android-artifacts
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 97 lines (+58/-0)
2 files modified
scripts/publish_to_snapshots.py (+28/-0)
tests/test_publish_to_snapshots.py (+30/-0)
To merge this branch: bzr merge lp:~gesha/linaro-license-protection/flatten-android-artifacts
Reviewer Review Type Date Requested Status
Deepti B. Kalakeri (community) Approve
Review via email: mp+138188@code.launchpad.net

Description of the change

This branch adds support of reshuffling android artifacts. It does 'flattening' of 'target/product/<name>/*' directory, all entries from the '<name>' directory are moved to the top level directory (job id).

To post a comment you must log in.
Revision history for this message
Deepti B. Kalakeri (deeptik) wrote :

Looks good. +1.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scripts/publish_to_snapshots.py'
2--- scripts/publish_to_snapshots.py 2012-11-29 09:36:04 +0000
3+++ scripts/publish_to_snapshots.py 2012-12-05 14:36:25 +0000
4@@ -12,6 +12,7 @@
5 target_path = '/srv/snapshots.linaro.org/www/'
6 staging_uploads_path = '/srv/staging.snapshots.linaro.org/uploads/'
7 staging_target_path = '/srv/staging.snapshots.linaro.org/www/'
8+product_dir_path = 'target/product'
9 PASS = 0
10 FAIL = 1
11 acceptable_job_types = [
12@@ -263,6 +264,30 @@
13 os.chdir(orig_dir)
14 return FAIL
15
16+ def reshuffle_android_artifacts(self, src_dir):
17+ dst_dir = src_dir
18+ full_product_path = os.path.join(src_dir, product_dir_path)
19+ if os.path.isdir(full_product_path):
20+ filelist = os.listdir(full_product_path)
21+ try:
22+ for file in filelist:
23+ src = os.path.join(full_product_path, file)
24+ if os.path.isdir(src):
25+ for artifact in os.listdir(src):
26+ dest = os.path.join(dst_dir, artifact)
27+ if os.path.exists(dest):
28+ if os.path.isdir(dest):
29+ continue
30+ else:
31+ os.remove(dest)
32+ shutil.move(os.path.join(src, artifact), dest)
33+ except shutil.Error:
34+ print "Error while reshuffling the content"
35+ try:
36+ shutil.rmtree(os.path.dirname(full_product_path))
37+ except shutil.Error:
38+ print "Error removing empty product dir"
39+
40 def move_dir_content(self, src_dir, dest_dir, sanitize=False):
41 filelist = os.listdir(src_dir)
42 try:
43@@ -300,6 +325,9 @@
44 if not os.path.isdir(target_dir_path):
45 raise OSError
46
47+ if (args.job_type == "android"):
48+ self.reshuffle_android_artifacts(build_dir_path)
49+
50 self.move_dir_content(build_dir_path, target_dir_path,
51 sanitize=args.staging)
52
53
54=== modified file 'tests/test_publish_to_snapshots.py'
55--- tests/test_publish_to_snapshots.py 2012-10-10 18:59:02 +0000
56+++ tests/test_publish_to_snapshots.py 2012-12-05 14:36:25 +0000
57@@ -10,6 +10,7 @@
58 PublisherArgumentException,
59 SnapshotsPublisher,
60 setup_parser,
61+ product_dir_path,
62 )
63
64
65@@ -696,3 +697,32 @@
66 self.assertEqual(os.path.basename(artifact),
67 open(moved_artifact).read())
68 self.assertIn("Moved the files from", stdout.read())
69+
70+ def test_flatten_android_artifacts(self):
71+ source_dir = tempfile.mkdtemp()
72+ full_product_path = os.path.join(source_dir, product_dir_path)
73+ full_board_path = os.path.join(full_product_path, 'board')
74+ full_howto_path = os.path.join(full_board_path, 'howto')
75+ os.makedirs(full_howto_path)
76+
77+ content = "file_content"
78+ file_name = os.path.join(full_board_path, "artifact.txt")
79+ file = open(file_name, "w")
80+ file.write(content)
81+ file.close()
82+
83+ howto_content = "howto_file_content"
84+ howto_file_name = os.path.join(full_howto_path, "HOWTO_install.txt")
85+ file = open(howto_file_name, "w")
86+ file.write(howto_content)
87+ file.close()
88+
89+ publisher = SnapshotsPublisher()
90+ publisher.reshuffle_android_artifacts(source_dir)
91+ resulting_file = os.path.join(source_dir,
92+ os.path.basename(file_name))
93+ resulting_howto_file = os.path.join(source_dir, 'howto',
94+ os.path.basename(howto_file_name))
95+ self.assertEqual(content, open(resulting_file).read())
96+ self.assertEqual(howto_content, open(resulting_howto_file).read())
97+ shutil.rmtree(source_dir)

Subscribers

People subscribed via source and target branches