Created
June 16, 2014 21:37
-
-
Save cogumbreiro/6ad72831c679c4ca99cd to your computer and use it in GitHub Desktop.
Lists the unknown files in a why3session.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import xml.etree.ElementTree as etree | |
from os.path import join, isfile | |
from os import listdir, unlink | |
from fnmatch import fnmatch | |
IGNORED = [ | |
'*.bak', | |
'#*#', | |
'why3session.xml', | |
] | |
def get_edited(basedir): | |
t = etree.parse(join(basedir, 'why3session.xml')) | |
for proof in t.findall('.//proof[@edited]'): | |
yield proof.attrib['edited'] | |
def get_all_files(basedir): | |
return (f for f in listdir(basedir) if isfile(join(basedir,f))) | |
def match_any(filename, patterns): | |
for patt in patterns: | |
if fnmatch(filename, patt): | |
return True | |
return False | |
def list_extra_files(basedir, ignored=IGNORED): | |
edited = set(get_edited(basedir)) | |
for x in get_all_files(basedir): | |
if x not in edited and not match_any(x, ignored): | |
yield x | |
def remove_extra_files(basedir): | |
for x in list_extra_files(basedir): | |
print(join(basedir, x)) | |
if __name__ == '__main__': | |
import sys | |
if len(sys.argv) != 2: | |
print("usage: why3unknown [FILE|DIRECTORY]", file=sys.stderr) | |
exit(-1) | |
file_or_dir = sys.argv[1] | |
if file_or_dir.endswith('.why') or file_or_dir.endswith('.mlw'): | |
basedir = file_or_dir[:-4] | |
else: | |
basedir = file_or_dir | |
remove_extra_files(basedir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To remove unknown files, I am doing the current fish shell: