Skip to content

Commit 87785bd

Browse files
Added custom directory support
1 parent 8d3e548 commit 87785bd

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

NHXDB/NHXDB.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33

44
class database:
55

6-
def __init__(self, verbose=False):
6+
def __init__(self, verbose=False, directory=None):
7+
self.logged_in = False
8+
self.logged_DB = None
9+
self.defaultwd = None
10+
self.verbose = verbose
711
try:
8-
self.logged_in = False
9-
self.logged_DB = None
10-
if verbose == True:
11-
self.verbose = True
12+
if directory == None or os.path.exists(directory) == False:
13+
if sys.platform.lower().startswith("win32"):
14+
defaultwd = "C:/Users/" + os.getlogin() + "/AppData/Local/"
15+
else:
16+
defaultwd = "/usr/local/share/"
1217
else:
13-
self.verbose = False
14-
if sys.platform.lower().startswith("linux") or sys.platform.lower().startswith("darwin"):
15-
defaultwd = "/usr/local/share/"
16-
elif sys.platform.lower().startswith("win32"):
17-
defaultwd = "C:/Users/" + os.getlogin() + "/AppData/Local/"
18+
defaultwd = directory
1819
if os.path.exists(defaultwd + "NHX") != True:
1920
os.mkdir(defaultwd + "NHX")
2021
os.mkdir(defaultwd + "NHX/NHXDB-Data")

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ NHXDB syntax is made as closer as possible to the syntax of Python. Moreover, th
5050

5151
The main database object is called by the following syntax:
5252
```sh
53-
db = NHXDB.database(<optional:verbose=False>, <optional:default_directory=None>)
53+
db = NHXDB.database(<optional:verbose=False>, <optional:directory=None>)
5454
```
5555
If verbose functionality is required, use 1 or True as argument to enable verbosity (or otherwise verbose=True). This allows to return, instead of status code, an exception on screen (when occured). The default_directory, when None, will use the directory specified by NHXDB, or otherwise if specified directory is not found (must be full Path). Else, the provided path is used.
5656
All administration functions are then called on the ```db``` variable, as well as the db variable is passed to the table() object after logging in for manipulation of data inside tables.

0 commit comments

Comments
 (0)