Esempio n. 1
0
def upload(args, parser):
    """Upload a file tree to a remote server.

    """
    parser.add_option('-C', '--compare', action='store_true', default=False,
                      dest='compare',
                      help="Compare remote files that need to be changed "
                           "to local files (implies -D.)")
    options, args = parser.parse_args(args)

    if options.compare:
        options.dry_run = True

    index = create_file_index(options)
    if not index:
        return 0

    session = FTPSession(
        options=options,
        host=parser.config.get('destination', 'host'),
        username=parser.config.get('destination', 'username'),
        password=parser.config.get('destination', 'password'),
        index=index)

    session.connect()

    if not options._continue:
        print "Downloading file index from server..."
        index.download(session)
    print "Reading file index..."
    index.load()

    def process(filename):
        session.upload_if_newer(filename)

    print "Traversing current directory..."
    traverse_dir('.', process, options)

    print "Uploading file index to server..."
    index.upload(session)
    print "Successfully uploaded file index, backing it up..."
    do_it("mv %s %s.bak" % (index.filename, index.filename))
    print "All done, logging off."

    session.disconnect()
    return 0
Esempio n. 2
0
def index(args, parser):
    """Create a new file index file.

    """
    options, args = parser.parse_args(args)

    if not options.dry_run:
        index = create_file_index(options)
        if not index:
            return 0

    def add_file_to_index(filename):
        if options.dry_run:
            print "WOULD ADD %s TO INDEX" % filename
        else:
            index.update(filename, lazy=True)

    print "Traversing current directory..."
    traverse_dir('.', add_file_to_index, options=options)
    if not options.dry_run:
        index.save()
        print "Successfully created file index %s" % index.filename
    return 0