-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathrepoutil
executable file
·739 lines (660 loc) · 30.8 KB
/
repoutil
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright 2011 Disney Enterprises, Inc. All rights reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
# Studios" or the names of its contributors may NOT be used to
# endorse or promote products derived from this software without
# specific prior written permission from Walt Disney Pictures.
# Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
# IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
'''A tool to replicate most of the functionality of
Apple Software Update server'''
import optparse
import os
import shutil
from reposadolib import reposadocommon
def deleteBranchCatalogs(branchname):
'''Removes catalogs corresponding to a deleted branch'''
for catalog_URL in reposadocommon.pref('AppleCatalogURLs'):
localcatalogpath = reposadocommon.getLocalPathNameFromURL(catalog_URL)
# now strip the '.sucatalog' bit from the name
if localcatalogpath.endswith('.sucatalog'):
localcatalogpath = localcatalogpath[0:-10]
branchcatalogpath = localcatalogpath + '_' + branchname + '.sucatalog'
if os.path.exists(branchcatalogpath):
reposadocommon.print_stdout(
'Removing %s', os.path.basename(branchcatalogpath))
os.remove(branchcatalogpath)
def getProductLocation(product, product_id):
'''Returns local path to replicated product
We pass in the product dictionary to avoid calling
reposadocommon.getProductInfo(), which is slow.'''
if not 'CatalogEntry' in product:
# something is wrong with the product entry
return None
catalog_entry = product['CatalogEntry']
product_url = None
if 'ServerMetadataURL' in catalog_entry:
product_url = catalog_entry['ServerMetadataURL']
else:
try:
# get the URL for the first package in the Packages array
product_url = catalog_entry['Packages'][0]['URL']
except (KeyError, IndexError):
return None
filepath = reposadocommon.getLocalPathNameFromURL(product_url)
# return the directory this pkg is in
return os.path.dirname(filepath)
def getRestartNeeded(product):
'''Returns "Yes" if all pkg_refs require a restart or shutdown,
"No" if none do, and "Sometimes" if some do and some don't.
Returns "UNKNOWN" if there is no pkg_ref data for the update.'''
pkgs = product.get('pkg_refs', {}).keys()
pkg_count = len(pkgs)
if pkg_count == 0:
return "UNKNOWN"
restart_count = 0
for pkg in pkgs:
if 'RestartAction' in product['pkg_refs'][pkg]:
restart_count += 1
if restart_count == 0:
# no pkgs require a restart/shutdown/logout
return "No"
elif restart_count == pkg_count:
# all pkgs require a restart/shutdown/logout
return "Yes"
else:
# some pkgs require a restart/shutdown/logout
return "Sometimes"
def print_info(key):
'''Prints detail for a specific product'''
products = reposadocommon.getProductInfo()
if key in products:
product = products[key]
downloaded_products_list = reposadocommon.getDownloadStatus()
if key in downloaded_products_list:
status = "Downloaded"
else:
status = "Not downloaded"
catalog_branches = reposadocommon.getCatalogBranches()
branchlist = [branch for branch in catalog_branches.keys()
if key in catalog_branches[branch]]
reposadocommon.print_stdout('Product: %s', key)
reposadocommon.print_stdout('Title: %s', product.get('title'))
reposadocommon.print_stdout('Version: %s', product.get('version'))
reposadocommon.print_stdout('Size: %s',
reposadocommon.humanReadable(product.get('size', 0)))
reposadocommon.print_stdout(
'Post Date: %s', product.get('PostDate'))
reposadocommon.print_stdout(
'RestartNeeded: %s', getRestartNeeded(product))
if reposadocommon.pref('LocalCatalogURLBase'):
# we're replicating products locally
reposadocommon.print_stdout('Status: %s', status)
if status == 'Downloaded':
reposadocommon.print_stdout(
'Location: %s' % getProductLocation(product, key))
if products[key].get('AppleCatalogs'):
reposadocommon.print_stdout('AppleCatalogs:')
for catalog in product['AppleCatalogs']:
reposadocommon.print_stdout(' %s', catalog)
else:
reposadocommon.print_stdout(' Product is deprecated.')
if product.get('OriginalAppleCatalogs'):
reposadocommon.print_stdout('OriginalAppleCatalogs:')
for catalog in product['OriginalAppleCatalogs']:
reposadocommon.print_stdout(' %s', catalog)
reposadocommon.print_stdout('Branches:')
if branchlist:
for branch in branchlist:
reposadocommon.print_stdout(' %s', branch)
else:
reposadocommon.print_stdout(' <None>')
reposadocommon.print_stdout('HTML Description:')
reposadocommon.print_stdout(product.get('description'))
else:
reposadocommon.print_stdout('No product id %s found.', key)
def print_dist(key):
'''Print the .dist file for a specific product for every language in
PreferredLocalizations'''
products = reposadocommon.getProductInfo()
languages = reposadocommon.pref('PreferredLocalizations')
if key in products:
if products[key].get('CatalogEntry'):
if products[key]['CatalogEntry'].get('Distributions'):
for lang in languages:
if products[key]['CatalogEntry']['Distributions'].get(lang):
distPath = reposadocommon.getLocalPathNameFromURL(
products[key]['CatalogEntry'][
'Distributions'][lang])
try:
distFd = open(distPath, 'r')
distContents = distFd.read()
distFd.close()
reposadocommon.print_stdout(distContents)
except (IOError, OSError), errorMsg:
reposadocommon.print_stderr(
'Error getting %s dist file for product %s:\n%s'
% (lang, key, errorMsg))
else:
reposadocommon.print_stdout('No product id %s found.', key)
def list_branches():
'''Prints catalog branch names'''
catalog_branches = reposadocommon.getCatalogBranches()
for key in catalog_branches.keys():
reposadocommon.print_stdout(key)
def print_product_line(key, products, catalog_branches=None):
'''Prints a line of product info'''
if key in products:
if not catalog_branches:
branchlist = ''
else:
branchlist = [branch for branch in catalog_branches.keys()
if key in catalog_branches[branch]]
branchlist.sort()
deprecation_state = ''
if not products[key].get('AppleCatalogs'):
# not in any Apple catalogs
deprecation_state = '(Deprecated)'
try:
post_date = products[key].get('PostDate').strftime('%Y-%m-%d')
except BaseException:
post_date = 'None'
reposadocommon.print_stdout(
'%-15s %-50s %-10s %-10s %s %s',
key,
products[key].get('title'),
products[key].get('version'),
post_date,
branchlist,
deprecation_state)
else:
reposadocommon.print_stdout('%-15s <MISSING INFO>', key)
def list_branch(branchname, sort_order='date', reverse_sort=False):
'''List products in a given catalog branch'''
catalog_branches = reposadocommon.getCatalogBranches()
if branchname in catalog_branches:
list_products(sort_order, reverse_sort, catalog_branches[branchname])
else:
reposadocommon.print_stderr(
'ERROR: %s is not a valid branch name.' % branchname)
def diff_branches(branch_list):
'''Displays differences between two branches'''
catalog_branches = reposadocommon.getCatalogBranches()
for branch in branch_list:
if not branch in catalog_branches:
reposadocommon.print_stderr(
'ERROR: %s is not a valid branch name.' % branch)
return
branch1 = set(catalog_branches[branch_list[0]])
branch2 = set(catalog_branches[branch_list[1]])
unique_to_first = branch1 - branch2
unique_to_second = branch2 - branch1
if len(unique_to_first) == 0 and len(unique_to_second) == 0:
reposadocommon.print_stdout(
'No differences between %s and %s.' % branch_list)
else:
reposadocommon.print_stdout('Unique to \'%s\':', branch_list[0])
if len(unique_to_first):
list_products(list_of_productids=unique_to_first)
else:
reposadocommon.print_stdout('<none>')
reposadocommon.print_stdout('\nUnique to \'%s\':', branch_list[1])
if len(unique_to_second):
list_products(list_of_productids=unique_to_second)
else:
reposadocommon.print_stdout('<none>')
def list_deprecated(sort_order='date', reverse_sort=False):
'''Find products that are no longer referenced in Apple\'s catalogs'''
products = reposadocommon.getProductInfo()
list_of_productids = [key for key in products.keys()
if not products[key].get('AppleCatalogs')]
list_products(sort_order, reverse_sort, list_of_productids)
def list_non_deprecated(sort_order='date', reverse_sort=False):
'''Find products that are referenced in Apple\'s catalogs'''
products = reposadocommon.getProductInfo()
list_of_productids = [key for key in products.keys()
if products[key].get('AppleCatalogs')]
list_products(sort_order, reverse_sort, list_of_productids)
def list_config_data(sort_order='date', reverse_sort=False):
'''Find updates with \'type="config-data"\' attribute'''
product_info = reposadocommon.getProductInfo()
product_list = product_info.keys()
matching_products = reposadocommon.check_or_remove_config_data_attribute(
product_list, remove_attr=False, products=product_info,
suppress_output=True)
list_products(sort_order, reverse_sort, matching_products)
def list_products(sort_order='date', reverse_sort=False,
list_of_productids=None):
'''Prints a list of Software Update products'''
def sort_by_key(a, b):
"""Internal comparison function for use with sorting"""
return cmp(a['sort_key'], b['sort_key'])
sort_keys = {'date': 'PostDate',
'title': 'title',
'id': 'id'}
sort_key = sort_keys.get(sort_order, 'PostDate')
errormessages = []
products = reposadocommon.getProductInfo()
catalog_branches = reposadocommon.getCatalogBranches()
product_list = []
if list_of_productids == None:
list_of_productids = products.keys()
for productid in list_of_productids:
if not productid in products:
errormessages.append(
'Skipped product %s because it does not exist '
'in the ProductInfo database.' % productid)
continue
product_dict = {}
product_dict['key'] = productid
if sort_key == 'id':
product_dict['sort_key'] = productid
else:
try:
product_dict['sort_key'] = products[productid][sort_key]
except KeyError:
errormessages.append(
'Product %s is missing the sort key %s -- '
'Product info database may be incomplete'
% (productid, sort_key))
continue
product_list.append(product_dict)
product_list.sort(sort_by_key)
if reverse_sort:
product_list.reverse()
for product in product_list:
print_product_line(product['key'], products, catalog_branches)
for error in errormessages:
reposadocommon.print_stderr('WARNING: %s' % error)
def add_product_to_branch(parameters):
'''Adds one or more products to a branch. Takes a list of strings.
The last string must be the name of a branch catalog. All other
strings must be product_ids.'''
# sanity checking
for item in parameters:
if item.startswith('-'):
reposadocommon.print_stderr(
'Ambiguous parameters: can\'t tell if '
'%s is a parameter or an option!', item)
return
branch_name = parameters[-1]
product_id_list = parameters[0:-1]
# remove all duplicate product ids
product_id_list = list(set(product_id_list))
catalog_branches = reposadocommon.getCatalogBranches()
if not branch_name in catalog_branches:
reposadocommon.print_stderr('Catalog branch %s doesn\'t exist!',
branch_name)
return
products = reposadocommon.getProductInfo()
if 'all' in product_id_list:
product_id_list = products.keys()
elif 'non-deprecated' in product_id_list:
product_id_list = [key for key in products.keys()
if products[key].get('AppleCatalogs')]
for product_id in product_id_list:
if not product_id in products:
reposadocommon.print_stderr(
'Product %s doesn\'t exist!', product_id)
else:
try:
title = products[product_id]['title']
vers = products[product_id]['version']
except KeyError:
reposadocommon.print_stderr(
'Product %s is missing a title or version!\n'
'Product info database may be incomplete.\n'
'Info for product:\n%s',
product_id, products[product_id])
# skip this one and move on
continue
if product_id in catalog_branches[branch_name]:
reposadocommon.print_stderr(
'%s (%s-%s) is already in branch %s!',
product_id, title, vers, branch_name)
else:
reposadocommon.print_stdout(
'Adding %s (%s-%s) to branch %s...',
product_id, title, vers, branch_name)
catalog_branches[branch_name].append(product_id)
reposadocommon.writeCatalogBranches(catalog_branches)
reposadocommon.writeAllBranchCatalogs()
def remove_product_from_branch(parameters):
'''Removes one or more products from a branch. Takes a list of strings.
The last string must be the name of a branch catalog. All other
strings must be product_ids.'''
# sanity checking
for item in parameters:
if item.startswith('-'):
reposadocommon.print_stderr(
'Ambiguous parameters: can\'t tell if '
'%s is a parameter or an option!', item)
return
branch_name = parameters[-1]
product_id_list = parameters[0:-1]
catalog_branches = reposadocommon.getCatalogBranches()
if not branch_name in catalog_branches:
reposadocommon.print_stderr(
'Catalog branch %s doesn\'t exist!', branch_name)
return
products = reposadocommon.getProductInfo()
if 'deprecated' in product_id_list:
product_id_list = [key for key in catalog_branches[branch_name]
if not products[key].get('AppleCatalogs')]
else:
# remove all duplicate product ids
product_id_list = list(set(product_id_list))
for product_id in product_id_list:
if product_id in products:
title = products[product_id].get('title')
vers = products[product_id].get('version')
else:
reposadocommon.print_stderr(
'Product %s doesn\'t exist!', product_id)
title = 'UNKNOWN'
vers = 'UNKNOWN'
if not product_id in catalog_branches[branch_name]:
reposadocommon.print_stderr('%s (%s-%s) is not in branch %s!',
product_id, title, vers, branch_name)
continue
reposadocommon.print_stdout('Removing %s (%s-%s) from branch %s...',
product_id, title, vers, branch_name)
catalog_branches[branch_name].remove(product_id)
reposadocommon.writeCatalogBranches(catalog_branches)
reposadocommon.writeAllBranchCatalogs()
def purge_product(product_ids, force=False):
'''Removes products from the ProductInfo.plist and purges their local
replicas (if they exist). Warns and skips if a product is not deprecated
or is in any branch, unless force == True. If force == True, product is
also removed from all branches. This action is destructive and cannot be
undone.
product_ids is a list of productids.'''
# sanity checking
for item in product_ids:
if item.startswith('-'):
reposadocommon.print_stderr('Ambiguous parameters: can\'t tell if '
'%s is a parameter or an option!', item)
return
products = reposadocommon.getProductInfo()
catalog_branches = reposadocommon.getCatalogBranches()
downloaded_product_list = reposadocommon.getDownloadStatus()
if 'all-deprecated' in product_ids:
product_ids.remove('all-deprecated')
deprecated_productids = [key for key in products.keys()
if not products[key].get('AppleCatalogs')]
product_ids.extend(deprecated_productids)
# remove all duplicate product ids
product_ids = list(set(product_ids))
for product_id in product_ids:
if not product_id in products:
reposadocommon.print_stderr(
'Product %s does not exist in the ProductInfo database. '
'Skipping.', product_id)
continue
product = products[product_id]
product_short_info = (
'%s (%s-%s)'
% (product_id, product.get('title'), product.get('version')))
if product.get('AppleCatalogs') and not force:
reposadocommon.print_stderr(
'WARNING: Product %s is in Apple catalogs:\n %s',
product_short_info, '\n '.join(product['AppleCatalogs']))
reposadocommon.print_stderr('Skipping product %s', product_id)
continue
branches_with_product = [branch for branch in catalog_branches.keys()
if product_id in catalog_branches[branch]]
if branches_with_product:
if not force:
reposadocommon.print_stderr(
'WARNING: Product %s is in catalog branches:\n %s',
product_short_info, '\n '.join(branches_with_product))
reposadocommon.print_stderr('Skipping product %s', product_id)
continue
else:
# remove product from all branches
for branch_name in branches_with_product:
reposadocommon.print_stdout(
'Removing %s from branch %s...',
product_short_info, branch_name)
catalog_branches[branch_name].remove(product_id)
local_copy = getProductLocation(product, product_id)
if local_copy:
# remove local replica
reposadocommon.print_stdout(
'Removing replicated %s from %s...',
product_short_info, local_copy)
try:
shutil.rmtree(local_copy)
except (OSError, IOError), err:
reposadocommon.print_stderr(
'Error: %s', err)
# but not fatal, so keep going...
# delete product from ProductInfo database
del products[product_id]
# delete product from downloaded product list
if product_id in downloaded_product_list:
downloaded_product_list.remove(product_id)
# write out changed catalog branches, productInfo,
# and rebuild our local and branch catalogs
reposadocommon.writeDownloadStatus(downloaded_product_list)
reposadocommon.writeCatalogBranches(catalog_branches)
reposadocommon.writeProductInfo(products)
reposadocommon.writeAllLocalCatalogs()
def copy_branches(source_branch, dest_branch, force=False):
'''Copies source_branch to dest_branch, replacing dest_branch'''
# sanity checking
for branch in [source_branch, dest_branch]:
if branch.startswith('-'):
reposadocommon.print_stderr(
'Ambiguous parameters: can\'t tell if %s is a branch name or'
' option!', branch)
return
catalog_branches = reposadocommon.getCatalogBranches()
if not source_branch in catalog_branches:
reposadocommon.print_stderr('Branch %s does not exist!', source_branch)
return
if dest_branch in catalog_branches and not force:
answer = raw_input(
'Really replace contents of branch %s with branch %s? [y/n] '
% (dest_branch, source_branch))
if not answer.lower().startswith('y'):
return
catalog_branches[dest_branch] = catalog_branches[source_branch]
reposadocommon.print_stdout('Copied contents of branch %s to branch %s.',
source_branch, dest_branch)
reposadocommon.writeCatalogBranches(catalog_branches)
reposadocommon.writeAllBranchCatalogs()
def delete_branch(branchname, force=False):
'''Deletes a branch'''
catalog_branches = reposadocommon.getCatalogBranches()
if not branchname in catalog_branches:
reposadocommon.print_stderr('Branch %s does not exist!', branchname)
return
if not force:
answer = raw_input('Really remove branch %s? [y/n] ' % branchname)
if not answer.lower().startswith('y'):
return
del catalog_branches[branchname]
deleteBranchCatalogs(branchname)
reposadocommon.writeCatalogBranches(catalog_branches)
def new_branch(branchname):
'''Creates a new empty branch'''
catalog_branches = reposadocommon.getCatalogBranches()
if branchname in catalog_branches:
reposadocommon.print_stderr('Branch %s already exists!', branchname)
return
catalog_branches[branchname] = []
reposadocommon.writeCatalogBranches(catalog_branches)
def configure():
'''Configures reposado preferences.'''
reposadocommon.configure_prefs()
def remove_config_data(product_ids):
'''Remove the config-data attribute from product dist files'''
if len(product_ids) == 1 and product_ids[0] == 'all':
'''Removes the config-data attribute from all products'''
reposadocommon.print_stdout(
'Checking all products for config-data attributes...')
product_info = reposadocommon.getProductInfo()
product_list = product_info.keys()
updated_products = reposadocommon.check_or_remove_config_data_attribute(
product_list, remove_attr=True, products=product_info,
suppress_output=True)
if updated_products:
reposadocommon.print_stdout(
'config-data attribute removed from:')
for key in updated_products:
reposadocommon.print_stdout(
' %s: %s-%s',
key, product_info[key]['title'], product_info[key]['version'])
else:
reposadocommon.print_stdout(
'No products with config-data attributes found.')
else:
reposadocommon.remove_config_data_attribute(product_ids)
def main():
'''Main command processing'''
p = optparse.OptionParser()
p.set_usage('''Usage: %prog [options]''')
#p.add_option('--sync', action='store_true',
# help="""Synchronize Apple updates""")
p.add_option('--configure', action='store_true',
help='Configure Reposado preferences.')
p.add_option('--products', '--updates', action='store_true',
dest='products',
help='List available updates.')
p.add_option('--deprecated', action='store_true',
help='List deprecated updates.')
p.add_option('--non-deprecated', action='store_true',
help='List non-deprecated updates.')
p.add_option('--config-data', action='store_true',
help="""List updates with 'type="config-data"' attribute""")
p.add_option('--sort', metavar='SORT_ORDER', default='date',
help='Sort list.\n'
'Available sort orders are: date, title, id.')
p.add_option('--reverse', action='store_true',
help='Reverse sort order.')
p.add_option('--branches', '--catalogs',
dest='list_branches', action='store_true',
help='List available branch catalogs.')
p.add_option('--new-branch',
metavar='BRANCH_NAME',
help='Create new empty branch BRANCH_NAME.')
p.add_option('--delete-branch',
metavar='BRANCH_NAME [--force]',
help='Delete branch BRANCH_NAME.')
p.add_option('--copy-branch', nargs=2,
metavar='SOURCE_BRANCH DEST_BRANCH [--force]',
help='Copy all items from SOURCE_BRANCH to '
'DEST_BRANCH. If DEST_BRANCH does not exist, '
'it will be created.')
p.add_option('--list-branch', '--list-catalog',
dest='branch',
metavar='BRANCH_NAME',
help='List updates in branch BRANCH_NAME.')
p.add_option('--diff', '--diff-branch', '--diff-branches',
dest='diff_branch', nargs=2,
metavar='BRANCH1_NAME BRANCH2_NAME',
help='Display differences between two branches.')
p.add_option('--product-info', '--info', metavar='PRODUCT_ID',
dest='info',
help='Print info on a specific update.')
p.add_option('--product-dist', '--dist', metavar='PRODUCT_ID',
dest='dist',
help='Print the contents of the .dist file for a specific '
'update.')
p.add_option('--add-product', '--add-products',
'--add-update', '--add-updates', '--add',
dest='add_product', nargs=2,
metavar='PRODUCT_ID [PRODUCT_ID ...] BRANCH_NAME',
help='Add one or more PRODUCT_IDs to catalog branch '
'BRANCH_NAME. --add-product all BRANCH_NAME will add '
'all cached products, including deprecated products, to '
'catalog BRANCH_NAME. --add-product non-deprecated '
'BRANCH_NAME will add all non-deprecated products to '
'catalog BRANCH_NAME.')
p.add_option('--remove-product', '--remove-products', nargs=2,
metavar='PRODUCT_ID [PRODUCT_ID ...] BRANCH_NAME',
help='Remove one or more PRODUCT_IDs from catalog branch '
'BRANCH_NAME. --remove-product deprecated will remove '
'all deprecated products from BRANCH_NAME.')
p.add_option('--remove-config-data',
metavar='PRODUCT_ID [PRODUCT_ID ...]',
help='Remove the \'type="config-data"\' attribute from one or '
'more PRODUCT_IDs.')
p.add_option('--purge-product', '--purge-products',
metavar='PRODUCT_ID [PRODUCT_ID ...] [--force]',
help='Purge one or more PRODUCT_IDs from product '
'database and remove any locally replicated version.')
p.add_option('--force', action='store_true',
help='Force purge of product, force copy or force delete a '
'branch. Must be used with --purge-product, --copy-branch '
'or --delete-branch options.')
options, arguments = p.parse_args()
if options.configure:
configure()
if options.products:
list_products(sort_order=options.sort, reverse_sort=options.reverse)
if options.deprecated:
list_deprecated(sort_order=options.sort, reverse_sort=options.reverse)
if options.non_deprecated:
list_non_deprecated(sort_order=options.sort, reverse_sort=options.reverse)
if options.config_data:
list_config_data(sort_order=options.sort, reverse_sort=options.reverse)
if options.branch:
list_branch(options.branch, sort_order=options.sort,
reverse_sort=options.reverse)
if options.list_branches:
list_branches()
if options.info:
print_info(options.info)
if options.dist:
print_dist(options.dist)
if options.new_branch:
new_branch(options.new_branch)
if options.copy_branch:
copy_branches(
options.copy_branch[0], options.copy_branch[1], force=options.force)
if options.delete_branch:
delete_branch(options.delete_branch, force=options.force)
if options.diff_branch:
diff_branches(options.diff_branch)
if options.add_product:
params = list(options.add_product)
params.extend(arguments)
add_product_to_branch(params)
if options.remove_product:
params = list(options.remove_product)
params.extend(arguments)
remove_product_from_branch(params)
if options.purge_product:
product_ids = [options.purge_product]
product_ids.extend(arguments)
purge_product(product_ids, force=options.force)
if options.remove_config_data:
params = [options.remove_config_data]
params.extend(arguments)
remove_config_data(params)
if __name__ == '__main__':
main()