프로젝트

일반

사용자정보

개정판 2709dc9f

ID2709dc9fcf697f4aefe09da1a31ace9a5fb369e0
상위 eb1fe49e
하위 80f6becd

humkyung 이(가) 약 7년 전에 추가함

Move Project.db file from executable folder to Program Data folder

차이점 보기:

DTI_PID/DTI_PID/AppDocData.py
11 11
import datetime
12 12

  
13 13
DB_NAME = os.path.dirname(os.path.realpath(__file__)) + "\\db\\DTI_PID.db"
14
PROJECT_DB_PATH = os.path.dirname(os.path.realpath(__file__)) + "\\Project_db.db"
15 14

  
16 15
class Area:
17 16
    def __init__(self):
......
57 56

  
58 57
            fileNames = os.listdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Scripts'))
59 58
            for fileName in fileNames:
60
                if fileName.endswith(".sql"):
59
                if fileName.endswith(".sql") and (1 == len(os.path.splitext(fileName).split('.'))):
61 60
                    try:
62 61
                        file = QFile(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Scripts', fileName))
63 62
                        file.open(QFile.ReadOnly)
......
83 82
        return self.project
84 83

  
85 84
    '''
86
        @brief  return project database path
85
        @brief      return project database path
86
        @history    humkyung 2018.04.19 return Project.db in Program Data folder instead of PROJECT_DB_PATH variable
87 87
    '''
88 88
    def getPrjDatabasePath(self):
89
        return PROJECT_DB_PATH
89
        path = os.path.join(os.getenv('ALLUSERSPROFILE'), 'Digital PID')
90
        if not os.path.exists(path): os.makedirs(path)
91

  
92
        prjDatabaseFilePath = os.path.join(path, 'Project.db')
93
        try:
94
            # Creates or opens a file called mydb with a SQLite3 DB
95
            conn = sqlite3.connect(prjDatabaseFilePath)
96
            # Get a cursor object
97
            cursor = conn.cursor()
98

  
99
            filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Scripts', 'Project.Projects.sql')
100
            try:
101
                file = QFile(filePath)
102
                file.open(QFile.ReadOnly)
103
                sql = file.readAll()
104
                sql = str(sql, encoding='utf8')
105
                cursor.executescript(sql)
106
            finally:
107
                file.close()
108
            conn.commit()
109
        # Catch the exception
110
        except Exception as ex:
111
            # Roll back any change if something goes wrong
112
            conn.rollback()
113
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
114
        finally:
115
            # Close the db connection
116
            conn.close()
117
        
118
        return prjDatabaseFilePath
90 119

  
91 120
    '''
92 121
        @brief  return line properties
......
122 151
        @brief      Insert New Project Info
123 152
        @author     Jeongwoo
124 153
        @date       2018.04.06
125
        @history    .
154
        @history    humkyung 2018.04.19 use getPrjDatabasePath function instead of PROJECT_DB_PATH variable
126 155
    '''
127 156
    def insertProjectInfo(self, dir):
128
        conn = sqlite3.connect(PROJECT_DB_PATH)
129
        folderName = dir.split('/')[-1]
130
        if folderName:
131
            nowDate = datetime.datetime.now().strftime('%Y.%m.%d %H:%M')
132
            sql = "INSERT INTO Projects(Name, Path, CreatedDate, UpdatedDate) VALUES('" + folderName + "', '" + dir + "', '" + nowDate + "', '" + nowDate + "')"
133
            cur = conn.cursor()
134
            cur.execute(sql)
135
            conn.commit()
157
        try:
158
            prjDatabaseFilePath = self.getPrjDatabasePath()
159
            conn = sqlite3.connect(prjDatabaseFilePath)
160
            folderName = dir.split('/')[-1]
161
            if folderName:
162
                nowDate = datetime.datetime.now().strftime('%Y.%m.%d %H:%M')
163
                sql = "INSERT INTO Projects(Name, Path, CreatedDate, UpdatedDate) VALUES('" + folderName + "', '" + dir + "', '" + nowDate + "', '" + nowDate + "')"
164
                cur = conn.cursor()
165
                cur.execute(sql)
166
                conn.commit()
167
            else:
168
                print("Empty folder name")
169
        except Exception as ex:
170
            # Roll back any change if something goes wrong
171
            conn.rollback()
172
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
173
        finally:
136 174
            conn.close()
137
        else:
138
            print("Empty folder name")
139 175

  
140 176
    '''
141 177
        @brief      Update Project UpdatedDate Field
142 178
        @author     Jeongwoo
143 179
        @date       2018.04.06
144
        @history    .
180
        @history    humkyung 2018.04.19 use getPrjDatabasePath function instead of PROJECT_DB_PATH variable
145 181
    '''
146 182
    def updateProjectUpdatedDate(self, id):
147
        conn = sqlite3.connect(PROJECT_DB_PATH)
148
        nowDate = datetime.datetime.now().strftime('%Y.%m.%d %H:%M')
149
        sql = '''
150
            UPDATE Projects
151
            SET UpdatedDate = ?
152
            WHERE Id = ?
153
        '''
154
        cur = conn.cursor()
155
        cur.execute(sql, (nowDate, id))
156
        conn.commit()
157
        conn.close()
183
        try:
184
            prjDatabaseFilePath = self.getPrjDatabasePath()
185
            conn = sqlite3.connect(prjDatabaseFilePath)
186
            nowDate = datetime.datetime.now().strftime('%Y.%m.%d %H:%M')
187
            sql = '''
188
                UPDATE Projects
189
                SET UpdatedDate = ?
190
                WHERE Id = ?
191
            '''
192
            cur = conn.cursor()
193
            cur.execute(sql, (nowDate, id))
194
            conn.commit()
195
        except Exception as ex:
196
            # Roll back any change if something goes wrong
197
            conn.rollback()
198
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
199
        finally:
200
            conn.close()
158 201

  
159 202
    '''
160 203
        @brief  get project list from database
204
        @history    humkyung 2018.04.18 add only project which's project exists
161 205
    '''
162 206
    def getProjectList(self):
163 207
        from Project import Project
......
167 211
        try:
168 212
            conn = sqlite3.connect(self.getPrjDatabasePath())
169 213
            cursor = conn.cursor()
170
            sql = 'SELECT * FROM Projects ORDER BY UpdatedDate DESC'
214
            sql = 'SELECT id,name,path,createddate,updateddate  FROM Projects ORDER BY UpdatedDate DESC'
171 215
            try:
172 216
                cursor.execute(sql)
173 217
                rows = cursor.fetchall()
174 218
                for row in rows:
175
                    projectList.append(Project(row[0], row[1], row[2], row[3], row[4]))
219
                    if os.path.isdir(row[2]):   # check if folder exists
220
                        projectList.append(Project(row[0], row[1], row[2], row[3], row[4]))
176 221
            except Exception as ex:
177 222
                print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
178 223
        finally:
DTI_PID/DTI_PID/Scripts/Project.Projects.sql
1
CREATE TABLE IF NOT EXISTS `Projects` (
2
	`Id`	INTEGER PRIMARY KEY AUTOINCREMENT,
3
	`Name`	TEXT,
4
	`Path`	TEXT,
5
	`CreatedDate`	TEXT,
6
	`UpdatedDate`	TEXT
7
);

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)