redefine version (0.4.x)

This commit is contained in:
Mort Yao 2015-10-21 17:01:31 +02:00
parent b53a2e6676
commit d60eafeacb
4 changed files with 33 additions and 8 deletions

View File

@ -20,6 +20,7 @@ _help = """Usage: {} [OPTION]... [URL]...
TODO TODO
""".format(script_name) """.format(script_name)
# TBD
def main_dev(**kwargs): def main_dev(**kwargs):
"""Main entry point. """Main entry point.
you-get-dev you-get-dev
@ -88,7 +89,7 @@ def main(**kwargs):
you-get (legacy) you-get (legacy)
""" """
from .common import main from .common import main
main() main(**kwargs)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -91,6 +91,7 @@ from importlib import import_module
from .version import __version__ from .version import __version__
from .util import log, term from .util import log, term
from .util.git import get_version
from .util.strings import get_filename, unescape_html from .util.strings import get_filename, unescape_html
from . import json_output as json_output_ from . import json_output as json_output_
@ -981,8 +982,11 @@ def download_main(download, download_playlist, urls, playlist, **kwargs):
else: else:
download(url, **kwargs) download(url, **kwargs)
def script_main(script_name, download, download_playlist = None): def script_main(script_name, download, download_playlist, **kwargs):
version = 'You-Get %s, a video downloader.' % __version__ def version():
log.i('version %s' % get_version(kwargs['repo_path']
if 'repo_path' in kwargs else __version__))
help = 'Usage: %s [OPTION]... [URL]...\n' % script_name help = 'Usage: %s [OPTION]... [URL]...\n' % script_name
help += '''\nStartup options: help += '''\nStartup options:
-V | --version Display the version and exit. -V | --version Display the version and exit.
@ -1035,10 +1039,10 @@ def script_main(script_name, download, download_playlist = None):
traceback = False traceback = False
for o, a in opts: for o, a in opts:
if o in ('-V', '--version'): if o in ('-V', '--version'):
print(version) version()
sys.exit() sys.exit()
elif o in ('-h', '--help'): elif o in ('-h', '--help'):
print(version) version()
print(help) print(help)
sys.exit() sys.exit()
elif o in ('-f', '--force'): elif o in ('-f', '--force'):
@ -1176,5 +1180,5 @@ def any_download_playlist(url, **kwargs):
m, url = url_to_module(url) m, url = url_to_module(url)
m.download_playlist(url, **kwargs) m.download_playlist(url, **kwargs)
def main(): def main(**kwargs):
script_main('you-get', any_download, any_download_playlist) script_main('you-get', any_download, any_download_playlist, **kwargs)

View File

@ -1,6 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
import os import os
import subprocess
from ..version import __version__
def get_head(repo_path): def get_head(repo_path):
"""Get (branch, commit) from HEAD of a git repo.""" """Get (branch, commit) from HEAD of a git repo."""
@ -11,3 +13,21 @@ def get_head(repo_path):
return branch, commit return branch, commit
except: except:
return None return None
def get_version(repo_path):
try:
version = __version__.split('.')
major, minor = version[0], version[1]
p = subprocess.Popen(['git', 'rev-list', 'HEAD', '--count'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw, err = p.communicate()
c_head = int(raw.decode('ascii'))
q = subprocess.Popen(['git', 'rev-list', 'master', '--count'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw, err = q.communicate()
c_master = int(raw.decode('ascii'))
cc = c_head - c_master
return '%s.%s.%s' % (major, minor, cc)
except:
return __version__

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
script_name = 'you-get' script_name = 'you-get'
__version__ = '0.3.36' __version__ = '0.4.0'