-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDB_RepositoryLabel.py
More file actions
92 lines (58 loc) · 2.05 KB
/
DB_RepositoryLabel.py
File metadata and controls
92 lines (58 loc) · 2.05 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import github
import datetime
import db_operation
class DB_RepositoryLabel:
"""
This class represents DB_RepositoryLabel as a database operating class for github.Label.Label
"""
repo = None
label = None
db = None
table = "RepositoryLabel"
def __init__(self, repo, label, db):
self.repo = repo
self.label = label
self.db = db
def open_if_connection_closed(self):
try:
if self.db is None:
return False
if self.db.open == 0:
self.db = db_operation.connect_to_db_simple()
if self.db is None:
return False
return True
except Exception, e:
print e
return False
def save(self):
try:
if self.open_if_connection_closed() == False:
return False
if self.exist():
return True
sql = "insert into %s (color, name, url, repository) values ('%s', '%s', '%s', %d);" \
%(self.table, self.label.color, self.label.name, self.label.url.replace("'", "\\'").replace('"', '\\"'), self.repo.id)
cursor = self.db.cursor()
cursor.execute(sql)
self.db.commit()
return True
except Exception as e:
print e
return False
def exist(self):
try:
if self.open_if_connection_closed() == False:
return False
cursor = self.db.cursor()
sql = "select count(*) from %s where url='%s';"%(self.table, self.label.url)
cursor.execute(sql)
result = cursor.fetchall()
if result[0][0] == 0:
return False
return True
except Exception as e:
print e
return False