Exemplo n.º 1
0
def main():
    parser = cli.get_uploader_parser()
    args = parser.parse_args()

    # check config availability and load configuration
    try:
        config_fobject = open(config.default_filename)
    except (IOError, OSError), e:
        util.report_error("Cannot load configuration (%s) -- run configleecher first" % (e))
        sys.exit(7)
Exemplo n.º 2
0
def download(client, remove_finished=False):
    for torrent, status, filename in client.get_files_to_download():
        # Set loop vars up
        download_lockfile = ".%s.done" % filename
        fully_downloaded = os.path.exists(download_lockfile)
        seeding = status == "Seeding"

        # If the file is completely downloaded but not to be remotely removed, skip
        if fully_downloaded and not remove_finished:
            util.report_message("%s from %s is fully downloaded, continuing to next torrent" % (filename, torrent))
            continue

        # If the remote files don't exist, skip
        util.report_message("Checking if %s from torrent %s exists on server" % (filename, torrent))
        if not client.exists_on_server(filename):
            util.report_message("%s from %s is no longer available on server, continuing to next torrent" % (filename, torrent))
            continue

        if not fully_downloaded:

            # Start download.
            util.report_message("Downloading %s from torrent %s" % (filename, torrent))
            util.mark_dir_downloading_when_it_appears(filename)
            retvalue = client.transfer(filename)
            if retvalue != 0:
                # rsync failed
                util.mark_dir_error(filename)
                if retvalue == 20:
                    util.report_error("Download of %s stopped -- rsync process interrupted" % (filename,))
                    util.report_message("Finishing by user request")
                    return 2
                elif retvalue < 0:
                    util.report_error("Download of %s failed -- rsync process killed with signal %s" % (filename, -retvalue))
                    util.report_message("Aborting")
                    return 1
                else:
                    util.report_error("Download of %s failed -- rsync process exited with return status %s" % (filename, retvalue))
                    util.report_message("Aborting")
                    return 1
            # Rsync successful
            # mark file as downloaded
            try: file(download_lockfile, "w").write("Done")
            except OSError, e:
                if e.errno != 17: raise
            # report successful download
            fully_downloaded = True
            util.mark_dir_complete(filename)
            util.report_message("Download of %s complete" % filename)

        else:

            if remove_finished:
                if seeding:
                    util.report_message("%s from %s is complete but still seeding, not removing" % (filename, torrent))
                else:
                    client.remove_remote_download(filename)
                    util.report_message("Removal of %s complete" % filename)
Exemplo n.º 3
0
    is_torrent = lambda _: not is_magnet(_)

    # give all the torrents/magnets to the client
    failed = False
    for uploadable in args.torrents:
        try:
            if type(uploadable) is str:
                uploadable = uploadable.decode(sys.getfilesystemencoding())
            if is_magnet(uploadable):
                client.upload_magnet_link(uploadable)
                util.report_message("%s submitted to seedbox" % uploadable)
            elif is_torrent(uploadable):
                client.upload_torrent(uploadable)
                util.report_message("%s submitted to seedbox" % os.path.basename(uploadable))
            else:
                raise ValueError("%s is not a torrent or a magnet link" % uploadable)
        except Exception as e:
            if args.debug:
                raise
            extramessage = ""
            if isinstance(e, ConnectionError):
                if e.args[0].errno == -2:
                    extramessage = "\nCheck the hostname in your seedboxtools configuration."
            util.report_error("error while uploading %s: %s%s" % (uploadable, e, extramessage))
            failed = True

    if failed:
        return 4
    else:
        return 0
Exemplo n.º 4
0
    # command line parameter checks
    if args: parser.error("This command accepts no arguments")

    if opts.run_every is not False:
        try:
            opts.run_every = int(opts.run_every)
            if opts.run_every < 1:
                raise ValueError
        except ValueError, e:
            parser.error("option --run-every must be a positive integer")

    # check config availability and load configuration
    try:
        config_fobject = open(config.default_filename)
    except (IOError, OSError), e:
        util.report_error("Cannot load configuration (%s) -- run configleecher first" % (e))
        sys.exit(7)
    cfg = config.load_config(config_fobject)
    local_download_dir = cfg.general.local_download_dir
    client = config.get_client(cfg)

    # check download dir and log file availability
    try:
        os.chdir(local_download_dir)
    except (IOError, OSError), e:
        util.report_error("Cannot change to download directory %r: %s" % (local_download_dir, e))
        sys.exit(4)

    if opts.logfile:
        try:
            file(opts.logfile, "a", 0)