Example #1
0
    def testStaticSet(self):
        brs = [self._createBlob() for i in range(5)]
        static_set = StaticSet(self.server)
        br = static_set.save(brs)

        d = self.server.describe_blob(br)
        self.assertEqual(d['camliType'], 'static-set')

        static_set2 = StaticSet(self.server, br)
        self.assertEqual(sorted(static_set2.data['members']), sorted(brs))
Example #2
0
    def testStaticSet(self):
        brs = [self._createBlob() for i in range(5)]
        static_set = StaticSet(self.server)
        br = static_set.save(brs)

        d = self.server.describe_blob(br)
        self.assertEqual(d['camliType'], 'static-set')

        static_set2 = StaticSet(self.server, br)
        self.assertEqual(sorted(static_set2.data['members']),
                         sorted(brs))
Example #3
0
def _put_directory(con, path, permanode=False):
    """ Put a directory, this function is called recursively over sub-directories. """
    # Initialization of the current directory schema.
    directory = Directory(con, path)
    # Since a Directory must point to a static set, we initialize one too.
    static_set = StaticSet(con)
    static_set_members = []
    # Don't walk recursively with walk, since we already
    # calling _put_dir recursively.
    root, dirs, files = Dir(path).walk().next()
    for f in files:
        static_set_members.append(con.put_file(os.path.join(root, f)))
    for d in dirs:
        static_set_members.append(_put_directory(con, os.path.join(root, d), permanode=False))

    static_set_br = static_set.save(static_set_members)

    # We return the directory blobRef
    return directory.save(static_set_br, permanode=permanode)
Example #4
0
def _put_directory(con, path, permanode=False):
    """ Put a directory, this function is called recursively over sub-directories. """
    # Initialization of the current directory schema.
    directory = Directory(con, path)
    # Since a Directory must point to a static set, we initialize one too.
    static_set = StaticSet(con)
    static_set_members = []
    # Don't walk recursively with walk, since we already
    # calling _put_dir recursively.
    root, dirs, files = Dir(path).walk().next()
    for f in files:
        static_set_members.append(con.put_file(os.path.join(root, f)))
    for d in dirs:
        static_set_members.append(
            _put_directory(con, os.path.join(root, d), permanode=False))

    static_set_br = static_set.save(static_set_members)

    # We return the directory blobRef
    return directory.save(static_set_br, permanode=permanode)
Example #5
0
def _get_directory(con, br, base_path):
    # Load the directory schema
    directory = Directory(con, blob_ref=br)
    # Build the absolute path of the current directory/sub-directory.
    path = os.path.join(base_path, directory.fileName)
    if not os.path.isdir(path):
        os.mkdir(path)
    apply_stat_info(path, directory.data)

    # Load the directory static set.
    static_set = StaticSet(con, directory.entries)
    for member_br in static_set.members:
        blob_metadata = con.describe_blob(member_br)
        if blob_metadata['camliType'] == 'file':
            file_path = os.path.join(path, blob_metadata['file']['fileName'])
            with open(file_path, 'wb') as fh:
                con.get_file(member_br, fh)
        elif blob_metadata['camliType'] == 'directory':
            _get_directory(con, member_br, base_path=path)
Example #6
0
 def static_set(self, blob_ref=None):
     """ Shortcut to initialize a static-set. """
     return StaticSet(self, blob_ref)