def test_get_storage_user(self):
     """Test the get_storage_user function."""
     user = make_storage_user(
         "Cool UserName", MAX_STORAGE_BYTES, visible_name='Visible Name')
     user = get_storage_user(user.id)
     self.assertTrue(isinstance(user, DAOStorageUser))
     # now check a locked user.
     StorageUser.objects.filter(id=user.id).update(locked=True)
     self.assertRaises(errors.LockedUserError, get_storage_user, user.id)
     # and ignore the lock too
     user = get_storage_user(user.id, readonly=True)
     self.assertTrue(isinstance(user, DAOStorageUser))
 def test_get_storage_user(self):
     """Test the get_storage_user function."""
     user = make_storage_user(
         "Cool UserName", MAX_STORAGE_BYTES, visible_name='Visible Name')
     user = get_storage_user(user.id)
     self.assertTrue(isinstance(user, DAOStorageUser))
     # now check a locked user.
     StorageUser.objects.filter(id=user.id).update(locked=True)
     self.assertRaises(errors.LockedUserError, get_storage_user, user.id)
     # and ignore the lock too
     user = get_storage_user(user.id, readonly=True)
     self.assertTrue(isinstance(user, DAOStorageUser))
 def create_share(self, user_id, node_id,
                  to_username, share_name, readonly):
     """Create a share."""
     user = self._get_user(user_id)
     to_user = services.get_storage_user(username=to_username)
     share = user.volume().dir(node_id).share(to_user.id,
                                              share_name, readonly)
     return dict(share_id=share.id)
Example #4
0
 def create_share(self, user_id, node_id, to_username, share_name,
                  readonly):
     """Create a share."""
     user = self._get_user(user_id)
     to_user = services.get_storage_user(username=to_username)
     share = user.volume().dir(node_id).share(to_user.id, share_name,
                                              readonly)
     return dict(share_id=share.id)
    def _create_share(self, _, accept=False, dead=False, from_id=None):
        """Create the share to me."""
        if from_id is None:
            from_id = self.usr1.id
        fromusr = get_storage_user(from_id)
        node = fromusr.root.load()
        share = node.share(self.usr0.id, u"name", readonly=True)
        self._state.subtree_id = node.id

        if accept:
            self.usr0.get_share(share.id).accept()
            self._state.share_id = share.id

        if dead:
            share.delete()
        return share
Example #6
0
    def _create_share(self, _, accept=False, dead=False, from_id=None):
        """Create the share to me."""
        if from_id is None:
            from_id = self.usr1.id
        fromusr = get_storage_user(from_id)
        node = fromusr.root.load()
        share = node.share(self.usr0.id, u"name", readonly=True)
        self._state.subtree_id = node.id

        if accept:
            self.usr0.get_share(share.id).accept()
            self._state.share_id = share.id

        if dead:
            share.delete()
        return share
 def _get_user(self, user_id, session_id=None):
     """Return a storage user for the given id."""
     return services.get_storage_user(user_id, session_id=session_id)
Example #8
0
 def _get_user(self, user_id, session_id=None):
     """Return a storage user for the given id."""
     return services.get_storage_user(user_id, session_id=session_id)
