"Fossies" - the Fresh Open Source Software Archive

Member "tdesktop-2.6.1/Telegram/build/updates.py" (24 Feb 2021, 10041 Bytes) of package /linux/misc/tdesktop-2.6.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "updates.py" see the Fossies "Dox" file reference documentation.

    1 import os, sys, re, subprocess, datetime, time
    2 
    3 executePath = os.getcwd()
    4 scriptPath = os.path.dirname(os.path.realpath(__file__))
    5 
    6 lastCommit = ''
    7 today = ''
    8 uuid = ''
    9 nextLast = False
   10 nextDate = False
   11 nextUuid = False
   12 building = True
   13 composing = False
   14 for arg in sys.argv:
   15     if nextLast:
   16         lastCommit = arg
   17         nextLast = False
   18     elif nextDate:
   19         today = arg
   20         nextDate = False
   21     elif nextUuid:
   22         uuid = arg
   23         nextUuid = False
   24     elif arg == 'send':
   25         building = False
   26         composing = False
   27     elif arg == 'from':
   28         nextLast = True
   29         building = False
   30         composing = True
   31     elif arg == 'date':
   32         nextDate = True
   33     elif arg == 'request_uuid':
   34         nextUuid = True
   35 
   36 def finish(code, error = ''):
   37     if error != '':
   38         print('[ERROR] ' + error)
   39     global executePath
   40     os.chdir(executePath)
   41     sys.exit(code)
   42 
   43 os.chdir(scriptPath + '/..')
   44 
   45 if 'AC_USERNAME' not in os.environ:
   46     finish(1, 'AC_USERNAME not found!')
   47 username = os.environ['AC_USERNAME']
   48 
   49 if today == '':
   50     today = datetime.datetime.now().strftime("%d_%m_%y")
   51 outputFolder = 'updates/' + today
   52 
   53 archive = 'tdesktop_macOS_' + today + '.zip'
   54 
   55 if building:
   56     print('Building debug version for OS X 10.12+..')
   57 
   58     if os.path.exists('../out/Debug/' + outputFolder):
   59         finish(1, 'Todays updates version exists.')
   60 
   61     if uuid == '':
   62         result = subprocess.call('./configure.sh', shell=True)
   63         if result != 0:
   64             finish(1, 'While calling GYP.')
   65 
   66     os.chdir('../out')
   67     if uuid == '':
   68         result = subprocess.call('cmake --build . --config Debug --target Telegram', shell=True)
   69         if result != 0:
   70             finish(1, 'While building Telegram.')
   71 
   72     os.chdir('Debug')
   73     if uuid == '':
   74         if not os.path.exists('Telegram.app'):
   75             finish(1, 'Telegram.app not found.')
   76 
   77         result = subprocess.call('strip Telegram.app/Contents/MacOS/Telegram', shell=True)
   78         if result != 0:
   79             finish(1, 'While stripping Telegram.')
   80 
   81         result = subprocess.call('codesign --force --deep --timestamp --options runtime --sign "Developer ID Application: John Preston" Telegram.app --entitlements "../../Telegram/Telegram/Telegram.entitlements"', shell=True)
   82         if result != 0:
   83             finish(1, 'While signing Telegram.')
   84 
   85         if not os.path.exists('Telegram.app/Contents/Frameworks/Updater'):
   86             finish(1, 'Updater not found.')
   87         elif not os.path.exists('Telegram.app/Contents/Helpers/crashpad_handler'):
   88             finish(1, 'crashpad_handler not found.')
   89         elif not os.path.exists('Telegram.app/Contents/Resources/Icon.icns'):
   90             finish(1, 'Icon not found.')
   91         elif not os.path.exists('Telegram.app/Contents/_CodeSignature'):
   92             finish(1, 'Signature not found.')
   93 
   94         if os.path.exists(today):
   95             subprocess.call('rm -rf ' + today, shell=True)
   96         result = subprocess.call('mkdir -p ' + today + '/TelegramForcePortable', shell=True)
   97         if result != 0:
   98             finish(1, 'Creating folder ' + today + '/TelegramForcePortable')
   99 
  100         result = subprocess.call('cp -r Telegram.app ' + today + '/', shell=True)
  101         if result != 0:
  102             finish(1, 'Cloning Telegram.app to ' + today + '.')
  103 
  104         result = subprocess.call('zip -r ' + archive + ' ' + today, shell=True)
  105         if result != 0:
  106             finish(1, 'Adding tdesktop to archive.')
  107 
  108         print('Beginning notarization process.')
  109         lines = subprocess.check_output('xcrun altool --notarize-app --primary-bundle-id "com.tdesktop.TelegramDebug" --username "' + username + '" --password "@keychain:AC_PASSWORD" --file "' + archive + '"', stderr=subprocess.STDOUT, shell=True)
  110         print('Response received.')
  111         uuid = ''
  112         for line in lines.split('\n'):
  113             parts = line.strip().split(' ')
  114             if len(parts) > 2 and parts[0] == 'RequestUUID':
  115                 uuid = parts[2]
  116         if uuid == '':
  117             finish(1, 'Could not extract Request UUID. Response: ' + lines)
  118         print('Request UUID: ' + uuid)
  119     else:
  120         print('Continue with request UUID: ' + uuid)
  121 
  122     requestStatus = ''
  123     logUrl = ''
  124     while requestStatus == '':
  125         time.sleep(5)
  126         print('Checking...')
  127         lines = subprocess.check_output('xcrun altool --notarization-info "' + uuid + '" --username "' + username + '" --password "@keychain:AC_PASSWORD"', stderr=subprocess.STDOUT, shell=True)
  128         statusFound = False
  129         for line in lines.split('\n'):
  130             parts = line.strip().split(' ')
  131             if len(parts) > 1:
  132                 if parts[0] == 'LogFileURL:':
  133                     logUrl = parts[1]
  134                 elif parts[0] == 'Status:':
  135                     if parts[1] == 'in':
  136                         print('In progress.')
  137                         statusFound = True
  138                     else:
  139                         requestStatus = parts[1]
  140                         print('Status: ' + requestStatus)
  141                         statusFound = True
  142         if not statusFound:
  143             print('Nothing: ' + lines)
  144     if requestStatus != 'success':
  145         print('Notarization problems, response: ' + lines)
  146         if logUrl != '':
  147             print('Requesting log...')
  148             result = subprocess.call('curl ' + logUrl, shell=True)
  149             if result != 0:
  150                 finish(1, 'Error calling curl ' + logUrl)
  151         finish(1, 'Notarization failed.')
  152     logLines = ''
  153     if logUrl != '':
  154         print('Requesting log...')
  155         logLines = subprocess.check_output('curl ' + logUrl, shell=True)
  156     result = subprocess.call('xcrun stapler staple Telegram.app', shell=True)
  157     if result != 0:
  158         finish(1, 'Error calling stapler')
  159 
  160     subprocess.call('rm -rf ' + today + '/Telegram.app', shell=True)
  161     subprocess.call('rm ' + archive, shell=True)
  162     result = subprocess.call('cp -r Telegram.app ' + today + '/', shell=True)
  163     if result != 0:
  164         finish(1, 'Re-Cloning Telegram.app to ' + today + '.')
  165 
  166     result = subprocess.call('zip -r ' + archive + ' ' + today, shell=True)
  167     if result != 0:
  168         finish(1, 'Re-Adding tdesktop to archive.')
  169     print('Re-Archived.')
  170 
  171     subprocess.call('mkdir -p ' + outputFolder, shell=True)
  172     subprocess.call('mv ' + archive + ' ' + outputFolder + '/', shell=True)
  173     subprocess.call('rm -rf ' + today, shell=True)
  174     print('Finished.')
  175 
  176     if logLines != '':
  177         displayingLog = 0
  178         for line in logLines.split('\n'):
  179             if displayingLog == 1:
  180                 print(line)
  181             else:
  182                 parts = line.strip().split(' ')
  183                 if len(parts) > 1 and parts[0] == '"issues":':
  184                     if parts[1] != 'null':
  185                         print('NB! Notarization log issues:')
  186                         print(line)
  187                         displayingLog = 1
  188                     else:
  189                         displayingLog = -1
  190         if displayingLog == 0:
  191             print('NB! Notarization issues not found: ' + logLines)
  192     else:
  193         print('NB! Notarization log not found.')
  194     finish(0)
  195 
  196 commandPath = scriptPath + '/../../out/Debug/' + outputFolder + '/command.txt'
  197 
  198 if composing:
  199     templatePath = scriptPath + '/../../../DesktopPrivate/updates_template.txt'
  200     if not os.path.exists(templatePath):
  201         finish(1, 'Template file "' + templatePath + '" not found.')
  202 
  203     if not re.match(r'^[a-f0-9]{9,40}$', lastCommit):
  204         finish(1, 'Wrong last commit: ' + lastCommit)
  205 
  206     log = subprocess.check_output(['git', 'log', lastCommit+'..HEAD'])
  207     logLines = log.split('\n')
  208     firstCommit = ''
  209     commits = []
  210     for line in logLines:
  211         if line.startswith('commit '):
  212             commit = line.split(' ')[1]
  213             if not len(firstCommit):
  214                 firstCommit = commit
  215             commits.append('')
  216         elif line.startswith('    '):
  217             stripped = line[4:]
  218             if not len(stripped):
  219                 continue
  220             elif not len(commits):
  221                 print(log)
  222                 finish(1, 'Bad git log output.')
  223             if len(commits[len(commits) - 1]):
  224                 commits[len(commits) - 1] += '\n' + stripped
  225             else:
  226                 commits[len(commits) - 1] = '- ' + stripped
  227     commits.reverse()
  228     if not len(commits):
  229         finish(1, 'No commits since last build :(')
  230 
  231     changelog = '\n'.join(commits)
  232     print('\n\nReady! File: ' + archive + '\nChangelog:\n' + changelog)
  233     with open(templatePath, 'r') as template:
  234         with open(commandPath, 'w') as f:
  235             for line in template:
  236                 if line.startswith('//'):
  237                     continue
  238                 line = line.replace('{path}', scriptPath + '/../../out/Debug/' + outputFolder + '/' + archive)
  239                 line = line.replace('{caption}', 'TDesktop at ' + today.replace('_', '.') + ':\n\n' + changelog)
  240                 f.write(line)
  241     print('\n\nEdit:\n')
  242     print('vi ' + commandPath)
  243     finish(0)
  244 
  245 if not os.path.exists(commandPath):
  246     finish(1, 'Command file not found.')
  247 
  248 readingCaption = False
  249 caption = ''
  250 with open(commandPath, 'r') as f:
  251     for line in f:
  252         if readingCaption:
  253             caption = caption + line
  254         elif line.startswith('caption: '):
  255             readingCaption = True
  256             caption = line[len('caption: '):]
  257             if not caption.startswith('TDesktop at ' + today.replace('_', '.') + ':'):
  258                 finish(1, 'Wrong caption start.')
  259 print('\n\nSending! File: ' + archive + '\nChangelog:\n' + caption)
  260 if len(caption) > 1024:
  261     print('Length: ' + str(len(caption)))
  262     print('vi ' + commandPath)
  263     finish(1, 'Too large.')
  264 
  265 if not os.path.exists('../out/Debug/' + outputFolder + '/' + archive):
  266     finish(1, 'Not built yet.')
  267 
  268 subprocess.call(scriptPath + '/../../out/Debug/Telegram.app/Contents/MacOS/Telegram -sendpath interpret://' + scriptPath + '/../../out/Debug/' + outputFolder + '/command.txt', shell=True)
  269 
  270 finish(0)