aboutsummaryrefslogtreecommitdiff
path: root/devscripts
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2012-12-11 07:52:44 -0800
committerPhilipp Hagemeister <phihag@phihag.de>2012-12-11 07:52:44 -0800
commitd050de77f94a5dc9071c0b459ba62cb09c6696c4 (patch)
tree3bea4b6975544ef76241ccf402de541da350b4ac /devscripts
parent4fb1acc212555e3e817f858dce964876eef75d85 (diff)
parent95eb771dcda47f948b050da85c7ff22539e3ee12 (diff)
Merge pull request #580 from FiloSottile/master
The new shiny build system
Diffstat (limited to 'devscripts')
-rw-r--r--devscripts/bash-completion.py26
-rw-r--r--devscripts/bash-completion.template14
-rw-r--r--devscripts/make_readme.py20
-rw-r--r--devscripts/transition_helper.py40
-rw-r--r--devscripts/transition_helper_exe/setup.py12
-rw-r--r--devscripts/transition_helper_exe/youtube-dl.py49
6 files changed, 161 insertions, 0 deletions
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/make_readme.py b/devscripts/make_readme.py
new file mode 100644
index 000000000..7f2ea319c
--- /dev/null
+++ b/devscripts/make_readme.py
@@ -0,0 +1,20 @@
+import sys
+import re
+
+README_FILE = 'README.md'
+helptext = sys.stdin.read()
+
+with open(README_FILE) as f:
+ oldreadme = f.read()
+
+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'
+
+with open(README_FILE, 'w') as f:
+ f.write(header)
+ f.write(options)
+ f.write(footer)
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')