From 44f61fb810ad87acaefa3c5d0ff9a5a81145f063 Mon Sep 17 00:00:00 2001 From: Jonathan Grizou Date: Sun, 7 Jul 2013 15:58:22 +0200 Subject: [PATCH] Implemented deep clean which erase every file that is not a '.tex' and every '.tex' file that has no associated paper. --- papers/plugs/texnote/texnote.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/papers/plugs/texnote/texnote.py b/papers/plugs/texnote/texnote.py index acc880b..f127df4 100644 --- a/papers/plugs/texnote/texnote.py +++ b/papers/plugs/texnote/texnote.py @@ -88,6 +88,8 @@ class TexnotePlugin(PapersPlugin): help='delete all but tex files in the texnote folder') p.add_argument('-f', '--force', action='store_true', help='do not ask for confirmation', default=False) + p.add_argument('-d', '--deep', action='store_true', + help='also delete tex file that are not associated a paper', default=False) return parser def command(self, args): @@ -168,18 +170,25 @@ class TexnotePlugin(PapersPlugin): cmd = 'papers list -k |xargs papers export >> {}'.format(TPL_BIB) os.system(cmd) - def clean(self, force=False): + def clean(self, force=False, deep=False): + if deep: + rp = repo.Repository(config()) for f in os.listdir(DIR): path = os.path.join(DIR, f) if os.path.isfile(path): name, extension = os.path.splitext(path) - if extension != '.tex': - if not force: - ui = get_ui() - are_you_sure = 'Are you sure you want to delete file [{}]'.format(path) - sure = ui.input_yn(question=are_you_sure, default='n') - if force or sure: - os.remove(path) + if extension == '.tex': + if not deep: + continue + citekey, _ = os.path.splitext(f) + if citekey in rp: + continue + if not force: + ui = get_ui() + are_you_sure = 'Are you sure you want to delete file [{}]'.format(path) + sure = ui.input_yn(question=are_you_sure, default='n') + if force or sure: + os.remove(path)