rmfMostRecent

This commit is contained in:
Geoffrey Frogeye 2019-06-18 09:19:54 +02:00
parent e76aaec03c
commit 90d5cd4d1f

View file

@ -345,7 +345,7 @@ class DatabaseFile():
table.set(x, y+1, features[featureName][y])
table.print()
def decideAction(self):
def decideAction(self, mostRecent=False):
# TODO More arguments for choosing
reason = "undecided"
self.action = None
@ -357,6 +357,16 @@ class DatabaseFile():
if len(features) == 1:
reason = "same files"
self.action = 0
elif 'st_mtime' in features and mostRecent:
recentTime = features['st_mtime'][0]
recentIndex = 0
for index, time in enumerate(features['st_mtime']):
if time > recentTime:
recentTime = time
recentIndex = 0
self.action = recentIndex
reason = "most recent"
if self.action is None:
log.warning(
f"{self.root}/{self.filename}: skip, cause: {reason}")
@ -390,6 +400,8 @@ if __name__ == "__main__":
nargs='?', help='Directory to analyse')
parser.add_argument('-d', '--database',
help='Database path for file informations')
parser.add_argument('-r', '--most-recent', action='store_true',
help='Always keep the most recent version')
parser.add_argument('-e', '--execute', action='store_true',
help='Really apply changes')
parser.add_argument('-p', '--print', action='store_true',
@ -436,4 +448,4 @@ if __name__ == "__main__":
if args.print:
database.printDifferences()
else:
database.takeAction(execute=args.execute)
database.takeAction(mostRecent=args.most_recent, execute=args.execute)