27
27
reload (sys )
28
28
sys .setdefaultencoding ('utf-8' )
29
29
30
+ path_to_dir = "./attachments/"
31
+
30
32
# read config file
31
33
configFile = "bugzilla2github.conf"
32
34
config = ConfigParser .RawConfigParser ()
@@ -63,6 +65,8 @@ def read_bugs(conn):
63
65
results = cur .fetchall ()
64
66
except (Exception , psycopg2 .DatabaseError ) as error :
65
67
print (error )
68
+ results = None
69
+ colnames = None
66
70
return results ,colnames
67
71
68
72
def read_comments (conn ,bug_id ):
@@ -71,11 +75,13 @@ def read_comments(conn,bug_id):
71
75
# create a new cursor object
72
76
cur = conn .cursor (cursor_factory = psycopg2 .extras .DictCursor )
73
77
# execute the SELECT statement
74
- cur .execute (""" SELECT * from longdescs where bug_id=%s limit 1 """ % bug_id ,)
78
+ cur .execute (""" SELECT * from longdescs where bug_id=%s """ % bug_id ,)
75
79
colnames = [desc [0 ] for desc in cur .description ]
76
80
results = cur .fetchall ()
77
81
except (Exception , psycopg2 .DatabaseError ) as error :
78
82
print (error )
83
+ results = None
84
+ colnames = None
79
85
return results ,colnames
80
86
81
87
def read_attachment (conn ,attach_id ):
@@ -89,21 +95,23 @@ def read_attachment(conn,attach_id):
89
95
#print query
90
96
cur .execute (""" SELECT * from attachments where attach_id=%s """ % attach_id , )
91
97
colnames = [desc [0 ] for desc in cur .description ]
92
- results = cur .fetchall ()
98
+ result = cur .fetchone ()
93
99
except (Exception , psycopg2 .DatabaseError ) as error :
94
100
print (error )
95
- return results ,colnames
101
+ result = None
102
+ colnames = None
103
+ return result ,colnames
96
104
97
- def save_attachment (conn ,attach_id ,filename ):
105
+ def save_attachment (conn ,attach_id ,bug_id , comment_id , filename ):
98
106
""" read BLOB data from a table """
99
107
#conn = None
100
108
try :
101
109
# create a new cursor object
102
110
cur = conn .cursor (cursor_factory = psycopg2 .extras .DictCursor )
103
111
# execute the SELECT statement
104
- cur .execute (""" SELECT thedata FROM atatch_data WHERE id=%s """ ,(attach_id ,))
112
+ cur .execute (""" SELECT thedata FROM attach_data WHERE id=%s """ ,(attach_id ,))
105
113
blob = cur .fetchone ()
106
- open (path_to_dir + blob [ 0 ] + '. ' + blob [ 1 ] , 'wb' ).write (blob [2 ])
114
+ open (path_to_dir + str ( bug_id ) + '_ ' + str ( comment_id ) + "_" + filename , 'wb' ).write (blob [0 ])
107
115
# close the communication with the PostgresQL database
108
116
cur .close ()
109
117
except (Exception , psycopg2 .DatabaseError ) as error :
@@ -132,13 +140,17 @@ def save_attachment(conn,attach_id,filename):
132
140
for comment in comments :
133
141
comment_id = comment ["comment_id" ]
134
142
attach_id = comment ["extra_data" ]
135
- if attach_id > 0 :
143
+ if attach_id is not None :
136
144
print " attach_id" ,attach_id
137
145
# check attachment record for this comment
138
146
attachment ,colnames = read_attachment (conn ,attach_id )
139
147
#for activity in activities:
140
- pprint (attachment )
141
- result = save_attachment (attach_id ,bug_id ,comment_id )
148
+ #pprint(colnames)
149
+ #pprint(attachment)
150
+ #attachment=attachment.pop
151
+ filename = attachment ["filename" ]
152
+ print " We have an attachment:" ,filename
153
+ result = save_attachment (conn ,attach_id ,bug_id ,comment_id ,filename )
142
154
143
155
#pprint(comment)
144
156
print " comment_id" ,comment ["comment_id" ]
0 commit comments