-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathadopt-queue.py
More file actions
137 lines (104 loc) · 4.12 KB
/
adopt-queue.py
File metadata and controls
137 lines (104 loc) · 4.12 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import ConfigParser
import sqlite3
import os
import urllib2
import sys
class Adopt():
def __init__(self, argv):
self.examplemode = False
print "Starting up."
self.args = sys.argv
for a in self.args:
if a == "-e":
self.examplemode = True
if os.path.isfile("db.sql"):
os.remove("db.sql")
self.setup_db()
if self.examplemode == True:
self.queuefile = open("exampleadopts/local-queue", 'r')
else:
if os.path.isfile("queue.list"):
print "existing file"
self.queuefile = open("queue.list", 'r')
queuelines = self.queuefile.readlines()
self.fileid = 1
if os.path.getsize("queue.list") == 0:
print "No projects in the queue to process."
else:
print "Processing .adopt files..."
# Let's gather the lines of .adopts that will need to be removed
lines_to_rem = []
for l in queuelines:
print "\t * " + str(l)
if self.examplemode == True:
self.process_file("./exampleadopts/" + l)
else:
f = open("current-adopt.tmp", 'wb')
url = urllib2.urlopen(l)
f.write(url.read())
f.close()
if self.process_file("current-adopt.tmp") == False:
lines_to_rem.append(l)
self.fileid = self.fileid + 1
print "...done."
# Now let's remove .adopts not required
# This happens when the status has changed from 'no' to 'yes'
f = open("queue.list","w")
print "Removing .adopts that are now maintained:"
for line in queuelines:
match = False
for i in lines_to_rem:
if line == i:
print "\t * " + str(line)
match = True
if match == False:
f.write(line)
f.close()
print "...done."
self.queuefile.close()
def setup_db(self):
"""Remove a pre-existing database and create a new database and schema."""
print "Setting up the database..."
self.db = sqlite3.connect("db.sql")
self.db.execute("CREATE TABLE projects (ID INT PRIMARY KEY NOT NULL, \
NAME TEXT NOT NULL, \
DESCRIPTION TEXT NOT NULL, \
CATEGORY TEXT NOT NULL, \
REPO TEXT NOT NULL, \
DISCUSSION TEXT NOT NULL, \
LANGUAGES TEXT NOT NULL, \
CONTACT TEXT NOT NULL, \
EMAIL TEXT NOT NULL \
)")
print "...done."
def process_file(self, f):
"""Process an individual .adopt file and add it to the database."""
config = ConfigParser.ConfigParser()
config.read(f.strip())
status = config.get('Project', 'maintained')
if status == "no":
name = config.get('Project', 'name')
description = config.get('Project', 'description')
category = config.get('Project', 'category')
repo = config.get('Project', 'repo')
discussion = config.get('Project', 'discussion')
languages = config.get('Project', 'languages')
contact = config.get('Contact', 'name')
email = config.get('Contact', 'email')
query = "INSERT INTO projects(ID, NAME, DESCRIPTION, CATEGORY, REPO, DISCUSSION, LANGUAGES, CONTACT, EMAIL) VALUES(" \
+ str(self.fileid) + ", " \
+ "'" + name + "', " \
+ "'" + description + "', " \
+ "'" + category + "', " \
+ "'" + repo + "', " \
+ "'" + discussion + "', " \
+ "'" + languages + "', " \
+ "'" + contact + "', " \
+ "'" + email + "')"
self.db.execute(query)
self.db.commit()
return True
else:
return False
if __name__ == '__main__':
a = Adopt(sys.argv)