]>
git.ipfire.org Git - people/ms/pakfire.git/blob - pakfire/server/master.py
13 import pakfire
.packages
as packages
14 import pakfire
.repository
as repository
15 import pakfire
.util
as util
16 from pakfire
.constants
import *
19 def __init__(self
, master
, id, name
, path
, targetpath
, revision
, branch
):
24 self
.targetpath
= targetpath
25 self
.revision
= revision
30 return self
.master
.pakfire
33 cmd
= "cd %s; git %s" % (self
.path
, cmd
)
35 logging
.debug("Running command: %s" % cmd
)
37 return subprocess
.check_output(["/bin/sh", "-c", cmd
])
39 def _git_rev_list(self
, revision
=None):
41 revision
= self
.revision
43 command
= "rev-list %s..origin/%s" % (revision
, self
.branch
)
45 # Get all normal commits.
46 commits
= self
._git
("%s --no-merges" % command
)
47 commits
= commits
.splitlines()
50 for commit
in self
._git
(command
).splitlines():
51 # Check if commit is a normal commit or merge commit.
52 merge
= not commit
in commits
54 revisions
.append((commit
, merge
))
56 return reversed(revisions
)
58 def _git_changed_files(self
, revision1
, revision2
=""):
59 files
= self
._git
("diff --name-only %s %s" % (revision1
, revision2
))
61 return [os
.path
.join(self
.path
, f
) for f
in files
.splitlines()]
63 def _git_checkout_revision(self
, revision
):
64 self
._git
("checkout %s" % revision
)
66 def update_revision(self
, (revision
, merge
)):
68 self
._git
_checkout
_revision
(revision
)
70 # Get list of all changes files between the current revision and
72 files
= self
._git
_changed
_files
("HEAD^", "HEAD")
74 self
.update_files([f
for f
in files
if f
.endswith(".%s" % MAKEFILE_EXTENSION
)])
76 # Send update to the server.
77 self
.master
.update_revision(self
, revision
)
79 def update_files(self
, files
):
80 rnd
= random
.randint(0, 1024**2)
81 tmpdir
= "/tmp/pakfire-source-%s" % rnd
85 if os
.path
.exists(file):
88 pkg_name
= os
.path
.basename(os
.path
.dirname(file))
90 # Send deleted package to server.
91 self
.master
.package_remove(self
, pkg_name
)
96 # XXX This totally ignores the local configuration.
98 pakfire
.dist(pkg
, resultdirs
=[tmpdir
,])
100 # Create a kind of dummy repository to link the packages against it.
101 repo
= repository
.LocalSourceRepository(self
.pakfire
,
102 "source-%s" % rnd
, "Source packages", tmpdir
, idx
="directory")
103 repo
.update(force
=True)
105 for pkg
in repo
.get_all():
106 logging
.debug("Processing package: %s" % pkg
)
108 pkg_path
= "%(name)s/%(epoch)s-%(version)s-%(release)s/%(arch)s" % pkg
.info
110 file = os
.path
.join(self
.targetpath
, pkg_path
, os
.path
.basename(pkg
.filename
))
111 dir = os
.path
.dirname(file)
115 if os
.path
.exists(file):
116 logging
.warning("Package does already exist: %s" % file)
119 if not os
.path
.exists(dir):
122 # Copy the source file to the designated data pool.
123 shutil
.copy2(pkg
.filename
, file)
125 # Register package in database and get an ID.
126 pkg_id
= self
.master
.package_add(self
, pkg
)
128 # Re-read the package metadata (mainly update filenames).
129 pkg
= packages
.SourcePackage(self
.pakfire
, repo
, file)
131 self
.master
.package_file_add(self
, pkg_id
, pkg
)
136 # Update files from server.
139 # If there has been no data, yet we need to import all packages
140 # that are currently checked out.
141 if not self
.revision
:
144 for rev
in self
._git
_rev
_list
():
145 self
.update_revision(rev
)
147 def update_all(self
):
149 for dir, subdirs
, files
in os
.walk(self
.path
):
151 if not f
.endswith(".%s" % MAKEFILE_EXTENSION
):
154 _files
.append(os
.path
.join(dir, f
))
156 self
.update_files(_files
)
159 class Master(object):
160 def __init__(self
, **pakfire_args
):
161 self
.pakfire
= pakfire
.base
.Pakfire(**pakfire_args
)
163 server
= self
.pakfire
.config
._master
.get("server")
165 logging
.info("Establishing RPC connection to: %s" % server
)
167 self
.conn
= xmlrpclib
.Server(server
)
169 def update_sources(self
):
170 sources
= self
.conn
.sources_get_all()
172 for source
in sources
:
173 source
= Source(self
, **source
)
177 def update_revision(self
, source
, revision
):
178 self
.conn
.sources_update_revision(source
.id, revision
)
180 def package_add(self
, source
, pkg
):
181 logging
.info("Adding package: %s" % pkg
.friendly_name
)
183 # Collect data that is sent to the database...
187 "version" : pkg
.version
,
188 "release" : pkg
.release
,
189 "groups" : " ".join(pkg
.groups
),
190 "maintainer" : pkg
.maintainer
,
191 "license" : pkg
.license
,
193 "summary" : pkg
.summary
,
194 "description" : pkg
.description
,
195 "supported_arches" : pkg
.supported_arches
,
196 "source_id" : source
.id,
199 return self
.conn
.package_add(info
)
201 def package_file_add(self
, source
, pkg_id
, pkg
):
202 logging
.info("Adding package file: %s" % pkg
.filename
)
205 "path" : pkg
.filename
[len(source
.path
) + 1:],
206 "source_id" : source
.id,
209 "summary" : pkg
.summary
,
210 "description" : pkg
.description
,
211 "requires" : " ".join(pkg
.requires
),
216 "license" : pkg
.license
,
217 "maintainer" : pkg
.maintainer
,
220 "build_host" : pkg
.build_host
,
221 "build_id" : pkg
.build_id
,
222 "build_time" : pkg
.build_time
,
226 if isinstance(pkg
, packages
.BinaryPackage
):
228 "provides" : " ".join(pkg
.provides
),
229 "obsoletes" : " ".join(pkg
.obsoletes
),
230 "conflicts" : " ".join(pkg
.conflicts
),
233 return self
.conn
.package_file_add(pkg_id
, info
)
235 def package_remove(self
, source
, pkg
):
236 logging
.info("Package '%s' has been removed." % pkg
)