1
0
mirror of https://github.com/nophead/Mendel90.git synced 2025-01-16 20:38:15 +01:00
Mendel90/prune.py
Chris Palmer 8a5578948f Mods for Python 3 compatibility.
Added make_all_machines.py to build all variations.
2016-04-25 15:23:51 +01:00

44 lines
1.0 KiB
Python

#!/usr/bin/env python
from __future__ import print_function
import sys
import os
import shutil
import filecmp
def prune_dir(dst, src):
for file in os.listdir(dst):
dfile = dst + '/' + file
sfile = src + '/' + file
if os.path.isdir(dfile):
prune_dir(dfile, sfile)
else:
if not os.path.isfile(sfile) or not filecmp.cmp(dfile, sfile):
print(dfile)
else:
os.remove(dfile)
def prune(variant):
#
# Check directories exist
#
target_dir = variant
if not os.path.isdir(target_dir):
print("directory", target_dir, "does not exist")
return
source_dir = variant.split('_')[0]
if not os.path.isdir(source_dir):
print("directory", source_dir, "does not exist")
return
prune_dir(target_dir, source_dir)
if __name__ == '__main__':
if len(sys.argv) == 2:
prune(sys.argv[1])
else:
print("usage: remove_identical_files machine_variant")
sys.exit(1)