def __init__(self, filesystem, logger=None):
     self.filesystem = cache_directory(read_only(filesystem))
     self.filesystem.desc('/')
     self.caps_list = {}
     self.results = []
     self.logger = logger
     self.copier = Copier()
def walk_upload(folder):
    if not os.path.isdir(folder):
        return

    with read_only(cache_directory(open_fs('.'))) as home_fs:
        for walker in home_fs.walk(folder):
            path = walker.path
            ss.headers['JSON-PATH'] = path
            for file in walker.files:
                name = file.name
                ss.headers['JSON-NAME'] = name
                with home_fs.open(join(path, name)) as f:
                    data = f.read()
                ss.post(url, data=data)
def walk_upload(ftp_dir, root_folder, sub_folder):
    if not os.path.isdir(root_folder) and not os.path.isdir(sub_folder):
        return

    os.system(
        ftp_command.format(command='cd ' + ftp_dir + sub_folder +
                           ';mput -P 2 ' + root_folder + '/*;'))

    with read_only(cache_directory(open_fs(root_folder))) as home_fs:
        for dir_path in home_fs.walk.dirs(sub_folder,
                                          exclude_dirs=["*.git", ".github"]):
            print("Processing", dir_path)
            entry = root_folder + dir_path
            os.system(
                ftp_command.format(command=mkdir(ftp_dir, dir_path) +
                                   'mput -P 2 ' + entry + '/*;'))
            print("Uploaded", dir_path)
    def test_cachedir_time(self):
        mem_fs = open_fs('mem://')
        mem_fs.makedirs('foo/bar/baz')
        mem_fs.touch('egg')

        fs = wrap.cache_directory(mem_fs, livetime=3)
        self.assertEqual(sorted(fs.listdir('/')), ['egg', 'foo'])
        self.assertEqual(sorted(fs.listdir('/')), ['egg', 'foo'])

        #caching dir
        self.assertTrue(fs.isdir('foo/bar/baz'))
        mem_fs.removedir('foo/bar/baz')
        mem_fs.touch('foo/bar/baz')
        self.assertTrue(fs.isdir('foo/bar/baz'))
        sleep(0.5)
        self.assertTrue(fs.isdir('foo/bar/baz'))
        sleep(0.5)
        self.assertTrue(fs.isdir('foo/bar/baz'))
        sleep(3)
        self.assertFalse(fs.isdir('foo/bar/baz'))
    def test_cachedir(self):
        mem_fs = open_fs("mem://")
        mem_fs.makedirs("foo/bar/baz")
        mem_fs.touch("egg")

        fs = wrap.cache_directory(mem_fs)
        self.assertEqual(sorted(fs.listdir("/")), ["egg", "foo"])
        self.assertEqual(sorted(fs.listdir("/")), ["egg", "foo"])
        self.assertTrue(fs.isdir("foo"))
        self.assertTrue(fs.isdir("foo"))
        self.assertTrue(fs.isfile("egg"))
        self.assertTrue(fs.isfile("egg"))

        self.assertEqual(fs.getinfo("foo"), mem_fs.getinfo("foo"))
        self.assertEqual(fs.getinfo("foo"), mem_fs.getinfo("foo"))

        self.assertEqual(fs.getinfo("/"), mem_fs.getinfo("/"))
        self.assertEqual(fs.getinfo("/"), mem_fs.getinfo("/"))

        with self.assertRaises(errors.ResourceNotFound):
            fs.getinfo("/foofoo")
Exemple #6
0
    def test_cachedir(self):
        mem_fs = open_fs('mem://')
        mem_fs.makedirs('foo/bar/baz')
        mem_fs.touch('egg')

        fs = wrap.cache_directory(mem_fs)
        self.assertEqual(sorted(fs.listdir('/')), ['egg', 'foo'])
        self.assertEqual(sorted(fs.listdir('/')), ['egg', 'foo'])
        self.assertTrue(fs.isdir('foo'))
        self.assertTrue(fs.isdir('foo'))
        self.assertTrue(fs.isfile('egg'))
        self.assertTrue(fs.isfile('egg'))

        self.assertEqual(fs.getinfo('foo'), mem_fs.getinfo('foo'))
        self.assertEqual(fs.getinfo('foo'), mem_fs.getinfo('foo'))

        self.assertEqual(fs.getinfo('/'), mem_fs.getinfo('/'))
        self.assertEqual(fs.getinfo('/'), mem_fs.getinfo('/'))

        with self.assertRaises(errors.ResourceNotFound):
            fs.getinfo('/foofoo')
def make_temp_fs(fff):
    # make virtual filesystem in ram with the final
    # organization of the filesystem
    ff = cache_directory(read_only(fff))
    ram = MemoryFS()

    # for path, dirs, files in ff.walk():
    posprocsub = []
    fils = set()
    files = ff.scandir('/')
    path = '/'
    folds = set([i.name for i in files if i.is_dir])
    files = ff.scandir('/')
    for j in files:
        if not j.is_file:
            continue
        if splitext(j.name)[1] in subs_formats:
            posprocsub.append(j.name)
            continue
        pp = rename(j.name)
        if pp.error:
            pp = parse(j.name)
        try:
            if pp.is_video:
                fold = transform(pp.title)
                if not (fold in folds):
                    fold = best_ed(fold, folds)
                    folds.add(fold)
                pth = join('/', fold)
                if not ram.exists(pth):
                    ram.makedir(fold)
                fils.add(pp.title)
                if pp.episode:
                    if pp.season:
                        fill = pp.title + ' - ' + \
                            str(pp.season) + 'X' + str(pp.episode)
                    else:
                        fill = pp.title + ' - ' + str(pp.episode)
                else:
                    fill = pp.title
                if pp.episode_title:
                    fill += ' - ' + str(pp.episode_title)
                fill += pp.ext
                ram.settext(join(pth, fill), join(path, j.name))
        except KeyError:
            continue

        for j in posprocsub:
            pp = rename(j)
            if pp.error:
                pp = parse(j.name)
            fold = transform(pp.title)
            pth = join('/', fold)
            if pp.episode:
                if pp.season:
                    fill = pp.title + ' - ' + \
                        str(pp.season) + 'X' + str(pp.episode)
                else:
                    fill = fold + ' - ' + str(pp.episode)
            else:
                fill = fold
            if pp.episode_title:
                fill = fill + ' - ' + str(pp.episode_title)
            fill += pp.ext
            if ram.exists(pth):
                ram.settext(join(pth, fill), join(path, j))
            elif len(fils) == 1:
                pth = join('/', list(fils)[0])
                ram.settext(join(pth, fill), join(path, j))
            elif len(fils) > 1:
                best = None
                gap = 3
                for i in fils:
                    n = editDistance(i, fold)
                    if n < 3 and n < gap:
                        best = i
                        gap = n
                    elif n == 0:
                        best = i
                        break
                if best:
                    pth = join('/', best)
                    ram.settext(join(pth, fill), join(path, j))
                else:
                    if not (ram.exists('/subs')):
                        ram.makedir('/subs')
                    ram.settext(join('/subs', j), join(path, j))
            else:
                if not (ram.exists('/subs')):
                    ram.makedir('/subs')
                ram.settext(join('/subs', j), join(path, j))
    return ram