From 3ea394937bcc9ac24a30fd068bbd05e056e48b31 Mon Sep 17 00:00:00 2001 From: derrod Date: Mon, 2 Nov 2020 15:14:59 +0100 Subject: [PATCH] [lfs] Migrate old manifest structure to new --- legendary/lfs/lgndry.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/legendary/lfs/lgndry.py b/legendary/lfs/lgndry.py index 7a960f5..9f78ef6 100644 --- a/legendary/lfs/lgndry.py +++ b/legendary/lfs/lgndry.py @@ -35,6 +35,33 @@ class LGDLFS: if not os.path.exists(os.path.join(self.path, f)): os.makedirs(os.path.join(self.path, f)) + # if "old" folder exists migrate files and remove it + if os.path.exists(os.path.join(self.path, 'manifests', 'old')): + self.log.info('Migrating manifest files from old folders to new, please wait...') + # remove unversioned manifest files + for _f in os.listdir(os.path.join(self.path, 'manifests')): + if '.manifest' not in _f: + continue + if '_' not in _f or (_f.startswith('UE_') and _f.count('_') < 2): + self.log.debug(f'Deleting "{_f}" ...') + os.remove(os.path.join(self.path, 'manifests', _f)) + + # move files from "old" to the base folder + for _f in os.listdir(os.path.join(self.path, 'manifests', 'old')): + try: + self.log.debug(f'Renaming "{_f}"') + os.rename(os.path.join(self.path, 'manifests', 'old', _f), + os.path.join(self.path, 'manifests', _f)) + except Exception as e: + self.log.warning(f'Renaming manifest file "{_f}" failed: {e!r}') + + # remove "old" folder + try: + os.removedirs(os.path.join(self.path, 'manifests', 'old')) + except Exception as e: + self.log.warning(f'Removing "{os.path.join(self.path, "manifests", "old")}" folder failed: ' + f'{e!r}, please remove manually') + # try loading config self.config.read(os.path.join(self.path, 'config.ini')) # make sure "Legendary" section exists