Remove orphaned compiled forms when switching branches

This commit is contained in:
Kovid Goyal 2017-06-09 00:21:10 +05:30
parent 9065690ff7
commit 2c80dc2aed
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -20,16 +20,19 @@ class GUI(Command):
parser.add_option('--summary', default=False, action='store_true', parser.add_option('--summary', default=False, action='store_true',
help='Only display a summary about how many files were compiled') help='Only display a summary about how many files were compiled')
@classmethod def find_forms(self):
def find_forms(cls):
# We do not use the calibre function find_forms as # We do not use the calibre function find_forms as
# mporting calibre.gui2 may not work # importing calibre.gui2 may not work
forms = [] forms = []
for root, _, files in os.walk(cls.PATH): for root, _, files in os.walk(self.PATH):
for name in files: for name in files:
path = os.path.abspath(os.path.join(root, name))
if name.endswith('.ui'): if name.endswith('.ui'):
forms.append(os.path.abspath(os.path.join(root, name))) forms.append(path)
elif name.endswith('_ui.py') or name.endswith('_ui.pyc'):
fname = path.rpartition('_')[0] + '.ui'
if not os.path.exists(fname):
os.remove(path)
return forms return forms
@classmethod @classmethod