]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
script to add existign packages to db added
authorHolger Levsen <holger@layer-acht.org>
Thu, 27 Sep 2012 14:34:11 +0000 (16:34 +0200)
committerHolger Levsen <holger@layer-acht.org>
Thu, 27 Sep 2012 14:34:11 +0000 (16:34 +0200)
common_code.py [new file with mode: 0755]
db_add.py
debian_build.py
debian_packages2db.py
debian_repos2db.sh

diff --git a/common_code.py b/common_code.py
new file mode 100755 (executable)
index 0000000..f2db8db
--- /dev/null
@@ -0,0 +1,31 @@
+#!/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)
+
+
index b9ce111232c5dd363f74bbdeb4b0e7af021e57bb..cec82558e4a1eecfa0d2dc463223b9c632defd4c 100755 (executable)
--- a/db_add.py
+++ b/db_add.py
@@ -6,15 +6,13 @@ import re
 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()
@@ -120,4 +118,15 @@ def add_package_instance(origin, job_name, build_number, changes_file, version,
     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
 
index 63eb8ce2aee738abf36e3771885368f07c90bc1d..f599a78754cde529f5469523dc3b10e86e528356 100755 (executable)
@@ -19,6 +19,7 @@ import time
 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 *
@@ -92,22 +93,10 @@ DPUT_CF = os.path.join(CWD, '..', 'dput.cf')
 
 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)
@@ -190,15 +179,6 @@ def remove_git_target_workspace():
         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')
@@ -213,6 +193,7 @@ def getopts():
     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(
index e46994a9c4b6a28b11dc69d8a623745c6eaee5c5..a32ad7e3121781ffd5c518f86eac9c15f7f03268 100755 (executable)
@@ -10,36 +10,44 @@ import subprocess
 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)
index db6ff9a8d52dc67b713e08e149c9dd84290d691f..0604c17e75a038fac5ad43728e5f542120a7546d 100755 (executable)
@@ -9,11 +9,16 @@ REPO_SECTIONS[1]="main contrib non-free"
 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