Merge lp:~sil2100/click-sync/lock-separate-dir into lp:click-sync

Proposed by Łukasz Zemczak
Status: Merged
Approved by: Łukasz Zemczak
Approved revision: 21
Merged at revision: 20
Proposed branch: lp:~sil2100/click-sync/lock-separate-dir
Merge into: lp:click-sync
Diff against target: 83 lines (+27/-8)
1 file modified
click-sync.py (+27/-8)
To merge this branch: bzr merge lp:~sil2100/click-sync/lock-separate-dir
Reviewer Review Type Date Requested Status
Ubuntu CD Image Team Pending
Review via email: mp+288597@code.launchpad.net

Commit message

Support having a different directory with locked clicks.

Description of the change

Support having a different directory with locked clicks.

To post a comment you must log in.
21. By Łukasz Zemczak

locked_list does not exist enymore, use locked_clicks_dir instead.

Revision history for this message
Łukasz Zemczak (sil2100) wrote :

Tested as working on a local setup.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'click-sync.py'
2--- click-sync.py 2016-03-09 12:29:41 +0000
3+++ click-sync.py 2016-03-10 14:56:12 +0000
4@@ -14,6 +14,7 @@
5 import subprocess
6 import urllib
7 import logging
8+import shutil
9
10 logging.basicConfig(level=logging.INFO)
11 log = logging.getLogger()
12@@ -124,13 +125,21 @@
13 os.rename(new_target_file, target_file)
14
15
16-def get_store_apps(download_dir, auth=None, locked_list=[]):
17+def get_store_apps(download_dir, auth=None, locked_clicks_dir=None):
18 """
19 Gets click apps from the store.
20 """
21 http_client = httplib2.Http()
22 download_list = []
23
24+ locked_list = []
25+ if locked_clicks_dir:
26+ locked_clicks_path = os.path.join(locked_clicks_dir,
27+ 'locked_clicks_list')
28+ if os.path.exists(locked_clicks_path):
29+ locked_list = [line.strip() for line in
30+ open(locked_clicks_path, 'r')]
31+
32 for click in store_click_packages:
33 # Skip packages that are manually locked down
34 click_locked = False
35@@ -140,7 +149,16 @@
36 click_locked = True
37 break
38
39- if not click_locked:
40+ if click_locked:
41+ # Copy the click from the locked directory (if present)
42+ source_click = os.path.join(locked_clicks_dir, click_file)
43+ dest_click = os.path.join(download_dir, click_file)
44+ if os.path.exists(source_click):
45+ shutil.copyfile(source_click, dest_click)
46+
47+ if not os.path.exists(dest_click):
48+ continue
49+ else:
50 # Download the click from the store if not locked
51 json_content = get_json_for_uri(store_uri % click)
52 click_file = json_content['download_url'].split('/')[-1]
53@@ -171,9 +189,12 @@
54 help='jenkins url to download click packages from.')
55 parser.add_argument('download_dir',
56 help='''Path to store the downloaded click packages.
57- The path must exist''')
58+ The path must exist.''')
59 parser.add_argument('--credentials-file', default=None, required=False,
60 help='''json dictionary with tokens for oauth.''')
61+ parser.add_argument('--locked-clicks-dir', default=None,
62+ help='Path where the locked clicks and their list are '
63+ 'stored.')
64 return parser.parse_args()
65
66
67@@ -203,13 +224,11 @@
68 auth = OAuthClient.credentials_from_file(args.credentials_file)
69
70 # Look for the manual-lock list
71- locked_list = []
72- locked_clicks_path = os.path.join(args.download_dir, 'locked_clicks_list')
73- if os.path.exists(locked_clicks_path):
74- locked_list = [line.strip() for line in open(locked_clicks_path, 'r')]
75+ locked_clicks_dir = args.locked_clicks_dir if args.locked_clicks_dir \
76+ else args.download_dir
77
78 download_list = download_list + get_store_apps(args.download_dir, auth,
79- locked_list)
80+ locked_clicks_dir)
81
82 click_list = os.path.join(args.download_dir, 'click_list')
83 with open(click_list, 'w') as f:

Subscribers

People subscribed via source and target branches