Various fixes to notarize command that should have been squashed.
[cdist.git] / cdist
diff --git a/cdist b/cdist
index b508babbdf78d4f875720c35b115c514390ccbae..7f5552230c5989bb16b9dd094a99a43b9478a78d 100755 (executable)
--- a/cdist
+++ b/cdist
@@ -26,6 +26,7 @@ import glob
 import inspect
 import multiprocessing
 import os
+from pathlib import Path
 import platform
 import re
 import shlex
@@ -752,10 +753,10 @@ def notarize_dmg(dmg, bundle_id):
         raise Error('No RequestUUID found in response from Apple')
 
     for i in range(0, 30):
-        print('Checking up on %s' % request_uuid)
+        print('%s: checking up on %s' % (datetime.datetime.now(), request_uuid))
         p = subprocess.run(['xcrun', 'altool', '--notarization-info', request_uuid, '-u', config.get('apple_id'), '-p', config.get('apple_password'), '--output-format', 'xml'], capture_output=True)
         status = string_after(p, 'Status')
-        print('Got %s' % status)
+        print('%s: got status %s' % (datetime.datetime.now(), status))
         if status == 'invalid':
             raise Error("Notarization failed")
         elif status == 'success':
@@ -795,6 +796,9 @@ class OSXTarget(Target):
                 raise Error('macOS packages must be returned from cscript as tuples of (dmg-filename, bundle-id)')
             if notarize:
                 notarize_dmg(x[0], x[1])
+            else:
+                with open(dmg + '.id', 'w') as f:
+                    print(x[1], out=f)
         return [x[0] for x in p]
 
 
@@ -1169,6 +1173,8 @@ def main():
     parser_checkout = subparsers.add_parser("checkout", help="check out the project")
     parser_revision = subparsers.add_parser("revision", help="print the head git revision number")
     parser_dependencies = subparsers.add_parser("dependencies", help="print details of the project's dependencies as a .dot file")
+    parser_notarize = subparsers.add_parser("notarize", help="notarize .dmgs in a directory using *.dmg.id files")
+    parser_notarize.add_argument('--dmgs', help='directory containing *.dmg and *.dmg.id')
 
     global args
     args = parser.parse_args()
@@ -1199,7 +1205,7 @@ def main():
         if not os.path.exists(args.work):
             os.makedirs(args.work)
 
-    if args.project is None and args.command != 'shell':
+    if args.project is None and not args.command in ['shell', 'notarize']:
         raise Error('you must specify -p or --project')
 
     globals.quiet = args.quiet
@@ -1379,6 +1385,18 @@ def main():
             print("%s -> %s;" % (d[2].name.replace("-", "-"), d[0].name.replace("-", "_")))
         print("}")
 
+    elif args.command == 'notarize':
+        if args.dmgs is None:
+            raise Error('you must specify ---dmgs')
+
+        for dmg in Path(args.dmgs).glob('*.dmg'):
+            id = None
+            try:
+                with open(str(dmg) + '.id') as f:
+                    id = f.readline().strip()
+            except OSError:
+                raise Error('could not find ID file for %s' % dmg)
+            notarize_dmg(dmg, id)
 
 try:
     main()