Пример #1
0
 def test_parseargs(self):
     self.assertEqual(parseargs(('d', '--a', 'pq', 'e', '--b', '3', '--c',
                                 '4.5', 'f'),
                                (('a', 'x', ''), ('b', 1, ''),
                                 ('c', 2.3, ''))),
                      ({'a': 'pq', 'b': 3, 'c': 4.5}, ['d', 'e', 'f']))
     self.assertEqual(parseargs([], [('a', 'x', '')]), ({'a': 'x'}, []))
     self.assertEqual(parseargs(['--a', 'x', '--a', 'y'], [('a', '', '')]),
                      ({'a': 'y'}, []))
     self.assertEqual(parseargs(['x'], [], 1, 2), ({}, ['x']))
     self.assertEqual(parseargs(['x', 'y'], [], 1, 2), ({}, ['x', 'y']))
     self.assertRaises(ValueError, parseargs, ['--a', 'x'], [])
     self.assertRaises(ValueError, parseargs, ['--a'], [('a', 'x', '')])
     self.assertRaises(ValueError, parseargs, [], [], 1, 2)
     self.assertRaises(ValueError, parseargs, ['x', 'y', 'z'], [], 1, 2)
     self.assertRaises(ValueError, parseargs, ['--a', '2.0'],
                       [('a', 3, '')])
     self.assertRaises(ValueError, parseargs, ['--a', 'z'],
                       [('a', 2.1, '')])
Пример #2
0
 def test_parseargs(self):
     self.assertEqual(
         parseargs(('d', '--a', 'pq', 'e', '--b', '3', '--c', '4.5', 'f'),
                   (('a', 'x', ''), ('b', 1, ''), ('c', 2.3, ''))),
         ({
             'a': 'pq',
             'b': 3,
             'c': 4.5
         }, ['d', 'e', 'f']))
     self.assertEqual(parseargs([], [('a', 'x', '')]), ({'a': 'x'}, []))
     self.assertEqual(parseargs(['--a', 'x', '--a', 'y'], [('a', '', '')]),
                      ({
                          'a': 'y'
                      }, []))
     self.assertEqual(parseargs(['x'], [], 1, 2), ({}, ['x']))
     self.assertEqual(parseargs(['x', 'y'], [], 1, 2), ({}, ['x', 'y']))
     self.assertRaises(ValueError, parseargs, ['--a', 'x'], [])
     self.assertRaises(ValueError, parseargs, ['--a'], [('a', 'x', '')])
     self.assertRaises(ValueError, parseargs, [], [], 1, 2)
     self.assertRaises(ValueError, parseargs, ['x', 'y', 'z'], [], 1, 2)
     self.assertRaises(ValueError, parseargs, ['--a', '2.0'],
                       [('a', 3, '')])
     self.assertRaises(ValueError, parseargs, ['--a', 'z'],
                       [('a', 2.1, '')])
Пример #3
0
def main(argv):
    program, _ = os.path.splitext(os.path.basename(argv[0]))
    usage = "Usage: %s <trackerurl> <file> [file...] [params...]" % program

    if len(argv) < 3:
        print "{}\n\n{}{}".format(usage, formatDefinitions(defaults, 80),
                                  announcelist_details)
        return 2

    try:
        config, args = parseargs(argv[1:], defaults, 2, None)
        for file in args[1:]:
            make_meta_file(file, args[0], config.copy(), progress=prog)
    except ValueError as e:
        print 'error: ' + str(e)
        print 'run with no args for parameter explanations'

    return 0
Пример #4
0
def main(argv):
    program, _ = os.path.splitext(os.path.basename(argv[0]))
    usage = "Usage: %s <trackerurl> <file> [file...] [params...]" % program

    if len(argv) < 3:
        print "{}\n\n{}{}".format(usage, formatDefinitions(defaults, 80),
                                  announcelist_details)
        return 2

    try:
        config, args = parseargs(argv[1:], defaults, 2, None)
        for file in args[1:]:
            make_meta_file(file, args[0], config.copy(), progress=prog)
    except ValueError as e:
        print 'error: ' + str(e)
        print 'run with no args for parameter explanations'

    return 0
Пример #5
0
def parse_params(params, presets={}):
    if len(params) == 0:
        return None
    config, args = parseargs(params, defaults, 0, 1, presets=presets)
    if args:
        if config["metafile"] or config["url"]:
            raise ValueError("must have metafile or url as arg or " "parameter, not both")
        if os.path.isfile(args[0]):
            config["metafile"] = args[0]
        else:
            try:
                urlparse(args[0])
            except ValueError:
                raise ValueError("bad filename or url")
            config["url"] = args[0]
    elif (config["metafile"] == "") == (config["url"] == ""):
        raise ValueError("need metafile or url, must have one, cannot have " "both")
    return config
Пример #6
0
def track(args):
    if len(args) == 0:
        print formatDefinitions(defaults, 80)
        return
    try:
        config, _ = parseargs(args, defaults, 0, 0)
    except ValueError as e:
        print 'error: ' + str(e)
        print 'run with no arguments for parameter explanations'
        return
    r = RawServer(threading.Event(), config['timeout_check_interval'],
                  config['socket_timeout'], ipv6_enable=config['ipv6_enabled'])
    t = Tracker(config, r)
    r.bind(config['port'], config['bind'],
           reuse=True, ipv6_socket_style=config['ipv6_binds_v4'])
    r.listen_forever(
        HTTPHandler(t.get, config['min_time_between_log_flushes']))
    t.save_state()
    print '# Shutting down: ' + isotime()
