]>
git.ipfire.org Git - people/jschlag/pbs.git/blob - src/buildservice/sources.py
13 class Sources(base
.Object
):
15 sources
= self
.db
.query("SELECT id FROM sources ORDER BY id")
17 return [Source(self
.pakfire
, s
.id) for s
in sources
]
19 def get_by_id(self
, id):
20 return Source(self
.pakfire
, id)
22 def get_by_distro(self
, distro
):
23 sources
= self
.db
.query("SELECT id FROM sources WHERE distro_id = %s", distro
.id)
25 return [Source(self
.pakfire
, s
.id) for s
in sources
]
27 def update_revision(self
, source_id
, revision
):
28 query
= "UPDATE sources SET revision = %s WHERE id = %s"
30 return self
.db
.execute(query
, revision
, source_id
)
32 def get_pending_commits(self
, limit
=None):
33 query
= "SELECT id FROM sources_commits WHERE state = 'pending' ORDER BY id ASC"
40 rows
= self
.db
.query(query
, *args
)
44 commit
= Commit(self
.pakfire
, row
.id)
45 commits
.append(commit
)
49 def get_commit_by_id(self
, commit_id
):
50 commit
= self
.db
.get("SELECT id FROM sources_commits WHERE id = %s", commit_id
)
53 return Commit(self
.pakfire
, commit
.id)
56 class Commit(base
.Object
):
57 def __init__(self
, pakfire
, id):
58 base
.Object
.__init
__(self
, pakfire
)
68 def create(cls
, pakfire
, source
, revision
, author
, committer
, subject
, body
, date
):
70 id = pakfire
.db
.execute("INSERT INTO sources_commits(source_id, revision, \
71 author, committer, subject, body, date) VALUES(%s, %s, %s, %s, %s, %s, %s)",
72 source
.id, revision
, author
, committer
, subject
, body
, date
)
73 except database
.IntegrityError
:
74 # If the commit (apperently) already existed, we return nothing.
77 return cls(pakfire
, id)
81 if self
._data
is None:
82 data
= self
.db
.get("SELECT * FROM sources_commits WHERE id = %s", self
.id)
91 return self
.data
.revision
95 return self
.data
.source_id
99 if self
._source
is None:
100 self
._source
= Source(self
.pakfire
, self
.source_id
)
107 A shortcut to the distribution this commit
110 return self
.source
.distro
113 return self
.data
.state
115 def set_state(self
, state
):
116 self
.db
.execute("UPDATE sources_commits SET state = %s WHERE id = %s",
120 self
._data
["state"] = state
122 state
= property(get_state
, set_state
)
126 return self
.data
.author
130 return self
.data
.committer
134 return self
.data
.subject
.strip()
138 return self
.data
.body
.strip()
141 def message_full(self
):
142 msg
= [self
.subject
, ""] + self
.message
.splitlines()
144 return "\n".join(msg
)
148 return self
.data
.date
152 if self
._packages
is None:
155 for pkg
in self
.db
.query("SELECT id FROM packages WHERE commit_id = %s", self
.id):
156 pkg
= packages
.Package(self
.pakfire
, pkg
.id)
157 self
._packages
.append(pkg
)
159 self
._packages
.sort()
161 return self
._packages
165 Removes all packages that have been created by this commit and
166 resets the state so it will be processed again.
168 # Remove all packages and corresponding builds.
169 for pkg
in self
.packages
:
170 # Check if there is a build associated with the package.
171 # If so, the whole build will be deleted.
176 # Delete the package.
180 self
._packages
= None
182 # Reset the state to 'pending'.
183 self
.state
= "pending"
186 class Source(base
.Object
):
187 def __init__(self
, pakfire
, id):
188 base
.Object
.__init
__(self
, pakfire
)
193 self
._head
_revision
= None
197 if self
._data
is None:
198 data
= self
.db
.get("SELECT * FROM sources WHERE id = %s", self
.id)
205 def __cmp__(self
, other
):
206 return cmp(self
.id, other
.id)
215 "targetpath" : self
.targetpath
,
216 "revision" : self
.revision
,
217 "branch" : self
.branch
,
220 def _import_revision(self
, revision
):
221 logging
.debug("Going to import revision: %s" % revision
)
223 rev_author
= self
._git
("log -1 --format=\"%%an <%%ae>\" %s" % revision
)
224 rev_committer
= self
._git
("log -1 --format=\"%%cn <%%ce>\" %s" % revision
)
225 rev_subject
= self
._git
("log -1 --format=\"%%s\" %s" % revision
)
226 rev_body
= self
._git
("log -1 --format=\"%%b\" %s" % revision
)
227 rev_date
= self
._git
("log -1 --format=\"%%at\" %s" % revision
)
228 rev_date
= datetime
.datetime
.utcfromtimestamp(float(rev_date
))
230 # Convert strings properly. No idea why I have to do that.
231 rev_author
= rev_author
.decode("latin-1").strip()
232 rev_committer
= rev_committer
.decode("latin-1").strip()
233 rev_subject
= rev_subject
.decode("latin-1").strip()
234 rev_body
= rev_body
.decode("latin-1").rstrip()
236 # Create a new source build object.
237 build
.SourceBuild
.new(self
.pakfire
, self
.id, revision
, rev_author
,
238 rev_committer
, rev_subject
, rev_body
, rev_date
)
242 return self
.data
.name
245 def identifier(self
):
246 return self
.data
.identifier
254 return self
.data
.gitweb
258 return self
.data
.revision
262 return self
.data
.branch
266 return self
.pakfire
.builds
.get_by_source(self
.id)
270 return self
.pakfire
.distros
.get_by_id(self
.data
.distro_id
)
273 def start_revision(self
):
274 return self
.data
.revision
277 def head_revision(self
):
278 if self
._head
_revision
is None:
279 commit
= self
.db
.get("SELECT id FROM sources_commits \
280 WHERE source_id = %s ORDER BY id DESC LIMIT 1", self
.id)
283 self
._head
_revision
= Commit(self
.pakfire
, commit
.id)
285 return self
._head
_revision
288 def num_commits(self
):
289 ret
= self
.db
.get("SELECT COUNT(*) AS num FROM sources_commits \
290 WHERE source_id = %s", self
.id)
294 def get_commits(self
, limit
=None, offset
=None):
295 query
= "SELECT id FROM sources_commits WHERE source_id = %s \
301 query
+= " LIMIT %s,%s"
302 args
+= [offset
, limit
]
308 for commit
in self
.db
.query(query
, *args
):
309 commit
= Commit(self
.pakfire
, commit
.id)
310 commits
.append(commit
)
314 def get_commit(self
, revision
):
315 commit
= self
.db
.get("SELECT id FROM sources_commits WHERE source_id = %s \
316 AND revision = %s LIMIT 1", self
.id, revision
)
321 commit
= Commit(self
.pakfire
, commit
.id)
322 commit
._source
= self