]>
git.ipfire.org Git - people/jschlag/pbs.git/blob - src/buildservice/sources.py
e028478a3e864b254edac357e374f8c6be4bdde2
12 from .decorators
import *
14 class Sources(base
.Object
):
15 def _get_source(self
, query
, *args
):
16 res
= self
.db
.get(query
, *args
)
19 return Source(self
.backend
, res
.id, data
=res
)
21 def _get_sources(self
, query
, *args
):
22 res
= self
.db
.query(query
, *args
)
25 yield Source(self
.backend
, row
.id, data
=row
)
27 def _get_commit(self
, query
, *args
):
28 res
= self
.db
.get(query
, *args
)
31 return Commit(self
.backend
, res
.id, data
=res
)
33 def _get_commits(self
, query
, *args
):
34 res
= self
.db
.query(query
, *args
)
37 yield Commit(self
.backend
, row
.id, data
=row
)
40 return self
._get
_sources
("SELECT * FROM sources")
42 def get_by_id(self
, id):
43 return self
._get
_source
("SELECT * FROM sources \
46 def get_by_distro(self
, distro
):
47 return self
._get
_sources
("SELECT * FROM sources \
48 WHERE distro_id = %s", distro
.id)
50 def update_revision(self
, source_id
, revision
):
51 query
= "UPDATE sources SET revision = %s WHERE id = %s"
53 return self
.db
.execute(query
, revision
, source_id
)
55 def get_pending_commits(self
, limit
=None):
56 query
= "SELECT id FROM sources_commits WHERE state = 'pending' ORDER BY id ASC"
63 rows
= self
.db
.query(query
, *args
)
67 commit
= Commit(self
.pakfire
, row
.id)
68 commits
.append(commit
)
72 def get_commit_by_id(self
, commit_id
):
73 commit
= self
.db
.get("SELECT id FROM sources_commits WHERE id = %s", commit_id
)
76 return Commit(self
.pakfire
, commit
.id)
80 repo
= git
.Repo(self
.backend
, source
, mode
="mirror")
82 # If the repository is not yet cloned, we need to make a local
87 # Otherwise we just fetch updates.
91 # Import all new revisions.
92 repo
.import_revisions()
95 class Commit(base
.DataObject
):
96 table
= "sources_commits"
100 return self
.data
.revision
104 return self
.backend
.sources
.get_by_id(self
.data
.source_id
)
109 A shortcut to the distribution this commit
112 return self
.source
.distro
114 def set_state(self
, state
):
115 self
._set
_attribute
("state", state
)
117 state
= property(lambda s
: s
.data
.state
, set_state
)
121 return self
.data
.author
125 return self
.data
.committer
129 return self
.data
.subject
.strip()
133 return self
.data
.body
.strip()
136 def message_full(self
):
137 msg
= [self
.subject
, ""] + self
.message
.splitlines()
139 return "\n".join(msg
)
143 return self
.data
.date
147 return self
.backend
.packages
._get
_packages
("SELECT * FROM packages \
148 WHERE commit_id = %s", self
.id)
152 Removes all packages that have been created by this commit and
153 resets the state so it will be processed again.
155 # Remove all packages and corresponding builds.
156 for pkg
in self
.packages
:
157 # Check if there is a build associated with the package.
158 # If so, the whole build will be deleted.
163 # Delete the package.
169 # Reset the state to 'pending'.
170 self
.state
= "pending"
173 class Source(base
.DataObject
):
176 def __eq__(self
, other
):
177 return self
.id == other
.id
180 ret
= self
.db
.get("SELECT COUNT(*) AS len FROM sources_commits \
181 WHERE source_id = %s", self
.id)
185 def create_commit(self
, revision
, author
, committer
, subject
, body
, date
):
186 commit
= self
.backend
.sources
._get
_commit
("INSERT INTO sources_commits(source_id, \
187 revision, author, committer, subject, body, date) VALUES(%s, %s, %s, %s, %s, %s, %s)",
188 self
.id, revision
, author
, committer
, subject
, body
, date
)
202 "targetpath" : self
.targetpath
,
203 "revision" : self
.revision
,
204 "branch" : self
.branch
,
209 return self
.data
.name
212 def identifier(self
):
213 return self
.data
.identifier
221 return self
.data
.gitweb
225 return self
.data
.revision
229 return self
.data
.branch
233 return self
.pakfire
.builds
.get_by_source(self
.id)
237 return self
.pakfire
.distros
.get_by_id(self
.data
.distro_id
)
240 def start_revision(self
):
241 return self
.data
.revision
244 def head_revision(self
):
245 return self
.backend
.sources
._get
_commit
("SELECT * FROM sources_commits \
246 WHERE source_id = %s ORDER BY id DESC LIMIT 1", self
.id)
248 def get_commits(self
, limit
=None, offset
=None):
249 return self
.backend
.sources
._get
_commits
("SELECT * FROM sources_commits \
250 WHERE source_id = %s ORDER BY id DESC LIMIT %s OFFSET %s", limit
, offset
)
252 def get_commit(self
, revision
):
253 commit
= self
.backend
.sources
._get
_commit
("SELECT * FROM sources_commits \
254 WHERE source_id = %s AND revision = %s", self
.id, revision
)