-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppProject.py
68 lines (57 loc) · 2.18 KB
/
AppProject.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
# -*- coding: utf-8 -*-
import configparser
from pathlib import Path
import LogWidget
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
#Python2
#class MyClass(BaseClass):
# __metaclass__ = Singleton
#Python3
class AppProject(metaclass=Singleton):
def __init__(self):
#super(AppProject, self).__init__()
self.mFilePath = u''
self.mDBFolder = u'db'
self.mSimFolder = u'sim'
self.mLogWdg = None
def reset(self):
self.mFilePath = u''
self.mDBFolder = u'db'
self.mSimFolder = u'sim'
def save(self):
if self.mFilePath !='' and Path( self.mFilePath ).parent.exists():
config = configparser.ConfigParser()
config['Paths'] = {'DB': self.mDBFolder,
'Sim': self.mSimFolder}
with open(self.mFilePath, 'w') as projectfile:
config.write(projectfile)
def load(self):
config = configparser.ConfigParser()
if self.mFilePath !='' and Path( self.mFilePath ).exists():
config.read(self.mFilePath)
self.mDBFolder = config['Paths']['DB']
self.mSimFolder = config['Paths']['Sim']
def creatFolder(self):
profile = Path( self.mFilePath )
if self.mFilePath !='' and profile.exists():
dirPath = (profile.parent / self.mDBFolder)
if not dirPath.exists() :
dirPath.mkdir()
dirPath = (profile.parent / self.mSimFolder)
if not dirPath.exists() :
dirPath.mkdir()
def getPath(self,pathType,dfFileName):
profile = Path( self.mFilePath )
if self.mFilePath !='' and profile.exists():
if( pathType ) == 'DB' :
return str( profile.parent / self.mDBFolder / dfFileName )
if( pathType ) == 'Sim' :
return str( profile.parent / self.mSimFolder / dfFileName )
else:
return ''