Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 172 lines (141 sloc) 5.544 kb
4ee93f6 @dom96 first commit
dom96 authored
1 # This module is used by the website.
fabb994 @dom96 The website now displays some information from the database; still a lot...
dom96 authored
2 import redis, times, strutils
4ee93f6 @dom96 first commit
dom96 authored
3 from sockets import TPort
4
5 type
6 TDb* = object
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
7 r*: TRedis
4ee93f6 @dom96 first commit
dom96 authored
8 lastPing: float
9
10 TBuildResult* = enum
4ab308c @dom96 Designed the basic look for the website, with the help of html5boilerpla...
dom96 authored
11 bUnknown, bFail, bSuccess
4ee93f6 @dom96 first commit
dom96 authored
12
13 TTestResult* = enum
4ab308c @dom96 Designed the basic look for the website, with the help of html5boilerpla...
dom96 authored
14 tUnknown, tFail, tSuccess
4ee93f6 @dom96 first commit
dom96 authored
15
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
16 TEntry* = tuple[c: TCommit, p: seq[TPlatform]]
fabb994 @dom96 The website now displays some information from the database; still a lot...
dom96 authored
17
473143b @dom96 Created a new module called 'builder' and removed the build code from 'g...
dom96 authored
18 TCommit* = object
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
19 commitMsg*, username*, hash*: string
20 date*: TTime
21
22 TPlatform* = object
473143b @dom96 Created a new module called 'builder' and removed the build code from 'g...
dom96 authored
23 buildResult*: TBuildResult
24 testResult*: TTestResult
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
25 failReason*, platform*: string
4ab308c @dom96 Designed the basic look for the website, with the help of html5boilerpla...
dom96 authored
26 total*, passed*, skipped*, failed*: biggestInt
03e7589 @dom96 Added C sources generation.
dom96 authored
27 csources*: bool
473143b @dom96 Created a new module called 'builder' and removed the build code from 'g...
dom96 authored
28
4ee93f6 @dom96 first commit
dom96 authored
29 const
30 listName = "commits"
31 failOnExisting = False
32
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
33 proc open*(host = "localhost", port: TPort): TDb =
4ee93f6 @dom96 first commit
dom96 authored
34 result.r = redis.open(host, port)
35 result.lastPing = epochTime()
36
37 proc customHSet(database: TDb, name, field, value: string) =
38 if database.r.hSet(name, field, value).int == 0:
39 if failOnExisting:
40 assert(false)
41 else:
42 echo("[Warning:REDIS] ", field, " already exists in ", name)
43
4ab308c @dom96 Designed the basic look for the website, with the help of html5boilerpla...
dom96 authored
44 proc updateProperty*(database: TDb, commitHash, platform, property,
45 value: string) =
46 var name = platform & ":" & commitHash
47 if database.r.hSet(name, property, value).int == 0:
48 echo("[INFO:REDIS] '$1' field updated in hash" % [property])
49 else:
50 echo("[INFO:REDIS] '$1' new field added to hash" % [property])
51
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
52 proc globalProperty*(database: TDb, commitHash, property, value: string) =
53 if database.r.hSet(commitHash, property, value).int == 0:
54 echo("[INFO:REDIS] '$1' field updated in hash" % [property])
55 else:
56 echo("[INFO:REDIS] '$1' new field added to hash" % [property])
57
58 proc addCommit*(database: TDb, commitHash, commitMsg, user: string) =
fabb994 @dom96 The website now displays some information from the database; still a lot...
dom96 authored
59 # Add the commit hash to the `commits` list.
4ee93f6 @dom96 first commit
dom96 authored
60 discard database.r.lPush(listName, commitHash)
9eccfbf @dom96 Added sexy github-inspired download buttons. More information is now sav...
dom96 authored
61 # Add the commit message, current date and username as a property
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
62 globalProperty(database, commitHash, "commitMsg", commitMsg)
63 globalProperty(database, commitHash, "date", $int(getTime()))
64 globalProperty(database, commitHash, "username", user)
4ee93f6 @dom96 first commit
dom96 authored
65
66 proc keepAlive*(database: var TDb) =
67 ## Keep the connection alive. Ping redis in this case. This functions does
68 ## not guarantee that redis will be pinged.
69 var t = epochTime()
70 if t - database.lastPing >= 60.0:
71 echo("PING -> redis")
fabb994 @dom96 The website now displays some information from the database; still a lot...
dom96 authored
72 assert(database.r.ping() == "PONG")
4ee93f6 @dom96 first commit
dom96 authored
73 database.lastPing = t
473143b @dom96 Created a new module called 'builder' and removed the build code from 'g...
dom96 authored
74
fabb994 @dom96 The website now displays some information from the database; still a lot...
dom96 authored
75 proc getCommits*(database: TDb,
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
76 plStr: var seq[string]): seq[TEntry] =
fabb994 @dom96 The website now displays some information from the database; still a lot...
dom96 authored
77 result = @[]
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
78 var commitsRaw = database.r.lrange("commits", 0, -1)
79 for c in items(commitsRaw):
80 var commit: TCommit
81 commit.hash = c
82 for key, value in database.r.hPairs(c):
83 case normalize(key)
84 of "commitmsg": commit.commitMsg = value
85 of "date": commit.date = TTime(parseInt(value))
86 of "username": commit.username = value
87 else:
88 echo(key)
89 assert(false)
90
fabb994 @dom96 The website now displays some information from the database; still a lot...
dom96 authored
91 var platformsRaw = database.r.lrange(c & ":platforms", 0, -1)
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
92 var platforms: seq[TPlatform] = @[]
fabb994 @dom96 The website now displays some information from the database; still a lot...
dom96 authored
93 for p in items(platformsRaw):
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
94 var platform: TPlatform
0e6b32c @dom96 Added doc gen. Changed some css styles a bit.
dom96 authored
95 for key, value in database.r.hPairs(p & ":" & c):
4ab308c @dom96 Designed the basic look for the website, with the help of html5boilerpla...
dom96 authored
96 case normalize(key)
97 of "buildresult":
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
98 platform.buildResult = parseInt(value).TBuildResult
4ab308c @dom96 Designed the basic look for the website, with the help of html5boilerpla...
dom96 authored
99 of "testresult":
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
100 platform.testResult = parseInt(value).TTestResult
4ab308c @dom96 Designed the basic look for the website, with the help of html5boilerpla...
dom96 authored
101 of "failreason":
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
102 platform.failReason = value
4ab308c @dom96 Designed the basic look for the website, with the help of html5boilerpla...
dom96 authored
103 of "total":
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
104 platform.total = parseBiggestInt(value)
4ab308c @dom96 Designed the basic look for the website, with the help of html5boilerpla...
dom96 authored
105 of "passed":
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
106 platform.passed = parseBiggestInt(value)
4ab308c @dom96 Designed the basic look for the website, with the help of html5boilerpla...
dom96 authored
107 of "skipped":
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
108 platform.skipped = parseBiggestInt(value)
4ab308c @dom96 Designed the basic look for the website, with the help of html5boilerpla...
dom96 authored
109 of "failed":
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
110 platform.failed = parseBiggestInt(value)
03e7589 @dom96 Added C sources generation.
dom96 authored
111 of "csources":
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
112 platform.csources = if value == "t": true else: false
fabb994 @dom96 The website now displays some information from the database; still a lot...
dom96 authored
113 else:
4ab308c @dom96 Designed the basic look for the website, with the help of html5boilerpla...
dom96 authored
114 echo(normalize(key))
fabb994 @dom96 The website now displays some information from the database; still a lot...
dom96 authored
115 assert(false)
116
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
117 platform.platform = p
aa53e78 @dom96 The builder now properly reads the output from the processes. Commit spe...
dom96 authored
118
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
119 platforms.add(platform)
120 if p notin plStr:
121 plStr.add(p)
122 result.add((commit, platforms))
473143b @dom96 Created a new module called 'builder' and removed the build code from 'g...
dom96 authored
123
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
124 proc commitExists*(database: TDb, commit: string, starts = false): bool =
5cde499 @dom96 The website now checks the database whether a commit already has been bu...
dom96 authored
125 # TODO: Consider making the 'commits' list a set.
126 for c in items(database.r.lrange("commits", 0, -1)):
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
127 if starts:
128 if c.startsWith(commit): return true
129 else:
130 if c == commit: return true
5cde499 @dom96 The website now checks the database whether a commit already has been bu...
dom96 authored
131 return false
132
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
133 proc platformExists*(database: TDb, commit: string, platform: string): bool =
134 for p in items(database.r.lrange(commit & ":" & "platforms", 0, -1)):
135 if p == platform: return true
136
137 proc expandHash*(database: TDb, commit: string): string =
138 for c in items(database.r.lrange("commits", 0, -1)):
139 if c.startsWith(commit): return c
140 assert false
141
142 proc isNewest*(database: TDb, commit: string): bool =
143 return database.r.lIndex("commits", 0) == commit
144
145 proc getNewest*(database: TDb): string =
146 return database.r.lIndex("commits", 0)
147
148 proc addPlatform*(database: TDb, commit: string, platform: string) =
149 assert database.commitExists(commit)
150 assert (not database.platformExists(commit, platform))
151 var name = platform & ":" & commit
152 if database.r.exists(name):
153 if failOnExisting: quit("[FAIL] " & name & " already exists!", 1)
154 else: echo("[Warning] " & name & " already exists!")
155
156 discard database.r.lPush(commit & ":" & "platforms", platform)
157
158 proc `[]`*(p: seq[TPlatform], name: string): TPlatform =
159 for platform in items(p):
160 if platform.platform == name:
161 return platform
162 raise newException(EInvalidValue, name & " platforms not found in commits.")
fabb994 @dom96 The website now displays some information from the database; still a lot...
dom96 authored
163
bc9a8ed @dom96 A lot of changes. Database layout changed, the way commits are stored on...
dom96 authored
164 proc contains*(p: seq[TPlatform], s: string): bool =
165 for i in items(p):
166 if i.platform == s:
5e9a6e6 @dom96 Fixed CSS path issue when requesting the website without a leading slash...
dom96 authored
167 return True
fabb994 @dom96 The website now displays some information from the database; still a lot...
dom96 authored
168
169
473143b @dom96 Created a new module called 'builder' and removed the build code from 'g...
dom96 authored
170
171
Something went wrong with that request. Please try again.