Exemple #1
0
def parse_configuration_and_args(defaults, uiname, arglist=[], minargs=0,
                                 maxargs=0):
    defconfig = dict([(name, value) for (name, value, doc) in defaults])
    if arglist[0:] == ['--version']:
        print version
        sys.exit(0)

    if arglist[0:] in (['--help'], ['-h'], ['--usage'], ['-?']):
        parseargs.printHelp(uiname, defaults)
        sys.exit(0)

    presets = get_config(defconfig, uiname)
    config, args = parseargs.parseargs(arglist, defaults, minargs, maxargs,
                                       presets)
    datadir = config['data_dir']
    if datadir:
        if uiname in ('anondownloadgui', 'anonmaketorrentgui'):
            p = SafeConfigParser()
            values = {}
            p.read(os.path.join(datadir, 'ui_config'))
            if p.has_section(uiname):
                for name, value in p.items(uiname):
                    if name in defconfig:
                        values[name] = value
            parseargs.parse_options(defconfig, values)
            presets.update(values)
            config, args = parseargs.parseargs(arglist, defaults, minargs,
                                               maxargs, presets)
        rdir = os.path.join(datadir, 'resume')
        mdir = os.path.join(datadir, 'metainfo')
        cdir = os.path.join(datadir, 'crypto')
        try:
            if not os.path.exists(datadir):
                os.mkdir(datadir, 0700)
            if not os.path.exists(mdir):
                os.mkdir(mdir, 0700)
            if not os.path.exists(rdir):
                os.mkdir(rdir, 0700)
            if not os.path.exists(cdir):
                os.mkdir(cdir, 0700)
        except:
            pass
    return config, args
Exemple #2
0
    ('comment', '',
        "optional human-readable comment to put in .torrent"),
    ('target', '',
        "optional target file for the torrent"),
    ('filesystem_encoding', '',
     "character encoding used on the local filesystem. If left empty, autodetected. Autodetection doesn't work under python versions older than 2.3.")
    ]


def dc(v):
    print v

def prog(amount):
    print '%.1f%% complete\r' % (amount * 100),

if __name__ == '__main__':
    if len(sys.argv) <= 1:
        printHelp('btmaketorrent', defaults)
    else:
        try:
            config, args = parseargs(sys.argv[1:], defaults, 2, None)
            print config
            print args
            if len(sys.argv) == 3:
                make_meta_files(args[0], args[1:], piece_len_pow2=config['piece_size_pow2'], progressfunc=prog, filefunc=dc, comment=config['comment'], target=config['target'], filesystem_encoding=config['filesystem_encoding'])
            else:
                make_meta_files(args[0], args[2:], piece_len_pow2=config['piece_size_pow2'], progressfunc=prog, filefunc=dc, comment=config['comment'], target=config['target'], filesystem_encoding=config['filesystem_encoding'])
        except BTFailure, e:
            print str(e)
            sys.exit(1)
Exemple #3
0

def dc(v):
    print v


def prog(amount):
    print '%.1f%% complete\r' % (amount * 100),


if __name__ == '__main__':
    if len(sys.argv) <= 1:
        printHelp('btmaketorrent', defaults)
    else:
        try:
            config, args = parseargs(sys.argv[1:], defaults, 2, None)
            print config
            print args
            if len(sys.argv) == 3:
                make_meta_files(
                    args[0],
                    args[1:],
                    piece_len_pow2=config['piece_size_pow2'],
                    progressfunc=prog,
                    filefunc=dc,
                    comment=config['comment'],
                    target=config['target'],
                    filesystem_encoding=config['filesystem_encoding'])
            else:
                make_meta_files(
                    args[0],