--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+import logging
+from logging import Formatter
+
+def logger_init():
+ log_format = '%(asctime)s %(name)s[%(process)d] %(levelname)s: %(message)s'
+ formatter = Formatter(log_format)
+ logging.basicConfig(
+ format=log_format,
+ level=logging.DEBUG
+ )
+ logger = logging.getLogger(__file__)
+ logger.setLevel(logging.DEBUG)
+ return logger
+
+def logger_error(msg):
+ print msg
+ logger.error(msg)
+
+def exit_ok():
+ sys.exit(0)
+
+def exit_error():
+ print "################################################################"
+ sys.exitfunc = lambda: None
+ sys.exit(1)
+
+
import pwd
import sys
import errno
-import logging
import datetime
import subprocess
import time
import fileinput
import psycopg2
+from common_code import *
from cidb import *
-from logging import Formatter
-
def db_add_job(con, name):
cur = con.cursor()
logger.info("CIDB update OK.")
return db_package_instance_id
+def add_package_version(origin, package, version):
+ logger = logger_init()
+ con = db_connect()
+ #logger.debug("save %s to database" %(job_name))
+ db_origin_id = db_add_origin(con, origin)
+ db_package_id = db_add_package (con, package)
+ db_package_instance_id = db_add_package_instance (con, db_package_id, db_origin_id, 'NULL', version)
+ logger.debug("INSERT success package version %s %s" %( package,version))
+ #logger.debug('Cmd returned with status %d' %(cmdobj.returncode))
+ con.commit()
+ return db_package_instance_id
import urllib
import fileinput
import psycopg2
+from common_code import *
from add_liveboot_request import add_liveboot_request
from db_add import *
from cidb import *
NO_UPLOAD = os.environ.get('NO_UPLOAD')
-log_format = '%(asctime)s %(name)s[%(process)d] %(levelname)s: %(message)s'
-formatter = Formatter(log_format)
-logging.basicConfig(
- format=log_format,
- level=logging.DEBUG
-)
-logger = logging.getLogger(__file__)
-logger.setLevel(logging.DEBUG)
class HudsonUrl(urllib.FancyURLopener):
pass
-def logger_error(msg):
- print msg
- logger.error(msg)
-
def read_file(path):
try:
fh = open(path, 'r', 1)
return True
-
-def exit_ok():
- sys.exit(0)
-
-def exit_error():
- print "################################################################"
- sys.exitfunc = lambda: None
- sys.exit(1)
-
def getopts():
usage = '%prog [options]'
parser = optparse.OptionParser(usage=usage, version='%prog 0.1')
return parser.parse_args()
if __name__ == '__main__':
+ logger = logger_init()
logger.debug('Called in: %s' % os.getcwd())
logger.debug('Called with: %s' % " ".join(sys.argv))
logger.debug(
import time
import fileinput
import string
+import tempfile
+from common_code import *
from db_add import *
if __name__ == '__main__':
- if len(sys.argv) != 2:
- print("usage: %s $packages_file")
+ if len(sys.argv) != 3:
+ print("usage: %s $packages_file $origin")
sys.exit(1)
packages_file = sys.argv[1]
+ origin = sys.argv[2]
- cmd = ['grep-dctrl', '-n', '-s', 'Package,Version', '', packages_file]
+ tmp = tempfile.NamedTemporaryFile(delete=False)
+ cmd = ['egrep', '(^Package:|^Version:)', packages_file]
print cmd
- grep_dctrl = subprocess.Popen(
+ egrep = subprocess.Popen(
cmd,
- stdout=subprocess.PIPE,
+ stdout=tmp,
close_fds=True,
shell=False,
+ bufsize=-1
)
- ret = grep_dctrl.wait()
+ ret = egrep.wait()
if ret:
print '%s was not successfull, return code was %s ' % (' '.join(cmd), ret)
sys.exit(1)
+ tmp.seek(0)
+
pkg_name = ' '
while pkg_name:
- pkg_name = grep_dctrl.stdout.readline()
- pkg_name = pkg_name.strip()
+ pkg_name = tmp.readline()
if pkg_name == '':
break
- version = grep_dctrl.stdout.readline()
- version = version.strip()
- empty = grep_dctrl.stdout.readline()
- print 'would add %s %s' % (pkg_name,version)
+ pkg_name = pkg_name.strip().split()[1]
+ version = tmp.readline()
+ version = version.strip().split()[1]
+ print 'would add %s %s %s' % (pkg_name,version,origin)
+ add_package_version(origin, pkg_name, version)
+ os.remove(tmp.name)
REPO_BASE_URL[1]="http://alexandria.profitbricks.localdomain/debian-mirror/dists/SUITE/SECTION/binary-amd64/"
for RUN in 0 1 ; do
+ if [ "$RUN" == 0 ] ; then
+ ORIGIN=profitbricks
+ else
+ ORIGIN=debian
+ fi
for SUITE in ${REPO_SUITES[$RUN]} ; do
for SECTION in ${REPO_SECTIONS[$RUN]} ; do
URL=$(echo ${REPO_BASE_URL[$RUN]} | sed -s "s#SUITE#$SUITE#" | sed -s "s#SECTION#$SECTION#")/Packages
wget $URL -o /dev/null
- [ -s Packages ] && ./debian_packages2db.py Packages
+ [ -s Packages ] && ./debian_packages2db.py Packages $ORIGIN
rm Packages
done
done