Пример #7
0
def parse_params(params, presets={}):
    if len(params) == 0:
        return None
    config, args = parseargs(params, defaults, 0, 1, presets=presets)
    if args:
        if config['metafile'] or config['url']:
            raise ValueError('must have metafile or url as arg or '
                             'parameter, not both')
        if os.path.isfile(args[0]):
            config['metafile'] = args[0]
        else:
            try:
                urlparse(args[0])
            except ValueError:
                raise ValueError('bad filename or url')
            config['url'] = args[0]
    elif (config['metafile'] == '') == (config['url'] == ''):
        raise ValueError('need metafile or url, must have one, cannot have '
                         'both')
    return config
Пример #8
0
def parse_params(params, presets={}):
    if len(params) == 0:
        return None
    config, args = parseargs(params, defaults, 0, 1, presets=presets)
    if args:
        if config['metafile'] or config['url']:
            raise ValueError('must have metafile or url as arg or '
                             'parameter, not both')
        if os.path.isfile(args[0]):
            config['metafile'] = args[0]
        else:
            try:
                urlparse(args[0])
            except ValueError:
                raise ValueError('bad filename or url')
            config['url'] = args[0]
    elif (config['metafile'] == '') == (config['url'] == ''):
        raise ValueError('need metafile or url, must have one, cannot have '
                         'both')
    return config
Пример #9
0
def main(cmd, *argv):
    "Make a .torrent file for every file or directory in each given directory."
    program, _ = os.path.splitext(os.path.basename(cmd))
    usage = "Usage: %s <trackerurl> <dir> [dir...] [params...]" % program
    desc = __doc__

    if len(argv) < 2:
        print("{}\n{}\n{}{}".format(usage, desc,
                                    formatDefinitions(defaults, 80),
                                    announcelist_details))
        return 2

    try:
        config, args = parseargs(argv, defaults, 2, None)
        for directory in args[1:]:
            completedir(directory, args[0], config)
    except ValueError as error:
        print('error: ', error)
        print('run with no args for parameter explanations')
        return 1

    return 0
Пример #10
0
def main(cmd, *argv):
    "Make a .torrent file for every file or directory in each given directory."
    program, _ = os.path.splitext(os.path.basename(cmd))
    usage = "Usage: %s <trackerurl> <dir> [dir...] [params...]" % program
    desc = __doc__

    if len(argv) < 2:
        print("{}\n{}\n{}{}".format(usage, desc,
                                    formatDefinitions(defaults, 80),
                                    announcelist_details))
        return 2

    try:
        config, args = parseargs(argv, defaults, 2, None)
        for directory in args[1:]:
            completedir(directory, args[0], config)
    except ValueError as error:
        print('error: ', error)
        print('run with no args for parameter explanations')
        return 1

    return 0
Пример #11
0
    ])
    try:
        configdir = ConfigDir('launchmanycurses')
        defaultsToIgnore = ['responsefile', 'url', 'priority']
        configdir.setDefaults(defaults, defaultsToIgnore)
        configdefaults = configdir.loadConfig()
        defaults.append(('save_options', 0, 'whether to save the current '
                         'options as the new default configuration (only for '
                         'btlaunchmanycurses.py)'))
        if len(sys.argv) < 2:
            print("Usage: btlaunchmanycurses.py <directory> <global options>\n"
                  "<directory> - directory to look for .torrent files "
                  "(semi-recursive)")
            print(get_usage(defaults, 80, configdefaults))
            sys.exit(1)
        config, args = parseargs(sys.argv[1:], defaults, 1, 1, configdefaults)
        if config['save_options']:
            configdir.saveConfig(config)
        configdir.deleteOldCacheData(config['expire_cache_data'])
        if not os.path.isdir(args[0]):
            raise ValueError("Warning: " + args[0] + " is not a directory")
        config['torrent_dir'] = args[0]
    except ValueError as e:
        print('error: {}\nrun with no args for parameter explanations'
              ''.format(e))
        sys.exit(1)

    curses.wrapper(LaunchManyWrapper, config)
    if Exceptions:
        print('\nEXCEPTION:')
        print(Exceptions[0])
Пример #12
0
    ])
    try:
        configdir = ConfigDir('launchmany')
        defaultsToIgnore = ['responsefile', 'url', 'priority']
        configdir.setDefaults(defaults, defaultsToIgnore)
        configdefaults = configdir.loadConfig()
        defaults.append(
            ('save_options', 0, 'whether to save the current options as the '
             'new default configuration (only for btlaunchmany.py)'))
        if len(sys.argv) < 2:
            print "Usage: btlaunchmany.py <directory> <global options>\n"
            print "<directory> - directory to look for .torrent files " \
                "(semi-recursive)"
            print get_usage(defaults, 80, configdefaults)
            sys.exit(1)
        config, args = parseargs(sys.argv[1:], defaults, 1, 1, configdefaults)
        if config['save_options']:
            configdir.saveConfig(config)
        configdir.deleteOldCacheData(config['expire_cache_data'])
        if not os.path.isdir(args[0]):
            raise ValueError("Warning: " + args[0] + " is not a directory")
        config['torrent_dir'] = args[0]
    except ValueError as e:
        print 'error: {}\nrun with no args for parameter explanations' \
            ''.format(e)
        sys.exit(1)

    LaunchMany(config, HeadlessDisplayer())
    if Exceptions:
        print '\nEXCEPTION:'
        print Exceptions[0]