Example #9
0
def main(username, sharer, wlist, num):
    """Create UDFs, folders and files for the given user using a wordlist."""
    user = get_storage_user(None, username=utf2unicode(username))
    sharer = get_storage_user(None, username=utf2unicode(sharer))
    folders = [user.root]
    with open(wlist) as f:
        names = [utf2unicode(i.strip()) for i in f.readlines() if i.strip()]
    sample = random.sample(names, num)

    if sys.stdout.isatty():
        import curses
        curses.setupterm()
        cols = curses.tigetnum('cols') - 1
        progbar = makeStatBar(cols, cols - 2)
        home = curses.tigetstr('cr')

        def progress(ll):
            """progress bar writer."""
            sys.stdout.write(
                home + progbar((cols - 2) * (num - len(ll)) / num))
            sys.stdout.flush()
    else:
        def progress(ll): return

    # UDF
    udf = user.make_udf('~/abundant-files')
    folders.append(user.volume(udf.id).get_node(udf.root_id))

    # some UDFs
    for i in range(num / 100):
        progress(sample)
        folders.append(make_udf(user, sample))

    for i in range(num / 4):
        progress(sample)
        name = sample.pop()
        folders.append(random.choice(folders).make_subdirectory(name))

    sh_folders = [sharer.root]
    for i in range(num / 10):
        progress(sample)
        sh_folders.append(make_udf(sharer, sample))
    for i in range(num / 10):
        progress(sample)
        name = sample.pop()
        sh_folders.append(random.choice(sh_folders).make_subdirectory(name))
    for i in range(num / 20):
        progress(sample)
        name = sample.pop()
        filename = 'shared by ' + sharer.username
        readonly = random.choice((False, True))
        if readonly:
            name += ' (ro)'
            filename += ' (ro)'
        folder = random.choice(sh_folders).make_subdirectory(name)
        folder.make_file(filename)
        share = folder.share(user.id, folder.name, readonly)
        user.get_share(share.id).accept()

    for i in random.sample(folders, len(folders) / 4):
        progress(sample)
        name = sample.pop()
        filename = 'shared by ' + user.username
        readonly = random.choice((False, True))
        if readonly:
            name += ' (ro)'
            filename += ' (ro)'
        folder = random.choice(folders).make_subdirectory(name)
        folder.make_file(filename)
        share = folder.share(sharer.id, folder.name, readonly)
        sharer.get_share(share.id).accept()

    for i in range(num / 20):
        progress(sample)
        name = sample.pop()
        random.choice(folders).make_file(name)

    fake_hash = Factory().get_fake_hash()
    while sample:
        progress(sample)
        name = sample.pop()
        random.choice(folders).make_file_with_content(
            name, fake_hash, 12345, 100, 10000, uuid.uuid4(), 'image/tiff')

    if sys.stdout.isatty():
        sys.stdout.write(home + curses.tigetstr('el'))
def main(username, sharer, wlist, num):
    """Create UDFs, folders and files for the given user using a wordlist."""
    user = get_storage_user(None, username=utf2unicode(username))
    sharer = get_storage_user(None, username=utf2unicode(sharer))
    folders = [user.root]
    names = [utf2unicode(i.strip()) for i in file(wlist) if i.strip()]
    sample = random.sample(names, num)

    if sys.stdout.isatty():
        import curses
        curses.setupterm()
        cols = curses.tigetnum('cols') - 1
        progbar = makeStatBar(cols, cols - 2)
        home = curses.tigetstr('cr')

        def progress(l):
            """progress bar writer."""
            sys.stdout.write(home + progbar((cols - 2) * (num - len(l)) / num))
            sys.stdout.flush()
    else:
        def progress(l): return

    # UDF
    udf = user.make_udf('~/abundant-files')
    folders.append(user.volume(udf.id).get_node(udf.root_id))

    # some UDFs
    for i in range(num / 100):
        progress(sample)
        folders.append(make_udf(user, sample))

    for i in range(num / 4):
        progress(sample)
        name = sample.pop()
        folders.append(random.choice(folders).make_subdirectory(name))

    sh_folders = [sharer.root]
    for i in range(num / 10):
        progress(sample)
        sh_folders.append(make_udf(sharer, sample))
    for i in range(num / 10):
        progress(sample)
        name = sample.pop()
        sh_folders.append(random.choice(sh_folders).make_subdirectory(name))
    for i in range(num / 20):
        progress(sample)
        name = sample.pop()
        filename = 'shared by ' + sharer.username
        readonly = random.choice((False, True))
        if readonly:
            name += ' (ro)'
            filename += ' (ro)'
        folder = random.choice(sh_folders).make_subdirectory(name)
        folder.make_file(filename)
        share = folder.share(user.id, folder.name, readonly)
        user.get_share(share.id).accept()

    for i in random.sample(folders, len(folders) / 4):
        progress(sample)
        name = sample.pop()
        filename = 'shared by ' + user.username
        readonly = random.choice((False, True))
        if readonly:
            name += ' (ro)'
            filename += ' (ro)'
        folder = random.choice(folders).make_subdirectory(name)
        folder.make_file(filename)
        share = folder.share(sharer.id, folder.name, readonly)
        sharer.get_share(share.id).accept()

    for i in range(num / 20):
        progress(sample)
        name = sample.pop()
        random.choice(folders).make_file(name)

    fake_hash = Factory().get_fake_hash()
    while sample:
        progress(sample)
        name = sample.pop()
        random.choice(folders).make_file_with_content(
            name, fake_hash, 12345, 100, 10000, uuid.uuid4(), 'image/tiff')

    if sys.stdout.isatty():
        sys.stdout.write(home + curses.tigetstr('el'))