Exemple #1
0
def test_filename_with_timestamp():
    stamp = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
    # originally no stamp
    filename = 'pr2-test-1.bag'
    expected = '_'.join([stamp, filename])
    assert_equal(expected, filename_with_timestamp(filename))
    # stamped
    filename = '2015-01-01-23-59-59-pr2-test-999.bag'
    assert_equal(filename, filename_with_timestamp(filename))
    # wrong formated stamp
    filename = '2015-01-01_23-59-59-pr2-test-999.bag'
    expected = '_'.join([stamp, filename])
    assert_equal(expected, filename_with_timestamp(filename))
Exemple #2
0
def cmd_put(filename, public, stamped):
    """Upload file to aries."""
    if stamped:
        filename_org = filename
        filename = filename_with_timestamp(filename)
        if filename_org != filename:
            print('Filename is being changed: {0} -> {1}'
                  .format(filename_org, filename))
            yn = raw_input('Are you sure?[Y/n]: ')
            if yn not in 'yY':
                sys.stderr.write('Aborted!')
                sys.exit(1)
            os.rename(filename_org, filename)

    if public:
        print('Uploading to Google Drive...')
        stdout = upload_gdrive(filename)
        for line in stdout.splitlines():
            if line.startswith('Title:'):
                filename = line.split(' ')[-1].strip()
            elif line.startswith('Id:'):
                file_id = line.split(' ')[-1].strip()
        print('Done.')
        print('You can download it by:')
        dl_url = google_drive_file_url(file_id, download=True)
        print('$ wget {url} -O {file}'.format(url=dl_url, file=filename))
    else:
        print('Uploading to aries...')
        cmd = 'rsync -avz --progress -e "ssh -o StrictHostKeyChecking=no"\
            --bwlimit=100000 {file} {usr}@{host}:{dir}/private/'
        cmd = cmd.format(file=filename, usr=LOGIN_USER, host=HOST,
                         dir=DATA_DIR)
        subprocess.call(shlex.split(cmd))
        print('Done.')