Mercurial > repos > cathywise > truststore_import
comparison TrustStoreGalaxyImport.py @ 5:159d2159e745
Add list files.
| author | Catherine Wise <catherine.wise@csiro.au> |
|---|---|
| date | Thu, 12 Dec 2013 16:17:43 +1100 |
| parents | 32d9b3343955 |
| children | b94a8f55b1da |
comparison
equal
deleted
inserted
replaced
| 4:32d9b3343955 | 5:159d2159e745 |
|---|---|
| 1 import sys | 1 import sys |
| 2 import shutil | 2 import shutil |
| 3 from py_ts import TrustStoreClient, ts_utils | 3 from py_ts import TrustStoreClient, ts_utils |
| 4 | |
| 5 def printNice(elem, f, depth): | |
| 6 try: | |
| 7 f.write('\t'*depth + elem.name + " (" + str(len(elem.fragments)) + " parts)\n") | |
| 8 except AttributeError: | |
| 9 f.write('\t'*depth + elem.name + "\n") | |
| 10 for child in elem.children: | |
| 11 printNice(child, f, depth+1) | |
| 4 | 12 |
| 5 if __name__ == '__main__': | 13 if __name__ == '__main__': |
| 6 | 14 |
| 7 kms_url = sys.argv[1] | 15 kms_url = sys.argv[1] |
| 8 ims_url = sys.argv[2] | 16 ims_url = sys.argv[2] |
| 10 password = sys.argv[4] | 18 password = sys.argv[4] |
| 11 client_key = sys.argv[5] | 19 client_key = sys.argv[5] |
| 12 client_secret = sys.argv[6] | 20 client_secret = sys.argv[6] |
| 13 storename = sys.argv[7] | 21 storename = sys.argv[7] |
| 14 path = sys.argv[8] | 22 path = sys.argv[8] |
| 15 filename = sys.argv[9] | 23 filename = "" |
| 16 outputFile = sys.argv[10] | 24 outputFile = "" |
| 25 if len(sys.argv) > 10: | |
| 26 filename = sys.argv[9] | |
| 27 outputFile = sys.argv[10] | |
| 28 else: | |
| 29 outputFile = sys.argv[9] | |
| 17 | 30 |
| 18 config = TrustStoreClient.Config(ims_url, kms_url, client_key, client_secret) | 31 config = TrustStoreClient.Config(ims_url, kms_url, client_key, client_secret) |
| 19 ts = TrustStoreClient.TrustStoreClient(headless=True, config=config) | 32 ts = TrustStoreClient.TrustStoreClient(headless=True, config=config) |
| 20 try: | 33 try: |
| 21 ts.authenticate(username, password) | 34 ts.authenticate(username, password) |
| 35 if not location: | 48 if not location: |
| 36 print "Path not found" | 49 print "Path not found" |
| 37 sys.exit(3) | 50 sys.exit(3) |
| 38 else: | 51 else: |
| 39 location = root | 52 location = root |
| 40 downloadMe = ts_utils.ts_utils.recurseToChildNamed(location, filename) | 53 if filename and filename != "": |
| 41 if downloadMe: | 54 downloadMe = ts_utils.ts_utils.recurseToChildNamed(location, filename) |
| 42 download = ts.getFile(store, downloadMe) | 55 if downloadMe: |
| 43 shutil.copy(download, outputFile) | 56 download = ts.getFile(store, downloadMe) |
| 57 shutil.copy(download, outputFile) | |
| 58 else: | |
| 59 print "File not found" | |
| 60 sys.exit(4) | |
| 44 else: | 61 else: |
| 45 print "File not found" | 62 with open(outputFile, 'w+') as f: |
| 46 sys.exit(4) | 63 try: |
| 64 for child in root.children: | |
| 65 printNice(child, f, 0) | |
| 66 except AttributeError as e: | |
| 67 print e | |
| 68 print root | |
| 47 if not found: | 69 if not found: |
| 48 print "Store not found" | 70 print "Store not found" |
| 49 sys.exit(2) | 71 sys.exit(2) |
