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