From 7c9e4c99c0d6ba24faac2006b8b707038e12653e Mon Sep 17 00:00:00 2001 From: Gergely Wootsch Date: Wed, 5 Oct 2022 22:25:44 +0200 Subject: [PATCH] Fix database folder checking --- bookmarks/database.py | 30 ++++++++++++++---------------- bookmarks/test/run_tests.py | 2 -- set_version.py | 28 ++++++++++++++++------------ 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/bookmarks/database.py b/bookmarks/database.py index 73a0cd85..ecdc0fd9 100644 --- a/bookmarks/database.py +++ b/bookmarks/database.py @@ -494,11 +494,11 @@ def __init__(self, server, job, root, parent=None): self._is_valid = False self._connection = None - self._server = server - self._job = job - self._root = root + self.server = server + self.job = job + self.root = root - self._bookmark = '/'.join((server, job, root)) + self._bookmark = f'{server}/{job}/{root}' self._bookmark_root = f'{self._bookmark}/{common.bookmark_cache_dir}' self._database_path = f'{self._bookmark_root}/{common.bookmark_database}' @@ -568,8 +568,12 @@ def _create_bookmark_dir(self): can't create the folder. """ - _cache_dir = QtCore.QDir(self.root()) - _thumb_dir = QtCore.QDir(f'{self.root()}/thumbnails') + _root_dir = QtCore.QDir(self._bookmark) + if not _root_dir.exists(): + return False + + _cache_dir = QtCore.QDir(self._bookmark_root) + _thumb_dir = QtCore.QDir(f'{self._bookmark_root}/thumbnails') if not _cache_dir.exists(): if not _cache_dir.mkpath('.'): log.error(f'Could not create {_cache_dir.path()}') @@ -632,9 +636,9 @@ def _add_info(self): ) ).format( id=common.get_hash(self._bookmark), - server=b64encode(self._server), - job=b64encode(self._job), - root=b64encode(self._root), + server=b64encode(self.server), + job=b64encode(self.job), + root=b64encode(self.root), user=b64encode(common.get_username()), host=b64encode(platform.node()), created=time.time(), @@ -666,12 +670,6 @@ def _init_tables(self): raise sleep() - def root(self): - """Returns the `root` path. - - """ - return self._bookmark_root - def is_valid(self): """Returns the database's status. @@ -712,7 +710,7 @@ def source(self, *args): """ if args: - return self._bookmark + '/' + '/'.join(args) + return f'{self._bookmark}/{"/".join(args)}' return self._bookmark def get_row(self, source, table): diff --git a/bookmarks/test/run_tests.py b/bookmarks/test/run_tests.py index 9053f5e7..4f36bbc2 100644 --- a/bookmarks/test/run_tests.py +++ b/bookmarks/test/run_tests.py @@ -12,7 +12,6 @@ import bookmarks.test.test_settings import bookmarks.test.test_session_lock import bookmarks.test.test_actions -import bookmarks.test.test_bookmarker if __name__ == '__main__': loader = unittest.TestLoader() @@ -26,7 +25,6 @@ loader.loadTestsFromTestCase(bookmarks.test.test_settings.Test), loader.loadTestsFromTestCase(bookmarks.test.test_actions.Test), loader.loadTestsFromTestCase(bookmarks.test.test_actions.TestWidgetActions), - loader.loadTestsFromTestCase(bookmarks.test.test_bookmarker.Test), ) suite = unittest.TestSuite(cases) unittest.TextTestRunner(verbosity=2, failfast=True).run(suite) diff --git a/set_version.py b/set_version.py index 012473eb..a614187f 100644 --- a/set_version.py +++ b/set_version.py @@ -6,19 +6,25 @@ pkg_root = QtCore.QFileInfo(f'{__file__}{os.path.sep}..').absoluteFilePath() - STRINGS = { - f'{pkg_root}/docs/source/conf.py': re.compile(r"release = \'([0-9]\.[0-9]\.[0-9])\'", flags=re.MULTILINE), - f'{pkg_root}/bookmarks/__init__.py': re.compile(r"Version-v([0-9]\.[0-9]\.[0-9])", flags=re.MULTILINE), - f'{pkg_root}/bookmarks/__init__.py': re.compile(r"__version__ = \'([0-9]\.[0-9]\.[0-9])\'", flags=re.MULTILINE), - f'{pkg_root}/README.md': re.compile(r"Version-v([0-9]\.[0-9]\.[0-9])", flags=re.MULTILINE), - f'{pkg_root}/bookmarks/maya/plugin.py': re.compile(r"__version__ = \'([0-9]\.[0-9]\.[0-9])\'", flags=re.MULTILINE), - f'{pkg_root}/installer/installer.iss': re.compile(r'#define MyAppVersion "([0-9]\.[0-9]\.[0-9])"', flags=re.MULTILINE), - f'{pkg_root}/launcher/CMakeLists.txt': re.compile(r'VERSION ([0-9]\.[0-9]\.[0-9])', flags=re.MULTILINE), - f'{pkg_root}/docs/source/guide.rst': re.compile(r'.*([0-9]\.[0-9]\.[0-9]).*', flags=re.MULTILINE), + f'{pkg_root}/docs/source/conf.py': re.compile(r"release = \'([0-9]\.[0-9]\.[0-9])\'", + flags=re.MULTILINE), + f'{pkg_root}/bookmarks/__init__.py': re.compile(r"Version-v([0-9]\.[0-9]\.[0-9])", + flags=re.MULTILINE), + f'{pkg_root}/bookmarks/__init__.py': re.compile( + r"__version__ = \'([0-9]\.[0-9]\.[0-9])\'", flags=re.MULTILINE), + f'{pkg_root}/README.md': re.compile(r"Version-v([0-9]\.[0-9]\.[0-9])", + flags=re.MULTILINE), + f'{pkg_root}/bookmarks/maya/plugin.py': re.compile( + r"__version__ = \'([0-9]\.[0-9]\.[0-9])\'", flags=re.MULTILINE), + f'{pkg_root}/installer/installer.iss': re.compile( + r'#define MyAppVersion "([0-9]\.[0-9]\.[0-9])"', flags=re.MULTILINE), + f'{pkg_root}/launcher/CMakeLists.txt': re.compile(r'VERSION ([0-9]\.[0-9]\.[0-9])', + flags=re.MULTILINE), + f'{pkg_root}/docs/source/guide.rst': re.compile(r'.*([0-9]\.[0-9]\.[0-9]).*', + flags=re.MULTILINE), } - app = QtWidgets.QApplication() version, res = QtWidgets.QInputDialog.getText(None, 'Enter Version', 'New Version') @@ -27,7 +33,6 @@ if not version: raise RuntimeError('Must enter a valid version') - for k, v in STRINGS.items(): if not os.path.isfile(k): raise RuntimeError(f'{k} does not exist.') @@ -41,4 +46,3 @@ with open(k, 'w', encoding='utf-8') as f: f.write(v) -