Exemplo n.º 1
0
def localpath_to_s3path(localdir, localpath, s3prefix):
    """
    Convert a local filepath into a S3 path within the given ``s3prefix``.

    :param localdir: The local directory that corresponds to ``s3prefix``.
    :param localpath: Path to a file within ``localdir``.
    :param s3prefix: Prefix to use for the file on S3.

    Example::
    >>> localpath_to_s3path('/mydir', '/mydir/hello/world.txt', 'my/test')
    'my/test/hello/world.txt'
    """
    localdir = force_slashend(localpath_to_slashpath(abspath(localdir)))
    localpath = localpath_to_slashpath(abspath(localpath))
    s3prefix = force_slashend(s3prefix)
    relpath = localpath[len(localdir):]
    return s3prefix + relpath
Exemplo n.º 2
0
 def __init__(self, bucket, local_dir, s3prefix):
     """
     :param bucket: A :class:`boto.rds.bucket.DBInstance` object.
     :param local_dir: The local directory.
     :param local_dir: The S3 key prefix that corresponds to ``local_dir``.
     """
     self.bucket = bucket
     self.local_dir = local_dir
     self.s3prefix = force_slashend(s3prefix)
Exemplo n.º 3
0
def s3path_to_localpath(s3prefix, s3path, localdir):
    """
    Convert a s3 filepath into a local filepath within the given ``localdir``.

    :param s3prefix: Prefix used for the file on S3.
    :param s3path: Path to a file within ``s3prefix``.
    :param localdir: The local directory that corresponds to ``s3prefix``.

    Example::
    >>> s3path_to_localpath('mydir/', 'mydir/hello/world.txt', '/my/test')
    '/my/test/hello/world.txt'
    """
    s3prefix = force_slashend(s3prefix)
    localpath = slashpath_to_localpath(s3path[len(s3prefix):])
    return join(localdir, localpath)
Exemplo n.º 4
0
 def test_force_slashend(self):
     self.assertEquals(force_slashend('/path/to/'), '/path/to/')
     self.assertEquals(force_slashend('/path/to'), '/path/to/')
Exemplo n.º 5
0
 def test_force_slashend(self):
     self.assertEquals(force_slashend('/path/to/'), '/path/to/')
     self.assertEquals(force_slashend('/path/to'), '/path/to/')