Exemple #1
0
 def test_find_files_iterator(self):
     resp = reusables.find_files(test_root, ext=".cfg")
     assert not isinstance(resp, list)
     resp = [x for x in resp]
     assert [
         x for x in resp
         if x.endswith(os.path.join(test_root, "test_config.cfg"))
     ]
def remove_duplicates(directory):
    sizes = {}

    for image in reusables.find_files(directory):
        file_size = os.path.getsize(image)
        if file_size not in sizes:
            sizes[file_size] = [image]
        else:
            sizes[file_size].append(image)

    size_matches = [v for v in sizes.values() if len(v) > 1]

    hashes = {}
    for possible_duplicates in size_matches:
        for dd in possible_duplicates:
            file_hash = reusables.file_hash(dd)
            if file_hash not in hashes:
                hashes[file_hash] = [dd]
            else:
                hashes[file_hash].append(dd)

    return [v for v in hashes.values() if len(v) > 1]
shutil.move(
    c(os.path.join(program_name, 'static', 'css', 'project_name.css')),
    c(os.path.join(program_name, 'static', 'css', f'{program_name}.css')))
shutil.move(
    c(os.path.join(program_name, 'static', 'js', 'project_name.js')),
    c(os.path.join(program_name, 'static', 'js', f'{program_name}.js')))


def replace_file(replace_file):
    global program_name
    with open(replace_file, 'r+') as f:
        data = f.read().replace('<project_name>',
                                program_name).replace('project_name',
                                                      program_name)
        f.seek(0)
        f.write(data)
        f.truncate()


for file in list(
        reusables.find_files(program_name, ext=('css', 'js', 'py', 'html'))):
    replace_file(file)

for file in [
        f'{program_name}.logging.yaml', f'{program_name}.service',
        '.gitignore', 'deploy.sh', 'README.md'
]:
    replace_file(file)

print('Setup has completed, you may now delete this file\n')
Exemple #4
0
 def test_find_files_bad_ext(self):
     resp = iter(reusables.find_files(test_root, ext={'test': '.txt'}))
     self.assertRaises(TypeError, next, resp)
Exemple #5
0
 def test_find_files_iterator(self):
     resp = reusables.find_files(test_root, ext=".cfg")
     assert not isinstance(resp, list)
     resp = [x for x in resp]
     assert [x for x in resp if x.endswith(os.path.join(test_root, "test_config.cfg"))]
Exemple #6
0
 def test_find_files_bad_ext(self):
     resp = iter(reusables.find_files(test_root,
                                                ext={'test': '.txt'}))
     self.assertRaises(TypeError, next, resp)