2011-05-27 06:31:45 +00:00
|
|
|
import os,sys,logging
|
2012-01-10 06:13:50 +00:00
|
|
|
import signal, time, atexit, threading
|
2011-05-27 06:31:45 +00:00
|
|
|
from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
|
2012-01-15 21:03:53 +00:00
|
|
|
import xmlrpclib
|
|
|
|
|
|
|
|
try:
|
|
|
|
import sqlite3
|
|
|
|
except ImportError:
|
|
|
|
from pysqlite2 import dbapi2 as sqlite3
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
import bb.server.xmlrpc
|
|
|
|
import prserv
|
|
|
|
import prserv.db
|
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
logger = logging.getLogger("BitBake.PRserv")
|
|
|
|
|
2011-05-27 06:31:45 +00:00
|
|
|
if sys.hexversion < 0x020600F0:
|
|
|
|
print("Sorry, python 2.6 or later is required.")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
class Handler(SimpleXMLRPCRequestHandler):
|
|
|
|
def _dispatch(self,method,params):
|
|
|
|
try:
|
|
|
|
value=self.server.funcs[method](*params)
|
|
|
|
except:
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
raise
|
|
|
|
return value
|
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
PIDPREFIX = "/tmp/PRServer_%s_%s.pid"
|
2012-01-10 06:13:50 +00:00
|
|
|
singleton = None
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
|
2011-05-27 06:31:45 +00:00
|
|
|
class PRServer(SimpleXMLRPCServer):
|
|
|
|
def __init__(self, dbfile, logfile, interface, daemon=True):
|
|
|
|
''' constructor '''
|
|
|
|
SimpleXMLRPCServer.__init__(self, interface,
|
|
|
|
requestHandler=SimpleXMLRPCRequestHandler,
|
|
|
|
logRequests=False, allow_none=True)
|
|
|
|
self.dbfile=dbfile
|
|
|
|
self.daemon=daemon
|
|
|
|
self.logfile=logfile
|
2012-01-10 06:13:50 +00:00
|
|
|
self.working_thread=None
|
2011-05-27 06:31:45 +00:00
|
|
|
self.host, self.port = self.socket.getsockname()
|
|
|
|
self.db=prserv.db.PRData(dbfile)
|
|
|
|
self.table=self.db["PRMAIN"]
|
2012-01-10 06:13:50 +00:00
|
|
|
self.pidfile=PIDPREFIX % (self.host, self.port)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
self.register_function(self.getPR, "getPR")
|
|
|
|
self.register_function(self.quit, "quit")
|
|
|
|
self.register_function(self.ping, "ping")
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
self.register_function(self.export, "export")
|
|
|
|
self.register_function(self.importone, "importone")
|
2011-05-27 06:31:45 +00:00
|
|
|
self.register_introspection_functions()
|
2012-01-10 06:13:50 +00:00
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def export(self, version=None, pkgarch=None, checksum=None, colinfo=True):
|
|
|
|
try:
|
|
|
|
return self.table.export(version, pkgarch, checksum, colinfo)
|
|
|
|
except sqlite3.Error as exc:
|
2012-01-10 06:13:50 +00:00
|
|
|
logger.error(str(exc))
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
def importone(self, version, pkgarch, checksum, value):
|
|
|
|
return self.table.importone(version, pkgarch, checksum, value)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
def ping(self):
|
|
|
|
return not self.quit
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
def getinfo(self):
|
|
|
|
return (self.host, self.port)
|
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def getPR(self, version, pkgarch, checksum):
|
2011-05-27 06:31:45 +00:00
|
|
|
try:
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
return self.table.getValue(version, pkgarch, checksum)
|
2011-05-27 06:31:45 +00:00
|
|
|
except prserv.NotFoundError:
|
2012-01-10 06:13:50 +00:00
|
|
|
logger.error("can not find value for (%s, %s)",version, checksum)
|
2011-05-27 06:31:45 +00:00
|
|
|
return None
|
|
|
|
except sqlite3.Error as exc:
|
2012-01-10 06:13:50 +00:00
|
|
|
logger.error(str(exc))
|
2011-05-27 06:31:45 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
def quit(self):
|
|
|
|
self.quit=True
|
|
|
|
return
|
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
def work_forever(self,):
|
2011-05-27 06:31:45 +00:00
|
|
|
self.quit = False
|
|
|
|
self.timeout = 0.5
|
2013-02-06 23:18:19 +00:00
|
|
|
|
|
|
|
logger.info("Started PRServer with DBfile: %s, IP: %s, PORT: %s, PID: %s" %
|
2012-01-10 06:13:50 +00:00
|
|
|
(self.dbfile, self.host, self.port, str(os.getpid())))
|
|
|
|
|
2011-05-27 06:31:45 +00:00
|
|
|
while not self.quit:
|
|
|
|
self.handle_request()
|
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
logger.info("PRServer: stopping...")
|
2011-05-27 06:31:45 +00:00
|
|
|
self.server_close()
|
|
|
|
return
|
|
|
|
|
|
|
|
def start(self):
|
2013-02-06 23:18:19 +00:00
|
|
|
pid = self.daemonize()
|
|
|
|
# Ensure both the parent sees this and the child from the work_forever log entry above
|
|
|
|
logger.info("Started PRServer with DBfile: %s, IP: %s, PORT: %s, PID: %s" %
|
|
|
|
(self.dbfile, self.host, self.port, str(pid)))
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
def delpid(self):
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
os.remove(self.pidfile)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
def daemonize(self):
|
|
|
|
"""
|
|
|
|
See Advanced Programming in the UNIX, Sec 13.3
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
pid = os.fork()
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
if pid > 0:
|
2013-02-06 15:59:07 +00:00
|
|
|
os.waitpid(pid, 0)
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
#parent return instead of exit to give control
|
2013-02-06 23:18:19 +00:00
|
|
|
return pid
|
2011-06-14 23:44:58 +00:00
|
|
|
except OSError as e:
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
raise Exception("%s [%d]" % (e.strerror, e.errno))
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
os.setsid()
|
|
|
|
"""
|
|
|
|
fork again to make sure the daemon is not session leader,
|
|
|
|
which prevents it from acquiring controlling terminal
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
pid = os.fork()
|
|
|
|
if pid > 0: #parent
|
2013-02-06 15:59:07 +00:00
|
|
|
os._exit(0)
|
2011-06-14 23:44:58 +00:00
|
|
|
except OSError as e:
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
raise Exception("%s [%d]" % (e.strerror, e.errno))
|
2011-05-27 06:31:45 +00:00
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
os.umask(0)
|
2011-05-27 06:31:45 +00:00
|
|
|
os.chdir("/")
|
|
|
|
|
|
|
|
sys.stdout.flush()
|
|
|
|
sys.stderr.flush()
|
|
|
|
si = file('/dev/null', 'r')
|
|
|
|
so = file(self.logfile, 'a+')
|
|
|
|
se = so
|
|
|
|
os.dup2(si.fileno(),sys.stdin.fileno())
|
|
|
|
os.dup2(so.fileno(),sys.stdout.fileno())
|
|
|
|
os.dup2(se.fileno(),sys.stderr.fileno())
|
|
|
|
|
2013-02-06 23:18:19 +00:00
|
|
|
# Ensure logging makes it to the logfile
|
|
|
|
streamhandler = logging.StreamHandler()
|
|
|
|
streamhandler.setLevel(logging.DEBUG)
|
|
|
|
formatter = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
|
|
|
|
streamhandler.setFormatter(formatter)
|
|
|
|
logger.addHandler(streamhandler)
|
|
|
|
|
2011-05-27 06:31:45 +00:00
|
|
|
# write pidfile
|
|
|
|
pid = str(os.getpid())
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
pf = file(self.pidfile, 'w')
|
2011-05-27 06:31:45 +00:00
|
|
|
pf.write("%s\n" % pid)
|
|
|
|
pf.close()
|
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
self.work_forever()
|
2013-02-06 23:18:19 +00:00
|
|
|
self.delpid
|
2013-02-06 15:59:07 +00:00
|
|
|
os._exit(0)
|
2012-01-10 06:13:50 +00:00
|
|
|
|
|
|
|
class PRServSingleton():
|
|
|
|
def __init__(self, dbfile, logfile, interface):
|
|
|
|
self.dbfile = dbfile
|
|
|
|
self.logfile = logfile
|
|
|
|
self.interface = interface
|
|
|
|
self.host = None
|
|
|
|
self.port = None
|
|
|
|
|
2013-02-06 15:59:07 +00:00
|
|
|
def start(self):
|
|
|
|
self.prserv = PRServer(self.dbfile, self.logfile, self.interface)
|
|
|
|
self.prserv.start()
|
2012-01-10 06:13:50 +00:00
|
|
|
self.host, self.port = self.prserv.getinfo()
|
|
|
|
del self.prserv.db
|
|
|
|
|
|
|
|
def getinfo(self):
|
|
|
|
return (self.host, self.port)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
class PRServerConnection():
|
|
|
|
def __init__(self, host, port):
|
2012-01-10 06:13:50 +00:00
|
|
|
if is_local_special(host, port):
|
|
|
|
host, port = singleton.getinfo()
|
2011-05-27 06:31:45 +00:00
|
|
|
self.host = host
|
|
|
|
self.port = port
|
2013-05-30 17:05:14 +00:00
|
|
|
self.connection, self.transport = bb.server.xmlrpc._create_server(self.host, self.port)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
def terminate(self):
|
|
|
|
# Don't wait for server indefinitely
|
|
|
|
import socket
|
|
|
|
socket.setdefaulttimeout(2)
|
|
|
|
try:
|
2013-02-06 23:18:19 +00:00
|
|
|
logger.info("Terminating PRServer...")
|
2011-05-27 06:31:45 +00:00
|
|
|
self.connection.quit()
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
except Exception as exc:
|
|
|
|
sys.stderr.write("%s\n" % str(exc))
|
2011-05-27 06:31:45 +00:00
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def getPR(self, version, pkgarch, checksum):
|
|
|
|
return self.connection.getPR(version, pkgarch, checksum)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
def ping(self):
|
|
|
|
return self.connection.ping()
|
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def export(self,version=None, pkgarch=None, checksum=None, colinfo=True):
|
|
|
|
return self.connection.export(version, pkgarch, checksum, colinfo)
|
2012-01-10 06:13:50 +00:00
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def importone(self, version, pkgarch, checksum, value):
|
|
|
|
return self.connection.importone(version, pkgarch, checksum, value)
|
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
def start_daemon(dbfile, host, port, logfile):
|
|
|
|
pidfile = PIDPREFIX % (host, port)
|
2011-05-27 06:31:45 +00:00
|
|
|
try:
|
2012-01-10 06:13:50 +00:00
|
|
|
pf = file(pidfile,'r')
|
2011-05-27 06:31:45 +00:00
|
|
|
pid = int(pf.readline().strip())
|
|
|
|
pf.close()
|
|
|
|
except IOError:
|
|
|
|
pid = None
|
|
|
|
|
|
|
|
if pid:
|
|
|
|
sys.stderr.write("pidfile %s already exist. Daemon already running?\n"
|
2012-01-10 06:13:50 +00:00
|
|
|
% pidfile)
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
return 1
|
2011-05-27 06:31:45 +00:00
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
server = PRServer(os.path.abspath(dbfile), os.path.abspath(logfile), (host,port))
|
2011-05-27 06:31:45 +00:00
|
|
|
server.start()
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
return 0
|
2011-05-27 06:31:45 +00:00
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def stop_daemon(host, port):
|
|
|
|
pidfile = PIDPREFIX % (host, port)
|
2011-05-27 06:31:45 +00:00
|
|
|
try:
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
pf = file(pidfile,'r')
|
2011-05-27 06:31:45 +00:00
|
|
|
pid = int(pf.readline().strip())
|
|
|
|
pf.close()
|
|
|
|
except IOError:
|
|
|
|
pid = None
|
|
|
|
|
|
|
|
if not pid:
|
|
|
|
sys.stderr.write("pidfile %s does not exist. Daemon not running?\n"
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
% pidfile)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
try:
|
|
|
|
PRServerConnection(host, port).terminate()
|
|
|
|
except:
|
|
|
|
logger.critical("Stop PRService %s:%d failed" % (host,port))
|
2011-05-27 06:31:45 +00:00
|
|
|
time.sleep(0.5)
|
|
|
|
|
|
|
|
try:
|
2012-01-10 06:13:50 +00:00
|
|
|
if pid:
|
|
|
|
if os.path.exists(pidfile):
|
|
|
|
os.remove(pidfile)
|
2011-05-27 06:31:45 +00:00
|
|
|
os.kill(pid,signal.SIGTERM)
|
|
|
|
time.sleep(0.1)
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
except OSError as e:
|
|
|
|
err = str(e)
|
2012-01-10 06:13:50 +00:00
|
|
|
if err.find("No such process") <= 0:
|
|
|
|
raise e
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
|
|
|
|
return 0
|
2011-05-27 06:31:45 +00:00
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
def is_local_special(host, port):
|
|
|
|
if host.strip().upper() == 'localhost'.upper() and (not port):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2013-05-02 14:46:11 +00:00
|
|
|
class PRServiceConfigError(Exception):
|
|
|
|
pass
|
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
def auto_start(d):
|
|
|
|
global singleton
|
2013-01-23 14:54:03 +00:00
|
|
|
|
|
|
|
host_params = filter(None, (d.getVar('PRSERV_HOST', True) or '').split(':'))
|
|
|
|
if not host_params:
|
|
|
|
return True
|
|
|
|
|
|
|
|
if len(host_params) != 2:
|
|
|
|
logger.critical('\n'.join(['PRSERV_HOST: incorrect format',
|
|
|
|
'Usage: PRSERV_HOST = "<hostname>:<port>"']))
|
2013-05-02 14:46:11 +00:00
|
|
|
raise PRServiceConfigError
|
2012-01-10 06:13:50 +00:00
|
|
|
|
2013-01-23 14:54:03 +00:00
|
|
|
if is_local_special(host_params[0], int(host_params[1])) and not singleton:
|
2012-01-10 06:13:50 +00:00
|
|
|
import bb.utils
|
|
|
|
cachedir = (d.getVar("PERSISTENT_DIR", True) or d.getVar("CACHE", True))
|
|
|
|
if not cachedir:
|
|
|
|
logger.critical("Please set the 'PERSISTENT_DIR' or 'CACHE' variable")
|
2013-05-02 14:46:11 +00:00
|
|
|
raise PRServiceConfigError
|
2012-01-10 06:13:50 +00:00
|
|
|
bb.utils.mkdirhier(cachedir)
|
|
|
|
dbfile = os.path.join(cachedir, "prserv.sqlite3")
|
|
|
|
logfile = os.path.join(cachedir, "prserv.log")
|
|
|
|
singleton = PRServSingleton(os.path.abspath(dbfile), os.path.abspath(logfile), ("localhost",0))
|
|
|
|
singleton.start()
|
|
|
|
if singleton:
|
|
|
|
host, port = singleton.getinfo()
|
|
|
|
else:
|
2013-01-23 14:54:03 +00:00
|
|
|
host = host_params[0]
|
|
|
|
port = int(host_params[1])
|
2012-01-10 06:13:50 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
return PRServerConnection(host,port).ping()
|
|
|
|
except Exception:
|
|
|
|
logger.critical("PRservice %s:%d not available" % (host, port))
|
2013-05-02 14:46:11 +00:00
|
|
|
raise PRServiceConfigError
|
2012-01-10 06:13:50 +00:00
|
|
|
|
|
|
|
def auto_shutdown(d=None):
|
|
|
|
global singleton
|
|
|
|
if singleton:
|
|
|
|
host, port = singleton.getinfo()
|
|
|
|
try:
|
|
|
|
PRServerConnection(host, port).terminate()
|
|
|
|
except:
|
|
|
|
logger.critical("Stop PRService %s:%d failed" % (host,port))
|
|
|
|
singleton = None
|
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def ping(host, port):
|
2012-01-10 06:13:50 +00:00
|
|
|
conn=PRServerConnection(host, port)
|
|
|
|
return conn.ping()
|