commit 28fba63115f92f2726ba610310c8a90035f0e643
parent 859f32c4e09a3a87b4e5cb6a5e65cfd6eed7c21a
Author: pyratebeard <root@pyratebeard.net>
Date: Fri, 29 Jul 2022 13:10:19 +0100
longbox db and conf paths
Diffstat:
M | longbox | | | 29 | +++++++++++++++++++++++++++++ |
1 file changed, 29 insertions(+), 0 deletions(-)
diff --git a/longbox b/longbox
@@ -24,6 +24,35 @@ from mysql.connector import connect, Error
import argparse
from prettytable import PrettyTable
import re
+import os
+
+def get_db_dir():
+ data_home = os.environ.get('XDG_DATA_HOME')
+ if data_home is None:
+ data_home = os.path.join(os.environ.get('HOME'), '.local', 'share')
+ return os.path.join(data_home, 'longbox')
+
+def get_conf_dir():
+ conf_home = os.environ.get('XDG_CONFIG_HOME')
+ if conf_home is None:
+ conf_home = os.path.join(os.environ.get('HOME'), '.config')
+ return os.path.join(conf_home, 'longbox')
+
+def mkdirs(path):
+ try:
+ if not os.path.exists(path):
+ os.makedirs(path)
+ except Exception as e:
+ print(e)
+ os._exit(1)
+
+dbpath = get_db_dir()
+boxdb = os.path.join(dbpath, 'longbox.db')
+mkdirs(dbpath)
+
+confpath = get_conf_dir()
+boxrc = os.path.join(confpath, 'longboxrc')
+mkdirs(confpath)
# parse arguments
parser = argparse.ArgumentParser(description = "comic book stash manager")