Improve updates sending script.

This commit is contained in:
John Preston 2018-12-25 19:42:02 +04:00
parent e5536880fb
commit 6fc4facddf

View file

@ -8,6 +8,7 @@ today = ''
nextLast = False nextLast = False
nextDate = False nextDate = False
building = True building = True
composing = False
for arg in sys.argv: for arg in sys.argv:
if nextLast: if nextLast:
lastCommit = arg lastCommit = arg
@ -17,8 +18,11 @@ for arg in sys.argv:
nextDate = False nextDate = False
elif arg == 'send': elif arg == 'send':
building = False building = False
composing = False
elif arg == 'from': elif arg == 'from':
nextLast = True nextLast = True
building = False
composing = True
elif arg == 'date': elif arg == 'date':
nextDate = True nextDate = True
@ -103,11 +107,7 @@ if building:
print('Finished.') print('Finished.')
finish(0) finish(0)
if composing:
if not os.path.exists('../out/Debug/' + outputFolder + '/' + archive):
print('[ERROR] Not built yet.')
finish(1)
templatePath = scriptPath + '/../../../TelegramPrivate/updates_template.txt' templatePath = scriptPath + '/../../../TelegramPrivate/updates_template.txt'
if not os.path.exists(templatePath): if not os.path.exists(templatePath):
print('[ERROR] Template file "' + templatePath + '" not found.') print('[ERROR] Template file "' + templatePath + '" not found.')
@ -146,9 +146,6 @@ if not len(commits):
changelog = '\n'.join(commits) changelog = '\n'.join(commits)
print('\n\nReady! File: ' + archive + '\nChangelog:\n' + changelog) print('\n\nReady! File: ' + archive + '\nChangelog:\n' + changelog)
if len(changelog) > 1024:
print('[ERROR] Length: ' + str(len(changelog)))
finish(1)
with open(templatePath, 'r') as template: with open(templatePath, 'r') as template:
with open(scriptPath + '/../../out/Debug/' + outputFolder + '/command.txt', 'w') as f: with open(scriptPath + '/../../out/Debug/' + outputFolder + '/command.txt', 'w') as f:
for line in template: for line in template:
@ -157,6 +154,35 @@ with open(templatePath, 'r') as template:
line = line.replace('{path}', scriptPath + '/../../out/Debug/' + outputFolder + '/' + archive) line = line.replace('{path}', scriptPath + '/../../out/Debug/' + outputFolder + '/' + archive)
line = line.replace('{caption}', 'TDesktop at ' + today.replace('_', '.') + ':\n\n' + changelog) line = line.replace('{caption}', 'TDesktop at ' + today.replace('_', '.') + ':\n\n' + changelog)
f.write(line) f.write(line)
finish(0)
commandPath = scriptPath + '/../../out/Debug/' + outputFolder + '/command.txt'
if not os.path.exists(commandPath):
print('[ERROR] Command file not found.')
finish(1)
readingCaption = False
caption = ''
with open(commandPath, 'r') as f:
for line in f:
if readingCaption:
caption = caption + line
elif line.startswith('caption: '):
readingCaption = True
caption = line[len('caption: '):]
if not caption.startswith('TDesktop at ' + today.replace('_', '.') + ':'):
print('[ERROR] Wrong caption start.')
finish(1)
print('\n\nSending! File: ' + archive + '\nChangelog:\n' + caption)
if len(caption) > 1024:
print('[ERROR] Length: ' + str(len(caption)))
print('vi ' + commandPath)
finish(1)
if not os.path.exists('../out/Debug/' + outputFolder + '/' + archive):
print('[ERROR] Not built yet.')
finish(1)
subprocess.call(scriptPath + '/../../out/Debug/Telegram.app/Contents/MacOS/Telegram -sendpath interpret://' + scriptPath + '/../../out/Debug/' + outputFolder + '/command.txt', shell=True) subprocess.call(scriptPath + '/../../out/Debug/Telegram.app/Contents/MacOS/Telegram -sendpath interpret://' + scriptPath + '/../../out/Debug/' + outputFolder + '/command.txt', shell=True)
finish(0) finish(0)