aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Ochotnicky <sochotnicky@gmail.com>2009-07-16 16:21:18 +0200
committerStanislav Ochotnicky <sochotnicky@gmail.com>2009-07-17 10:58:00 +0200
commita34fd0e6ea73cdded7773ec49e27444629bb846c (patch)
tree2e7cbb18490dba4fbfde4c4d56a845c4c126b3be
parentAdded README and INSTALL (diff)
downloadcollagen-a34fd0e6ea73cdded7773ec49e27444629bb846c.tar.gz
collagen-a34fd0e6ea73cdded7773ec49e27444629bb846c.tar.bz2
collagen-a34fd0e6ea73cdded7773ec49e27444629bb846c.zip
Added random selection of package to compile
-rw-r--r--src/matchbox/__init__.py32
-rw-r--r--src/tinderbox/__init__.py13
2 files changed, 43 insertions, 2 deletions
diff --git a/src/matchbox/__init__.py b/src/matchbox/__init__.py
index 7ca0b53..f55fd91 100644
--- a/src/matchbox/__init__.py
+++ b/src/matchbox/__init__.py
@@ -3,7 +3,12 @@ import thread
import protocol
import pickle
import StringIO
+import os
+import portage
+import random
+import db
+from db import DjangoDB
class MatchboxServer(object):
@@ -11,6 +16,8 @@ class MatchboxServer(object):
self.host = host
self.port = port
self.sock = None
+ self.db = DjangoDB()
+ self.portsettings = portage.config(clone=portage.settings)
def start_server(self):
try:
@@ -52,7 +59,8 @@ class MatchboxServer(object):
if type(command) is protocol.GetNextPackage:
print "returning next package to compile"
# TODO get real package from database with missing info
- repl = protocol.GetNextPackageReply('games-misc/fortune-mod-cs','1.6.9','-unicode')
+ repl = protocol.GetNextPackageReply(self._get_next_package(),None,None)
+
client_socket.sendall(pickle.dumps(repl))
elif type(command) is protocol.AddPackageInfo:
for pi in command.package_infos:
@@ -62,9 +70,10 @@ class MatchboxServer(object):
print pi.use_flags
print pi.emerge_info
print pi.attachments
-
+
print len(pi.content)
print pi.content.keys()
+
# TODO
else:
print "unknown command: %s" % command
@@ -73,5 +82,24 @@ class MatchboxServer(object):
print "closing client connection"
client_socket.close()
+ def _get_next_package(self):
+ categories = os.listdir(self.portsettings["PORTDIR"])
+ cat_ind = random.randint(0,len(categories)-1)
+ selcat = categories[cat_ind]
+ checkdir = "%s/%s" % (self.portsettings["PORTDIR"], selcat)
+ if not os.path.isdir(checkdir):
+ return self._get_next_package()
+
+
+ packages = os.listdir(checkdir)
+ pkg_ind = random.randint(0,len(packages)-1)
+ selpkg = packages[pkg_ind]
+
+ checkdir = "%s/%s/%s" % (self.portsettings["PORTDIR"], selcat, selpkg)
+ if not os.path.isdir(checkdir):
+ return self._get_next_package()
+
+ return "%s/%s" % (selcat,selpkg)
+
diff --git a/src/tinderbox/__init__.py b/src/tinderbox/__init__.py
index 863a848..a64f88e 100644
--- a/src/tinderbox/__init__.py
+++ b/src/tinderbox/__init__.py
@@ -106,6 +106,7 @@ class Tinderbox(object):
# setup logging!
os.chroot(config.WORK_CHROOT)
init_logging()
+ package.version = "-".join(portage.pkgsplit(pkg)[1:])
self._emerge_package_subprocess(pkg, ebuild, dep_groups, package)
sys.exit(0)
@@ -233,6 +234,18 @@ class Tinderbox(object):
self._save_info('package_infos', package_infos)
+ def _add_attachment(self, pkg, path):
+ try:
+ attfile = open(path,"r")
+ except IOError, (errno, strerror):
+ print "Unable to read file %s: %d: %s" % (path, errno, strerror)
+ log.warning("Unable to read file (%s) %d: %s" % (path, errno, strerror))
+ pkg.attachments[os.path.basename(path)] = "Unable to read file %s" % path
+ else:
+ pkg.attachments[os.path.basename(path)] = attfile.read()
+ attfile.close()
+ del attfile
+
def _save_info(self, key, data):
"""
Save data inside CHROOT_LOGS directory, under name 'key'. This