7
from string import strip
8
from optparse import OptionParser
11
from canonical.lp import initZopeless
14
from canonical.launchpad.database import SourcePackageName
15
from canonical.launchpad.database import BinaryPackageName
18
"""Base for Packages name list"""
20
def __init__(self, filename):
21
self.filename = filename
28
f = open(self.filename)
30
print 'file %s not found. Exiting...' %self.filename
34
line = self._check_format(strip(line))
36
if not self._valid_name(line):
37
print ' - Invalid package name: %s' %line
39
self.list.append(line)
41
def _check_format(self, name):
42
assert isinstance(name, basestring), repr(name)
44
# check that this is unicode data
45
name.decode("utf-8").encode("utf-8")
48
# check that this is latin-1 data
49
s = name.decode("latin-1").encode("utf-8")
53
def _valid_name(self, name):
54
pat = r"^[a-z0-9][a-z0-9\\+\\.\\-]+$"
55
if re.match(pat, name):
58
class SourcePackageNameList(BaseNameList):
59
"""Build a sourcepackagename list from a given file"""
61
class BinaryPackageNameList(BaseNameList):
62
"""Build a binarypackagename list from a given file"""
65
def __init__(self, interval):
67
self.interval = interval
70
setattr(self, 'step', self._fake_step)
72
setattr(self, 'step', self._step)
76
if self._count > self.interval:
87
def __init__(self, source_list, binary_list, commit_interval=0):
88
self.source_list = source_list
89
self.binary_list = binary_list
90
self.ztm = initZopeless()
91
self.interval = commit_interval
92
self.count = Counter(commit_interval)
95
print '\t\t@ Commiting...'
99
def processSource(self):
100
if not self.source_list:
103
spnl = SourcePackageNameList(self.source_list).list
106
print '\t@ Evaluationg SourcePackageName %s' %name
107
SourcePackageName.ensure(name)
108
if self.count.step():
115
def processBinary(self):
116
if not self.binary_list:
119
bpnl = BinaryPackageNameList(self.binary_list).list
122
print '\t@ Evaluationg BinaryPackageName %s' %name
123
BinaryPackageName.ensure(name)
124
if self.count.step():
131
if __name__ == '__main__':
133
parser = OptionParser()
135
parser.add_option("-s", "--source-file", dest="source_file",
136
help="SourcePackageName list file",
139
parser.add_option("-b", "--binary-file", dest="binary_file",
140
help="BinaryPackageName list file",
143
parser.add_option("-c", "--commit-interval", dest="commit_interval",
144
help="DB commit interval. Default 0 performs not commit.",
147
(options,args) = parser.parse_args()
150
processor = ProcessNames(options.source_file,
152
int(options.commit_interval))
154
processor.processSource()
155
processor.processBinary()