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
=== modified file 'click-sync.py'
--- click-sync.py 2016-03-09 12:29:41 +0000
+++ click-sync.py 2016-03-10 14:56:12 +0000
@@ -14,6 +14,7 @@
14import subprocess14import subprocess
15import urllib15import urllib
16import logging16import logging
17import shutil
1718
18logging.basicConfig(level=logging.INFO)19logging.basicConfig(level=logging.INFO)
19log = logging.getLogger()20log = logging.getLogger()
@@ -124,13 +125,21 @@
124 os.rename(new_target_file, target_file)125 os.rename(new_target_file, target_file)
125126
126127
127def get_store_apps(download_dir, auth=None, locked_list=[]):128def get_store_apps(download_dir, auth=None, locked_clicks_dir=None):
128 """129 """
129 Gets click apps from the store.130 Gets click apps from the store.
130 """131 """
131 http_client = httplib2.Http()132 http_client = httplib2.Http()
132 download_list = []133 download_list = []
133134
135 locked_list = []
136 if locked_clicks_dir:
137 locked_clicks_path = os.path.join(locked_clicks_dir,
138 'locked_clicks_list')
139 if os.path.exists(locked_clicks_path):
140 locked_list = [line.strip() for line in
141 open(locked_clicks_path, 'r')]
142
134 for click in store_click_packages:143 for click in store_click_packages:
135 # Skip packages that are manually locked down144 # Skip packages that are manually locked down
136 click_locked = False145 click_locked = False
@@ -140,7 +149,16 @@
140 click_locked = True149 click_locked = True
141 break150 break
142151
143 if not click_locked:152 if click_locked:
153 # Copy the click from the locked directory (if present)
154 source_click = os.path.join(locked_clicks_dir, click_file)
155 dest_click = os.path.join(download_dir, click_file)
156 if os.path.exists(source_click):
157 shutil.copyfile(source_click, dest_click)
158
159 if not os.path.exists(dest_click):
160 continue
161 else:
144 # Download the click from the store if not locked162 # Download the click from the store if not locked
145 json_content = get_json_for_uri(store_uri % click)163 json_content = get_json_for_uri(store_uri % click)
146 click_file = json_content['download_url'].split('/')[-1]164 click_file = json_content['download_url'].split('/')[-1]
@@ -171,9 +189,12 @@
171 help='jenkins url to download click packages from.')189 help='jenkins url to download click packages from.')
172 parser.add_argument('download_dir',190 parser.add_argument('download_dir',
173 help='''Path to store the downloaded click packages.191 help='''Path to store the downloaded click packages.
174 The path must exist''')192 The path must exist.''')
175 parser.add_argument('--credentials-file', default=None, required=False,193 parser.add_argument('--credentials-file', default=None, required=False,
176 help='''json dictionary with tokens for oauth.''')194 help='''json dictionary with tokens for oauth.''')
195 parser.add_argument('--locked-clicks-dir', default=None,
196 help='Path where the locked clicks and their list are '
197 'stored.')
177 return parser.parse_args()198 return parser.parse_args()
178199
179200
@@ -203,13 +224,11 @@
203 auth = OAuthClient.credentials_from_file(args.credentials_file)224 auth = OAuthClient.credentials_from_file(args.credentials_file)
204225
205 # Look for the manual-lock list226 # Look for the manual-lock list
206 locked_list = []227 locked_clicks_dir = args.locked_clicks_dir if args.locked_clicks_dir \
207 locked_clicks_path = os.path.join(args.download_dir, 'locked_clicks_list')228 else args.download_dir
208 if os.path.exists(locked_clicks_path):
209 locked_list = [line.strip() for line in open(locked_clicks_path, 'r')]
210229
211 download_list = download_list + get_store_apps(args.download_dir, auth,230 download_list = download_list + get_store_apps(args.download_dir, auth,
212 locked_list)231 locked_clicks_dir)
213232
214 click_list = os.path.join(args.download_dir, 'click_list')233 click_list = os.path.join(args.download_dir, 'click_list')
215 with open(click_list, 'w') as f:234 with open(click_list, 'w') as f:

Subscribers

People subscribed via source and target branches