From 4bb028f48ecfcde1f4d2feafbc71fc8e346a7b99 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Fri, 7 Dec 2012 14:45:16 +0100 Subject: devscripts/make_readme.py in place of all that sedding, that has porting problems --- devscripts/make_readme.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 devscripts/make_readme.py (limited to 'devscripts') diff --git a/devscripts/make_readme.py b/devscripts/make_readme.py new file mode 100644 index 000000000..57ff0456e --- /dev/null +++ b/devscripts/make_readme.py @@ -0,0 +1,21 @@ +import sys +import re + +helptext = sys.stdin.read() + +f = open('README.md') +oldreadme = f.read() +f.close() + +header = oldreadme[:oldreadme.index('# OPTIONS')] +footer = oldreadme[oldreadme.index('# CONFIGURATION'):] + +options = helptext[helptext.index(' General Options:')+19:] +options = re.sub(r'^ (\w.+)$', r'## \1', options, flags=re.M) +options = '# OPTIONS\n' + options + '\n' + +f = open('README.md', 'w') +f.write(header) +f.write(options) +f.write(footer) +f.close() \ No newline at end of file -- cgit v1.2.3 From bdff345529dee85e2c2bc9f142b1df17e4ee266b Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Fri, 7 Dec 2012 21:38:45 +0100 Subject: adding a proper bash-completion generation --- devscripts/bash_completion.py | 22 ++++++++++++++++++++++ devscripts/bash_completion.template | 14 ++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 devscripts/bash_completion.py create mode 100644 devscripts/bash_completion.template (limited to 'devscripts') diff --git a/devscripts/bash_completion.py b/devscripts/bash_completion.py new file mode 100644 index 000000000..1cbfa8bec --- /dev/null +++ b/devscripts/bash_completion.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python2 +import youtube_dl + +BASH_COMPLETION_FILE = "youtube-dl.bash_completion" +BASH_COMPLETION_TEMPLATE = "devscripts/bash_completion.template" + +def build_completion(opt_parser): + opts_flag = [] + for group in opt_parser.option_groups: + for option in group.option_list: + #for every long flag + opts_flag.append(option.get_opt_string()) + with open(BASH_COMPLETION_TEMPLATE) as f: + template = f.read() + with open(BASH_COMPLETION_FILE, "w") as f: + #just using the special char + print opts_flag + filled_template = template.replace("{{flags}}", " ".join(opts_flag)) + f.write(filled_template) + +parser = youtube_dl.parseOpts()[0] +build_completion(parser) diff --git a/devscripts/bash_completion.template b/devscripts/bash_completion.template new file mode 100644 index 000000000..3b99a9614 --- /dev/null +++ b/devscripts/bash_completion.template @@ -0,0 +1,14 @@ +__youtube-dl() +{ + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + opts="{{flags}}" + + if [[ ${cur} == * ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + fi +} + +complete -F __youtube-dl youtube-dl -- cgit v1.2.3 From 682407f2d5048cf034faf75b3e3611db31850f91 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Fri, 7 Dec 2012 21:40:06 +0100 Subject: little correction on the readme --- devscripts/make_readme.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'devscripts') diff --git a/devscripts/make_readme.py b/devscripts/make_readme.py index 57ff0456e..7f2ea319c 100644 --- a/devscripts/make_readme.py +++ b/devscripts/make_readme.py @@ -1,11 +1,11 @@ import sys import re +README_FILE = 'README.md' helptext = sys.stdin.read() -f = open('README.md') -oldreadme = f.read() -f.close() +with open(README_FILE) as f: + oldreadme = f.read() header = oldreadme[:oldreadme.index('# OPTIONS')] footer = oldreadme[oldreadme.index('# CONFIGURATION'):] @@ -14,8 +14,7 @@ options = helptext[helptext.index(' General Options:')+19:] options = re.sub(r'^ (\w.+)$', r'## \1', options, flags=re.M) options = '# OPTIONS\n' + options + '\n' -f = open('README.md', 'w') -f.write(header) -f.write(options) -f.write(footer) -f.close() \ No newline at end of file +with open(README_FILE, 'w') as f: + f.write(header) + f.write(options) + f.write(footer) -- cgit v1.2.3 From a9d2f7e8945abfb792b76ba551f568d3580c30a6 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Fri, 7 Dec 2012 21:59:59 +0100 Subject: making the script compatible with python3 --- devscripts/bash_completion.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'devscripts') diff --git a/devscripts/bash_completion.py b/devscripts/bash_completion.py index 1cbfa8bec..704034f22 100644 --- a/devscripts/bash_completion.py +++ b/devscripts/bash_completion.py @@ -1,4 +1,9 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python +import os +from os.path import dirname as dirn +import sys + +sys.path.append(dirn(dirn((os.path.abspath(__file__))))) import youtube_dl BASH_COMPLETION_FILE = "youtube-dl.bash_completion" @@ -14,7 +19,6 @@ def build_completion(opt_parser): template = f.read() with open(BASH_COMPLETION_FILE, "w") as f: #just using the special char - print opts_flag filled_template = template.replace("{{flags}}", " ".join(opts_flag)) f.write(filled_template) -- cgit v1.2.3 From 4c1d273e88a88f7a7b9e09bb2bbadb161d25b615 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Sat, 8 Dec 2012 00:37:26 +0100 Subject: it's curious but bash-completion is with - and not _ --- devscripts/bash-completion.py | 26 ++++++++++++++++++++++++++ devscripts/bash-completion.template | 14 ++++++++++++++ devscripts/bash_completion.py | 26 -------------------------- devscripts/bash_completion.template | 14 -------------- 4 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 devscripts/bash-completion.py create mode 100644 devscripts/bash-completion.template delete mode 100644 devscripts/bash_completion.py delete mode 100644 devscripts/bash_completion.template (limited to 'devscripts') diff --git a/devscripts/bash-completion.py b/devscripts/bash-completion.py new file mode 100644 index 000000000..880db7886 --- /dev/null +++ b/devscripts/bash-completion.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +import os +from os.path import dirname as dirn +import sys + +sys.path.append(dirn(dirn((os.path.abspath(__file__))))) +import youtube_dl + +BASH_COMPLETION_FILE = "youtube-dl.bash-completion" +BASH_COMPLETION_TEMPLATE = "devscripts/bash-completion.template" + +def build_completion(opt_parser): + opts_flag = [] + for group in opt_parser.option_groups: + for option in group.option_list: + #for every long flag + opts_flag.append(option.get_opt_string()) + with open(BASH_COMPLETION_TEMPLATE) as f: + template = f.read() + with open(BASH_COMPLETION_FILE, "w") as f: + #just using the special char + filled_template = template.replace("{{flags}}", " ".join(opts_flag)) + f.write(filled_template) + +parser = youtube_dl.parseOpts()[0] +build_completion(parser) diff --git a/devscripts/bash-completion.template b/devscripts/bash-completion.template new file mode 100644 index 000000000..3b99a9614 --- /dev/null +++ b/devscripts/bash-completion.template @@ -0,0 +1,14 @@ +__youtube-dl() +{ + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + opts="{{flags}}" + + if [[ ${cur} == * ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + fi +} + +complete -F __youtube-dl youtube-dl diff --git a/devscripts/bash_completion.py b/devscripts/bash_completion.py deleted file mode 100644 index 704034f22..000000000 --- a/devscripts/bash_completion.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python -import os -from os.path import dirname as dirn -import sys - -sys.path.append(dirn(dirn((os.path.abspath(__file__))))) -import youtube_dl - -BASH_COMPLETION_FILE = "youtube-dl.bash_completion" -BASH_COMPLETION_TEMPLATE = "devscripts/bash_completion.template" - -def build_completion(opt_parser): - opts_flag = [] - for group in opt_parser.option_groups: - for option in group.option_list: - #for every long flag - opts_flag.append(option.get_opt_string()) - with open(BASH_COMPLETION_TEMPLATE) as f: - template = f.read() - with open(BASH_COMPLETION_FILE, "w") as f: - #just using the special char - filled_template = template.replace("{{flags}}", " ".join(opts_flag)) - f.write(filled_template) - -parser = youtube_dl.parseOpts()[0] -build_completion(parser) diff --git a/devscripts/bash_completion.template b/devscripts/bash_completion.template deleted file mode 100644 index 3b99a9614..000000000 --- a/devscripts/bash_completion.template +++ /dev/null @@ -1,14 +0,0 @@ -__youtube-dl() -{ - local cur prev opts - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - opts="{{flags}}" - - if [[ ${cur} == * ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - fi -} - -complete -F __youtube-dl youtube-dl -- cgit v1.2.3 From c7287a3cafba65b700b64633d76aa016f5cbc95d Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Sat, 8 Dec 2012 01:28:44 +0100 Subject: ATTENTION DO NOT USE THESE: new binaries in the Downloads section placed fake binaries that update themselves where old versions updating will search for the new version --- devscripts/transition_helper.py | 40 +++++++++++++++++++++ devscripts/transition_helper_exe/setup.py | 12 +++++++ devscripts/transition_helper_exe/youtube-dl.py | 49 ++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 devscripts/transition_helper.py create mode 100644 devscripts/transition_helper_exe/setup.py create mode 100644 devscripts/transition_helper_exe/youtube-dl.py (limited to 'devscripts') diff --git a/devscripts/transition_helper.py b/devscripts/transition_helper.py new file mode 100644 index 000000000..d5ca2d4ba --- /dev/null +++ b/devscripts/transition_helper.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +import sys, os + +try: + import urllib.request as compat_urllib_request +except ImportError: # Python 2 + import urllib2 as compat_urllib_request + +sys.stderr.write(u'Hi! We changed distribution method and now youtube-dl needs to update itself one more time.\n') +sys.stderr.write(u'This will only happen once. Simply press enter to go on. Sorry for the trouble!\n') +sys.stderr.write(u'The new location of the binaries is https://github.com/rg3/youtube-dl/downloads, not the git repository.\n\n') + +try: + raw_input() +except NameError: # Python 3 + input() + +filename = sys.argv[0] + +API_URL = "https://api.github.com/repos/rg3/youtube-dl/downloads" +BIN_URL = "https://github.com/downloads/rg3/youtube-dl/youtube-dl" + +if not os.access(filename, os.W_OK): + sys.exit('ERROR: no write permissions on %s' % filename) + +try: + urlh = compat_urllib_request.urlopen(BIN_URL) + newcontent = urlh.read() + urlh.close() +except (IOError, OSError) as err: + sys.exit('ERROR: unable to download latest version') + +try: + with open(filename, 'wb') as outf: + outf.write(newcontent) +except (IOError, OSError) as err: + sys.exit('ERROR: unable to overwrite current version') + +sys.stderr.write(u'Done! Now you can run youtube-dl.\n') diff --git a/devscripts/transition_helper_exe/setup.py b/devscripts/transition_helper_exe/setup.py new file mode 100644 index 000000000..aaf5c2983 --- /dev/null +++ b/devscripts/transition_helper_exe/setup.py @@ -0,0 +1,12 @@ +from distutils.core import setup +import py2exe + +py2exe_options = { + "bundle_files": 1, + "compressed": 1, + "optimize": 2, + "dist_dir": '.', + "dll_excludes": ['w9xpopen.exe'] +} + +setup(console=['youtube-dl.py'], options={ "py2exe": py2exe_options }, zipfile=None) \ No newline at end of file diff --git a/devscripts/transition_helper_exe/youtube-dl.py b/devscripts/transition_helper_exe/youtube-dl.py new file mode 100644 index 000000000..409f980bc --- /dev/null +++ b/devscripts/transition_helper_exe/youtube-dl.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +import sys, os +import urllib2 + +sys.stderr.write(u'Hi! We changed distribution method and now youtube-dl needs to update itself one more time.\n') +sys.stderr.write(u'This will only happen once. Simply press enter to go on. Sorry for the trouble!\n') +sys.stderr.write(u'The new location of the binaries is https://github.com/rg3/youtube-dl/downloads, not the git repository.\n\n') + +raw_input() + +filename = sys.argv[0] + +API_URL = "https://api.github.com/repos/rg3/youtube-dl/downloads" +EXE_URL = "https://github.com/downloads/rg3/youtube-dl/youtube-dl.exe" + +if not os.access(filename, os.W_OK): + sys.exit('ERROR: no write permissions on %s' % filename) + +exe = os.path.abspath(filename) +directory = os.path.dirname(exe) +if not os.access(directory, os.W_OK): + sys.exit('ERROR: no write permissions on %s' % directory) + +try: + urlh = urllib2.urlopen(EXE_URL) + newcontent = urlh.read() + urlh.close() + with open(exe + '.new', 'wb') as outf: + outf.write(newcontent) +except (IOError, OSError) as err: + sys.exit('ERROR: unable to download latest version') + +try: + bat = os.path.join(directory, 'youtube-dl-updater.bat') + b = open(bat, 'w') + b.write(""" +echo Updating youtube-dl... +ping 127.0.0.1 -n 5 -w 1000 > NUL +move /Y "%s.new" "%s" +del "%s" + \n""" %(exe, exe, bat)) + b.close() + + os.startfile(bat) +except (IOError, OSError) as err: + sys.exit('ERROR: unable to overwrite current version') + +sys.stderr.write(u'Done! Now you can run youtube-dl.\n') -- cgit v1.2.3 From a4680a590f46b1cee44be04d7f285bbe7b6a8d63 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Tue, 11 Dec 2012 19:17:02 +0100 Subject: changing the template file extension --- devscripts/bash-completion.in | 14 ++++++++++++++ devscripts/bash-completion.py | 2 +- devscripts/bash-completion.template | 14 -------------- 3 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 devscripts/bash-completion.in delete mode 100644 devscripts/bash-completion.template (limited to 'devscripts') diff --git a/devscripts/bash-completion.in b/devscripts/bash-completion.in new file mode 100644 index 000000000..3b99a9614 --- /dev/null +++ b/devscripts/bash-completion.in @@ -0,0 +1,14 @@ +__youtube-dl() +{ + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + opts="{{flags}}" + + if [[ ${cur} == * ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + fi +} + +complete -F __youtube-dl youtube-dl diff --git a/devscripts/bash-completion.py b/devscripts/bash-completion.py index 880db7886..49287724d 100644 --- a/devscripts/bash-completion.py +++ b/devscripts/bash-completion.py @@ -7,7 +7,7 @@ sys.path.append(dirn(dirn((os.path.abspath(__file__))))) import youtube_dl BASH_COMPLETION_FILE = "youtube-dl.bash-completion" -BASH_COMPLETION_TEMPLATE = "devscripts/bash-completion.template" +BASH_COMPLETION_TEMPLATE = "devscripts/bash-completion.in" def build_completion(opt_parser): opts_flag = [] diff --git a/devscripts/bash-completion.template b/devscripts/bash-completion.template deleted file mode 100644 index 3b99a9614..000000000 --- a/devscripts/bash-completion.template +++ /dev/null @@ -1,14 +0,0 @@ -__youtube-dl() -{ - local cur prev opts - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - opts="{{flags}}" - - if [[ ${cur} == * ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - fi -} - -complete -F __youtube-dl youtube-dl -- cgit v1.2.3 From cb6ff87fbb05e421f77b57a79699c647866ceb09 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Wed, 26 Dec 2012 23:22:49 +0100 Subject: The new updates system, relies on gh-pages, secured by RSA, uses external web servers --- devscripts/transition_helper_exe/youtube-dl.py | 63 ++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 5 deletions(-) (limited to 'devscripts') diff --git a/devscripts/transition_helper_exe/youtube-dl.py b/devscripts/transition_helper_exe/youtube-dl.py index 409f980bc..dbb4c99e1 100644 --- a/devscripts/transition_helper_exe/youtube-dl.py +++ b/devscripts/transition_helper_exe/youtube-dl.py @@ -2,17 +2,48 @@ import sys, os import urllib2 +import json, hashlib + +def rsa_verify(message, signature, key): + from struct import pack + from hashlib import sha256 + from sys import version_info + def b(x): + if version_info[0] == 2: return x + else: return x.encode('latin1') + assert(type(message) == type(b(''))) + block_size = 0 + n = key[0] + while n: + block_size += 1 + n >>= 8 + signature = pow(int(signature, 16), key[1], key[0]) + raw_bytes = [] + while signature: + raw_bytes.insert(0, pack("B", signature & 0xFF)) + signature >>= 8 + signature = (block_size - len(raw_bytes)) * b('\x00') + b('').join(raw_bytes) + if signature[0:2] != b('\x00\x01'): return False + signature = signature[2:] + if not b('\x00') in signature: return False + signature = signature[signature.index(b('\x00'))+1:] + if not signature.startswith(b('\x30\x31\x30\x0D\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01\x05\x00\x04\x20')): return False + signature = signature[19:] + if signature != sha256(message).digest(): return False + return True sys.stderr.write(u'Hi! We changed distribution method and now youtube-dl needs to update itself one more time.\n') sys.stderr.write(u'This will only happen once. Simply press enter to go on. Sorry for the trouble!\n') -sys.stderr.write(u'The new location of the binaries is https://github.com/rg3/youtube-dl/downloads, not the git repository.\n\n') +sys.stderr.write(u'From now on, get the binaries from http://rg3.github.com/youtube-dl/download.html, not from the git repository.\n\n') raw_input() filename = sys.argv[0] -API_URL = "https://api.github.com/repos/rg3/youtube-dl/downloads" -EXE_URL = "https://github.com/downloads/rg3/youtube-dl/youtube-dl.exe" +UPDATE_URL = "http://rg3.github.com/youtube-dl/update/" +VERSION_URL = UPDATE_URL + 'LATEST_VERSION' +JSON_URL = UPDATE_URL + 'versions.json' +UPDATES_RSA_KEY = (0x9d60ee4d8f805312fdb15a62f87b95bd66177b91df176765d13514a0f1754bcd2057295c5b6f1d35daa6742c3ffc9a82d3e118861c207995a8031e151d863c9927e304576bc80692bc8e094896fcf11b66f3e29e04e3a71e9a11558558acea1840aec37fc396fb6b65dc81a1c4144e03bd1c011de62e3f1357b327d08426fe93, 65537) if not os.access(filename, os.W_OK): sys.exit('ERROR: no write permissions on %s' % filename) @@ -23,13 +54,35 @@ if not os.access(directory, os.W_OK): sys.exit('ERROR: no write permissions on %s' % directory) try: - urlh = urllib2.urlopen(EXE_URL) + versions_info = urllib2.urlopen(JSON_URL).read().decode('utf-8') + versions_info = json.loads(versions_info) +except: + sys.exit(u'ERROR: can\'t obtain versions info. Please try again later.') +if not 'signature' in versions_info: + sys.exit(u'ERROR: the versions file is not signed or corrupted. Aborting.') +signature = versions_info['signature'] +del versions_info['signature'] +if not rsa_verify(json.dumps(versions_info, sort_keys=True), signature, UPDATES_RSA_KEY): + sys.exit(u'ERROR: the versions file signature is invalid. Aborting.') + +version = versions_info['versions'][versions_info['latest']] + +try: + urlh = urllib2.urlopen(version['exe'][0]) newcontent = urlh.read() urlh.close() +except (IOError, OSError) as err: + sys.exit('ERROR: unable to download latest version') + +newcontent_hash = hashlib.sha256(newcontent).hexdigest() +if newcontent_hash != version['exe'][1]: + sys.exit(u'ERROR: the downloaded file hash does not match. Aborting.') + +try: with open(exe + '.new', 'wb') as outf: outf.write(newcontent) except (IOError, OSError) as err: - sys.exit('ERROR: unable to download latest version') + sys.exit(u'ERROR: unable to write the new version') try: bat = os.path.join(directory, 'youtube-dl-updater.bat') -- cgit v1.2.3 From 067f6a3536cfd8338c1d17400128d5cec405bce7 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Sun, 30 Dec 2012 21:02:19 +0100 Subject: moved docs and updates generation scripts from gh-pages branch to devscripts --- devscripts/gh-pages/generate-download.py | 33 ++++++++++++++++++++++++++++++++ devscripts/gh-pages/sign_versions.py | 30 +++++++++++++++++++++++++++++ devscripts/gh-pages/update-copyright.py | 21 ++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100755 devscripts/gh-pages/generate-download.py create mode 100755 devscripts/gh-pages/sign_versions.py create mode 100755 devscripts/gh-pages/update-copyright.py (limited to 'devscripts') diff --git a/devscripts/gh-pages/generate-download.py b/devscripts/gh-pages/generate-download.py new file mode 100755 index 000000000..f19729f59 --- /dev/null +++ b/devscripts/gh-pages/generate-download.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +import hashlib +import shutil +import subprocess +import tempfile +import urllib.request + +URL = 'https://github.com/downloads/rg3/youtube-dl/youtube-dl' + +with tempfile.NamedTemporaryFile(suffix='youtube-dl', delete=True) as ytdl_file: + with urllib.request.urlopen(URL) as dl: + shutil.copyfileobj(dl, ytdl_file) + + ytdl_file.seek(0) + data = ytdl_file.read() + + ytdl_file.flush() + version = subprocess.check_output(['python3', ytdl_file.name, '--version']).decode('ascii').strip() + +# Read template page +with open('download.html.in', 'r', encoding='utf-8') as tmplf: + template = tmplf.read() + +md5sum = hashlib.md5(data).hexdigest() +sha1sum = hashlib.sha1(data).hexdigest() +sha256sum = hashlib.sha256(data).hexdigest() +template = template.replace('@PROGRAM_VERSION@', version) +template = template.replace('@PROGRAM_URL@', URL) +template = template.replace('@PROGRAM_MD5SUM@', md5sum) +template = template.replace('@PROGRAM_SHA1SUM@', sha1sum) +template = template.replace('@PROGRAM_SHA256SUM@', sha256sum) +with open('download.html', 'w', encoding='utf-8') as dlf: + dlf.write(template) diff --git a/devscripts/gh-pages/sign_versions.py b/devscripts/gh-pages/sign_versions.py new file mode 100755 index 000000000..5d94a3a03 --- /dev/null +++ b/devscripts/gh-pages/sign_versions.py @@ -0,0 +1,30 @@ +#! /usr/bin/env python3 + +import rsa +import json +from binascii import hexlify + +# TODO path discovery +versions_info = json.load(open('update/versions.json')) +if 'signature' in versions_info: + del versions_info['signature'] + + +print('Enter the PKCS1 private key, followed by a blank line:') +privkey = '' +while True: + try: + line = input() + except EOFError: + break + if line == '': + break + privkey += line + '\n' +privkey = bytes(privkey, 'ascii') +privkey = rsa.PrivateKey.load_pkcs1(privkey) + +signature = hexlify(rsa.pkcs1.sign(json.dumps(versions_info, sort_keys=True).encode('utf-8'), privkey, 'SHA-256')).decode() +print('signature: ' + signature) + +versions_info['signature'] = signature +json.dump(versions_info, open('update/versions.json', 'w'), indent=4, sort_keys=True) \ No newline at end of file diff --git a/devscripts/gh-pages/update-copyright.py b/devscripts/gh-pages/update-copyright.py new file mode 100755 index 000000000..12c2a9194 --- /dev/null +++ b/devscripts/gh-pages/update-copyright.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# coding: utf-8 + +from __future__ import with_statement + +import datetime +import glob +import io # For Python 2 compatibilty +import os +import re + +year = str(datetime.datetime.now().year) +for fn in glob.glob('*.html*'): + with io.open(fn, encoding='utf-8') as f: + content = f.read() + newc = re.sub(u'(?PCopyright © 2006-)(?P[0-9]{4})', u'Copyright © 2006-' + year, content) + if content != newc: + tmpFn = fn + '.part' + with io.open(tmpFn, 'wt', encoding='utf-8') as outf: + outf.write(newc) + os.rename(tmpFn, fn) -- cgit v1.2.3 From b962b76f439f5614c5ce10c4efc601f290311986 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Mon, 31 Dec 2012 19:15:30 +0100 Subject: re-worked release workflow, it is one-step and creates GPG signatures now --- devscripts/bash-completion.py | 0 devscripts/gh-pages/add-version.py | 33 +++++++++++++++ devscripts/gh-pages/generate-download.py | 19 ++++----- devscripts/gh-pages/sign-versions.py | 28 ++++++++++++ devscripts/gh-pages/sign_versions.py | 30 ------------- devscripts/make_readme.py | 0 devscripts/release.sh | 73 +++++++++++++++++++++++++++++--- 7 files changed, 138 insertions(+), 45 deletions(-) mode change 100644 => 100755 devscripts/bash-completion.py create mode 100755 devscripts/gh-pages/add-version.py create mode 100755 devscripts/gh-pages/sign-versions.py delete mode 100755 devscripts/gh-pages/sign_versions.py mode change 100644 => 100755 devscripts/make_readme.py (limited to 'devscripts') diff --git a/devscripts/bash-completion.py b/devscripts/bash-completion.py old mode 100644 new mode 100755 diff --git a/devscripts/gh-pages/add-version.py b/devscripts/gh-pages/add-version.py new file mode 100755 index 000000000..6af8bb9d8 --- /dev/null +++ b/devscripts/gh-pages/add-version.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +import json +import sys +import hashlib +import urllib.request + +if len(sys.argv) <= 1: + print('Specify the version number as parameter') + sys.exit() +version = sys.argv[1] + +with open('update/LATEST_VERSION', 'w') as f: + f.write(version) + +versions_info = json.load(open('update/versions.json')) +if 'signature' in versions_info: + del versions_info['signature'] + +new_version = {} + +filenames = {'bin': 'youtube-dl', 'exe': 'youtube-dl.exe', 'tar': 'youtube-dl-%s.tar.gz' % version} +for key, filename in filenames.items(): + print('Downloading and checksumming %s...' %filename) + url = 'http://youtube-dl.org/downloads/%s/%s' % (version, filename) + data = urllib.request.urlopen(url).read() + sha256sum = hashlib.sha256(data).hexdigest() + new_version[key] = (url, sha256sum) + +versions_info['versions'][version] = new_version +versions_info['latest'] = version + +json.dump(versions_info, open('update/versions.json', 'w'), indent=4, sort_keys=True) \ No newline at end of file diff --git a/devscripts/gh-pages/generate-download.py b/devscripts/gh-pages/generate-download.py index f19729f59..55912e12c 100755 --- a/devscripts/gh-pages/generate-download.py +++ b/devscripts/gh-pages/generate-download.py @@ -4,18 +4,13 @@ import shutil import subprocess import tempfile import urllib.request +import json -URL = 'https://github.com/downloads/rg3/youtube-dl/youtube-dl' +versions_info = json.load(open('update/versions.json')) +version = versions_info['latest'] +URL = versions_info['versions'][version]['bin'][0] -with tempfile.NamedTemporaryFile(suffix='youtube-dl', delete=True) as ytdl_file: - with urllib.request.urlopen(URL) as dl: - shutil.copyfileobj(dl, ytdl_file) - - ytdl_file.seek(0) - data = ytdl_file.read() - - ytdl_file.flush() - version = subprocess.check_output(['python3', ytdl_file.name, '--version']).decode('ascii').strip() +data = urllib.request.urlopen(URL).read() # Read template page with open('download.html.in', 'r', encoding='utf-8') as tmplf: @@ -29,5 +24,9 @@ template = template.replace('@PROGRAM_URL@', URL) template = template.replace('@PROGRAM_MD5SUM@', md5sum) template = template.replace('@PROGRAM_SHA1SUM@', sha1sum) template = template.replace('@PROGRAM_SHA256SUM@', sha256sum) +template = template.replace('@EXE_URL@', versions_info['versions'][version]['exe'][0]) +template = template.replace('@EXE_SHA256SUM@', versions_info['versions'][version]['exe'][1]) +template = template.replace('@TAR_URL@', versions_info['versions'][version]['tar'][0]) +template = template.replace('@TAR_SHA256SUM@', versions_info['versions'][version]['tar'][1]) with open('download.html', 'w', encoding='utf-8') as dlf: dlf.write(template) diff --git a/devscripts/gh-pages/sign-versions.py b/devscripts/gh-pages/sign-versions.py new file mode 100755 index 000000000..dd126df52 --- /dev/null +++ b/devscripts/gh-pages/sign-versions.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +import rsa +import json +from binascii import hexlify + +versions_info = json.load(open('update/versions.json')) +if 'signature' in versions_info: + del versions_info['signature'] + +print('Enter the PKCS1 private key, followed by a blank line:') +privkey = '' +while True: + try: + line = input() + except EOFError: + break + if line == '': + break + privkey += line + '\n' +privkey = bytes(privkey, 'ascii') +privkey = rsa.PrivateKey.load_pkcs1(privkey) + +signature = hexlify(rsa.pkcs1.sign(json.dumps(versions_info, sort_keys=True).encode('utf-8'), privkey, 'SHA-256')).decode() +print('signature: ' + signature) + +versions_info['signature'] = signature +json.dump(versions_info, open('update/versions.json', 'w'), indent=4, sort_keys=True) \ No newline at end of file diff --git a/devscripts/gh-pages/sign_versions.py b/devscripts/gh-pages/sign_versions.py deleted file mode 100755 index 5d94a3a03..000000000 --- a/devscripts/gh-pages/sign_versions.py +++ /dev/null @@ -1,30 +0,0 @@ -#! /usr/bin/env python3 - -import rsa -import json -from binascii import hexlify - -# TODO path discovery -versions_info = json.load(open('update/versions.json')) -if 'signature' in versions_info: - del versions_info['signature'] - - -print('Enter the PKCS1 private key, followed by a blank line:') -privkey = '' -while True: - try: - line = input() - except EOFError: - break - if line == '': - break - privkey += line + '\n' -privkey = bytes(privkey, 'ascii') -privkey = rsa.PrivateKey.load_pkcs1(privkey) - -signature = hexlify(rsa.pkcs1.sign(json.dumps(versions_info, sort_keys=True).encode('utf-8'), privkey, 'SHA-256')).decode() -print('signature: ' + signature) - -versions_info['signature'] = signature -json.dump(versions_info, open('update/versions.json', 'w'), indent=4, sort_keys=True) \ No newline at end of file diff --git a/devscripts/make_readme.py b/devscripts/make_readme.py old mode 100644 new mode 100755 diff --git a/devscripts/release.sh b/devscripts/release.sh index 963a6c22b..776f17646 100755 --- a/devscripts/release.sh +++ b/devscripts/release.sh @@ -1,11 +1,74 @@ #!/bin/sh +# IMPORTANT: the following assumptions are made +# * you did --set-upstream +# * the gh-pages branch is named so locally +# * the git config user.signingkey is properly set + +# You will need +# pip install coverage nose rsa + +set -e + if [ -z "$1" ]; then echo "ERROR: specify version number like this: $0 1994.09.06"; exit 1; fi version="$1" if [ ! -z "`git tag | grep "$version"`" ]; then echo 'ERROR: version already present'; exit 1; fi -if [ ! -z "`git status --porcelain`" ]; then echo 'ERROR: the working directory is not clean; commit or stash changes'; exit 1; fi -sed -i "s/__version__ = '.*'/__version__ = '$version'/" youtube_dl/__init__.py -make all -git add -A +if [ ! -z "`git status --porcelain | grep -v CHANGELOG`" ]; then echo 'ERROR: the working directory is not clean; commit or stash changes'; exit 1; fi +if [ ! -f "updates_key.pem" ]; then echo 'ERROR: updates_key.pem missing'; exit 1; fi + +echo "\n### First of all, testing..." +make clean +nosetests --with-coverage --cover-package=youtube_dl --cover-html test || exit 1 + +echo "\n### Changing version in version.py..." +sed -i~ "s/__version__ = '.*'/__version__ = '$version'/" youtube_dl/version.py + +echo "\n### Committing CHANGELOG README.md and youtube_dl/version.py..." +make README.md +git add CHANGELOG README.md youtube_dl/version.py git commit -m "release $version" -git tag -m "Release $version" "$version" \ No newline at end of file + +echo "\n### Now tagging, signing and pushing..." +git tag -s -m "Release $version" "$version" +git show "$version" +read -p "Is it good, can I push? (y/n) " -n 1 +if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi +echo +git push + +echo "\n### OK, now it is time to build the binaries..." +REV=$(git rev-parse HEAD) +make youtube-dl youtube-dl.tar.gz +wget "http://jeromelaheurte.net:8142/download/rg3/youtube-dl/youtube-dl.exe?rev=$REV" -O youtube-dl.exe || \ + wget "http://jeromelaheurte.net:8142/build/rg3/youtube-dl/youtube-dl.exe?rev=$REV" -O youtube-dl.exe +mkdir -p "update_staging/$version" +mv youtube-dl youtube-dl.exe "update_staging/$version" +mv youtube-dl.tar.gz "update_staging/$version/youtube-dl-$version.tar.gz" +git checkout HEAD -- youtube-dl youtube-dl.exe + +echo "\n### Signing and uploading the new binaries to youtube-dl.org..." +for f in update_staging/$version/*; do gpg --detach-sig "$f"; done +scp -r "update_staging/$version" ytdl@youtube-dl.org:html/downloads/ +rm -r update_staging + +echo "\n### Now switching to gh-pages..." +MASTER=$(git rev-parse --abbrev-ref HEAD) +git checkout gh-pages +git checkout "$MASTER" -- devscripts/gh-pages/ +git reset devscripts/gh-pages/ +devscripts/gh-pages/add-version.py $version +devscripts/gh-pages/sign-versions.py < updates_key.pem +devscripts/gh-pages/generate-download.py +devscripts/gh-pages/update-copyright.py +rm -r test_coverage +mv cover test_coverage +git add *.html *.html.in update test_coverage +git commit -m "release $version" +git show HEAD +read -p "Is it good, can I push? (y/n) " -n 1 +if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi +echo +git push + +echo "\n### DONE!" +git checkout $MASTER -- cgit v1.2.3 From 6e3dba168bd9662186f0071caf249e4d0c52beff Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Wed, 2 Jan 2013 23:40:24 +0100 Subject: release.sh edits based on 2013.01.02 experience --- devscripts/release.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'devscripts') diff --git a/devscripts/release.sh b/devscripts/release.sh index 776f17646..0926c4038 100755 --- a/devscripts/release.sh +++ b/devscripts/release.sh @@ -1,13 +1,17 @@ #!/bin/sh # IMPORTANT: the following assumptions are made -# * you did --set-upstream +# * the GH repo is on the origin remote # * the gh-pages branch is named so locally # * the git config user.signingkey is properly set # You will need # pip install coverage nose rsa +# TODO +# release notes +# make hash on local files + set -e if [ -z "$1" ]; then echo "ERROR: specify version number like this: $0 1994.09.06"; exit 1; fi @@ -34,7 +38,9 @@ git show "$version" read -p "Is it good, can I push? (y/n) " -n 1 if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi echo -git push +MASTER=$(git rev-parse --abbrev-ref HEAD) +git push origin $MASTER:master +git push origin "$version" echo "\n### OK, now it is time to build the binaries..." REV=$(git rev-parse HEAD) @@ -52,7 +58,6 @@ scp -r "update_staging/$version" ytdl@youtube-dl.org:html/downloads/ rm -r update_staging echo "\n### Now switching to gh-pages..." -MASTER=$(git rev-parse --abbrev-ref HEAD) git checkout gh-pages git checkout "$MASTER" -- devscripts/gh-pages/ git reset devscripts/gh-pages/ @@ -68,7 +73,8 @@ git show HEAD read -p "Is it good, can I push? (y/n) " -n 1 if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi echo -git push +git push origin gh-pages echo "\n### DONE!" +rm -r devscripts git checkout $MASTER -- cgit v1.2.3 From 876f1a86af8e312432aeb1df31b3bbe1cbea14f2 Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Thu, 3 Jan 2013 19:18:55 +0100 Subject: Also publish hashsums --- devscripts/release.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'devscripts') diff --git a/devscripts/release.sh b/devscripts/release.sh index 0926c4038..4a7a55208 100755 --- a/devscripts/release.sh +++ b/devscripts/release.sh @@ -50,10 +50,14 @@ wget "http://jeromelaheurte.net:8142/download/rg3/youtube-dl/youtube-dl.exe?rev= mkdir -p "update_staging/$version" mv youtube-dl youtube-dl.exe "update_staging/$version" mv youtube-dl.tar.gz "update_staging/$version/youtube-dl-$version.tar.gz" +RELEASE_FILES=youtube-dl youtube-dl.exe youtube-dl-$version.tar.gz +(cd update_staging/$version/ && md5sum $RELEASE_FILES > MD5SUMS) +(cd update_staging/$version/ && sha1sum $RELEASE_FILES > SHA1SUMS) +(cd update_staging/$version/ && sha512sum $RELEASE_FILES > SHA512SUMS) git checkout HEAD -- youtube-dl youtube-dl.exe echo "\n### Signing and uploading the new binaries to youtube-dl.org..." -for f in update_staging/$version/*; do gpg --detach-sig "$f"; done +for f in $RELEASE_FILES; do gpg --detach-sig "update_staging/$version/$f"; done scp -r "update_staging/$version" ytdl@youtube-dl.org:html/downloads/ rm -r update_staging -- cgit v1.2.3 From 431d88dd31cfcf32507e0dd46c8445598fc9eaf8 Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Thu, 3 Jan 2013 19:49:06 +0100 Subject: Also generate SHA2-256 --- devscripts/release.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'devscripts') diff --git a/devscripts/release.sh b/devscripts/release.sh index 4a7a55208..cf5784e8c 100755 --- a/devscripts/release.sh +++ b/devscripts/release.sh @@ -53,7 +53,8 @@ mv youtube-dl.tar.gz "update_staging/$version/youtube-dl-$version.tar.gz" RELEASE_FILES=youtube-dl youtube-dl.exe youtube-dl-$version.tar.gz (cd update_staging/$version/ && md5sum $RELEASE_FILES > MD5SUMS) (cd update_staging/$version/ && sha1sum $RELEASE_FILES > SHA1SUMS) -(cd update_staging/$version/ && sha512sum $RELEASE_FILES > SHA512SUMS) +(cd update_staging/$version/ && sha256sum $RELEASE_FILES > SHA2-256SUMS) +(cd update_staging/$version/ && sha512sum $RELEASE_FILES > SHA2-512SUMS) git checkout HEAD -- youtube-dl youtube-dl.exe echo "\n### Signing and uploading the new binaries to youtube-dl.org..." -- cgit v1.2.3