|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import getopt |
| 4 | +import os |
| 5 | +import platform |
| 6 | +import sys |
| 7 | +from .version import script_name, __version__ |
| 8 | +from .util import git, log |
| 9 | + |
| 10 | +_options = [ |
| 11 | + 'help', |
| 12 | + 'version', |
| 13 | + 'gui', |
| 14 | + 'force', |
| 15 | + 'playlists', |
| 16 | +] |
| 17 | +_short_options = 'hVgfl' |
| 18 | + |
| 19 | +_help = """Usage: {} [OPTION]... [URL]... |
| 20 | +TODO |
| 21 | +""".format(script_name) |
| 22 | + |
| 23 | +def main_dev(**kwargs): |
| 24 | + """Main entry point. |
| 25 | + you-get-dev |
| 26 | + """ |
| 27 | + |
| 28 | + # Get (branch, commit) if running from a git repo. |
| 29 | + head = git.get_head(kwargs['repo_path']) |
| 30 | + |
| 31 | + # Get options and arguments. |
| 32 | + try: |
| 33 | + opts, args = getopt.getopt(sys.argv[1:], _short_options, _options) |
| 34 | + except getopt.GetoptError as e: |
| 35 | + log.wtf(""" |
| 36 | + [Fatal] {}. |
| 37 | + Try '{} --help' for more options.""".format(e, script_name)) |
| 38 | + |
| 39 | + if not opts and not args: |
| 40 | + # Display help. |
| 41 | + print(_help) |
| 42 | + # Enter GUI mode. |
| 43 | + #from .gui import gui_main |
| 44 | + #gui_main() |
| 45 | + else: |
| 46 | + conf = {} |
| 47 | + for opt, arg in opts: |
| 48 | + if opt in ('-h', '--help'): |
| 49 | + # Display help. |
| 50 | + print(_help) |
| 51 | + |
| 52 | + elif opt in ('-V', '--version'): |
| 53 | + # Display version. |
| 54 | + log.println("you-get:", log.BOLD) |
| 55 | + log.println(" version: {}".format(__version__)) |
| 56 | + if head is not None: |
| 57 | + log.println(" branch: {}\n commit: {}".format(*head)) |
| 58 | + else: |
| 59 | + log.println(" branch: {}\n commit: {}".format("(stable)", "(tag v{})".format(__version__))) |
| 60 | + |
| 61 | + log.println(" platform: {}".format(platform.platform())) |
| 62 | + log.println(" python: {}".format(sys.version.split('\n')[0])) |
| 63 | + |
| 64 | + elif opt in ('-g', '--gui'): |
| 65 | + # Run using GUI. |
| 66 | + conf['gui'] = True |
| 67 | + |
| 68 | + elif opt in ('-f', '--force'): |
| 69 | + # Force download. |
| 70 | + conf['force'] = True |
| 71 | + |
| 72 | + elif opt in ('-l', '--playlist', '--playlists'): |
| 73 | + # Download playlist whenever possible. |
| 74 | + conf['playlist'] = True |
| 75 | + |
| 76 | + if args: |
| 77 | + if 'gui' in conf and conf['gui']: |
| 78 | + # Enter GUI mode. |
| 79 | + from .gui import gui_main |
| 80 | + gui_main(*args, **conf) |
| 81 | + else: |
| 82 | + # Enter console mode. |
| 83 | + from .console import console_main |
| 84 | + console_main(*args, **conf) |
| 85 | + |
| 86 | +def main(**kwargs): |
| 87 | + """Main entry point. |
| 88 | + you-get (legacy) |
| 89 | + """ |
| 90 | + from .common import main |
| 91 | + main() |
0 commit comments