comparison bin/publishdebianpackages.py @ 414:e0539b483b04 treepkg-status

moved data handling in publishdebianpackages into seperate module
author Bjoern Ricks <bricks@intevation.de>
date Mon, 26 Jul 2010 08:28:48 +0000
parents 94a6ae627b31
children 4980f8d5014a
comparison
equal deleted inserted replaced
413:94a6ae627b31 414:e0539b483b04
10 """Publishes selected packages created by treepkg""" 10 """Publishes selected packages created by treepkg"""
11 11
12 import os 12 import os
13 import sys 13 import sys
14 import shlex 14 import shlex
15 import sqlite3
16 15
17 from optparse import OptionParser 16 from optparse import OptionParser
18 from ConfigParser import SafeConfigParser 17 from ConfigParser import SafeConfigParser
19 18
20 import treepkgcmd 19 import treepkgcmd
22 from treepkg.run import call, capture_output 21 from treepkg.run import call, capture_output
23 from treepkg.cmdexpand import cmdexpand 22 from treepkg.cmdexpand import cmdexpand
24 from treepkg.publish import * 23 from treepkg.publish import *
25 from treepkg.util import md5sum 24 from treepkg.util import md5sum
26 from treepkg.info.status import TreepkgInfo 25 from treepkg.info.status import TreepkgInfo
26 from treepkg.info.data import Package
27 from treepkg.info.data import CacheDb
27 28
28 config_desc = ["distribution", "section", "num_newest", 29 config_desc = ["distribution", "section", "num_newest",
29 "build_user", "build_host", "build_listpackages", 30 "build_user", "build_host", "build_listpackages",
30 "publish_user", "publish_host", 31 "publish_user", "publish_host",
31 ("architectures", shlex.split, "armel i386 source"), 32 ("architectures", shlex.split, "armel i386 source"),
33 ("publish_remove_old_packages", convert_bool), 34 ("publish_remove_old_packages", convert_bool),
34 ("publish_dir", remove_trailing_slashes), 35 ("publish_dir", remove_trailing_slashes),
35 ("cachedir", 36 ("cachedir",
36 lambda s: expand_filename(remove_trailing_slashes(s)))] 37 lambda s: expand_filename(remove_trailing_slashes(s)))]
37 38
38 class Package:
39
40 def __init__(self, filename, trackname, packagename, packagepath, arch, md5sum):
41 self.filename = filename
42 self.trackname = trackname
43 self.name = packagename
44 self.sourcepath = packagepath
45 self.arch = arch
46 self.md5sum = md5sum
47
48
49 class CacheDb:
50
51
52 def __init__(self, file):
53 self.SELECT_PACKAGE_TMPL = """SELECT * FROM packages
54 WHERE filename = ?"""
55 self.file = file
56 self.conn = sqlite3.connect(file)
57 self.cursor = self.conn.cursor()
58 self.init_db(file)
59
60 def init_db(self, file):
61 self.cursor.execute(
62 """CREATE TABLE IF NOT EXISTS packages (
63 filename TEXT PRIMARY KEY,
64 trackname TEXT,
65 packagename TEXT,
66 sourcepath TEXT,
67 arch TEXT,
68 md5sum TEXT )""")
69 self.conn.commit()
70
71
72 def add_package(self, package):
73 self.cursor.execute(self.SELECT_PACKAGE_TMPL, (package.filename,))
74 row = self.cursor.fetchone()
75 if not row:
76 self.insert_package(package)
77 else:
78 self.update_package(package)
79
80 def insert_package(self, package):
81 INSERT_TMPL = """INSERT INTO packages VALUES (
82 ?, ?, ? ,? ,?, ?)"""
83 self.cursor.execute(INSERT_TMPL, (package.filename,
84 package.trackname,
85 package.name,
86 package.sourcepath,
87 package.arch,
88 package.md5sum))
89 self.conn.commit()
90
91 def update_package(self, package):
92 UPDATE_TMPL = """UPDATE packages set md5sum = '?'
93 WHERE filename in (?)"""
94 self.cursor.execute(UPDATE_TMPL, (package.md5sum, package.filename))
95 self.conn.commit()
96
97 def get_package(self, filename):
98 self.cursor.execute(self.SELECT_PACKAGE_TMPL, (filename,))
99 row = self.cursor.fetchone()
100 if not row:
101 return None
102 return Package(row[0], row[1], row[2], row[3], row[4], row[5])
103
104 def get_old_packages(self, newfiles):
105 SELECT_TMPL = """SELECT * FROM packages
106 WHERE filename not in (%s)"""
107 tmp = ", ".join(['?'] * len(newfiles))
108 self.cursor.execute(SELECT_TMPL % tmp, newfiles)
109 return [Package(*row) for row in self.cursor.fetchall()]
110
111 def remove_packages(self, files):
112 DELET_TMPL = """DELETE FROM packages
113 WHERE filename in (%s)"""
114 tmp = ", ".join(['?'] * len(files))
115 self.cursor.execute(DELET_TMPL % tmp, files)
116 self.conn.commit()
117
118 def get_packages(self):
119 SELECT_TMPL = "SELECT * FROM packages"
120 self.cursor.execute(SELECT_TMPL)
121 return [Package(*row) for row in self.cursor.fetchall()]
122 39
123 def read_config(filename): 40 def read_config(filename):
124 if not os.path.exists(filename): 41 if not os.path.exists(filename):
125 print >>sys.stderr, "Config file %s does not exist" % filename 42 print >>sys.stderr, "Config file %s does not exist" % filename
126 sys.exit(1) 43 sys.exit(1)
153 70
154 def get_treepkg_info(variables): 71 def get_treepkg_info(variables):
155 runremote = prefix_for_remote_command(variables["build_user"], 72 runremote = prefix_for_remote_command(variables["build_user"],
156 variables["build_host"]) 73 variables["build_host"])
157 xml = capture_output(cmdexpand("@runremote $build_listpackages" 74 xml = capture_output(cmdexpand("@runremote $build_listpackages"
158 " --newest=$num_newest", 75 " --newest=$num_newest"
76 " --only-successful",
159 runremote=runremote, 77 runremote=runremote,
160 **variables)) 78 **variables))
161 return TreepkgInfo.fromxml(xml) 79 return TreepkgInfo.fromxml(xml)
162 80
163 def get_binary_arch(arch): 81 def get_binary_arch(arch):
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)