Package linda :: Module checker
[hide private]

Source Code for Module linda.checker

 1  import os, linda 
 2  from linda import clparser 
 3  from linda.debug import dprint, vprint 
 4  from linda.err_print import PrintErrors, ErrorPrintingException 
 5  from linda.libchecks import CheckRunningException 
 6  from linda.overrides import Overrides 
 7  from linda.unpack import Unpacker, UnpackException 
 8  from linda.parser.data import DataFileParser 
 9  from linda.parser.override import OverrideParser 
10   
11 -class Checker:
12 - def __init__(self):
13 self.mapping = {'deb': 'binary', 'dsc': 'source', 'changes': \ 14 'changes', 'udeb': 'udeb'} 15 self.data_files = {}
16
17 - def check(self, file):
18 self.file = file 19 self.processing_print() 20 self.err_printer = PrintErrors(file) 21 if os.path.splitext(self.file)[1] == '.changes': 22 self.unpacker = ChangesUnpacker() 23 self.overrides = ChangesOverrides() 24 self.run_checks(1) 25 else: 26 try: 27 self.unpacker = Unpacker() 28 except UnpackException, e: 29 raise CheckerException(e) 30 self.overrides = Overrides(file, self.unpacker.lab) 31 self.go()
32
33 - def go(self):
34 self.unpack(1) 35 self.overrides.parse() 36 self.run_checks(1) 37 ext = os.path.splitext(self.file)[1][1:] 38 if linda.checks.registry[self.mapping[ext]][2]: 39 if not clparser['unpack'] or clparser['unpack'] == 2: 40 self.unpack(2) 41 if os.path.exists(os.path.join(self.unpacker.information['dir'], \ 42 'debian', 'linda-overrides')): 43 try: 44 o = OverrideParser(os.path.join(self.unpacker.information['dir'], \ 45 'debian', 'linda-overrides')) 46 self.overrides.merge(o) 47 except EnvironmentError, e: 48 dprint(_("Failed to parse in-tarball override: %s")) 49 self.run_checks(2) 50 self.cull_lab()
51
52 - def unpack(self, level):
53 try: 54 self.unpacker.unpack(self.file, level) 55 except UnpackException, e: 56 raise CheckerException('Level %d unpacking failed: %s' % \ 57 (level, e))
58
59 - def cull_lab(self):
60 self.unpacker.cull_lab()
61
62 - def run_checks(self, level):
63 if not clparser['unpack']: 64 try: 65 errs = linda.checks.apply(self.unpacker.lab, self.file, \ 66 self.unpacker.information, level) 67 except CheckRunningException, e: 68 raise CheckerException(e) 69 for err in errs.keys(): 70 if not self.data_files.has_key(err) and os.path.exists(err): 71 self.data_files[err] = DataFileParser(err) 72 if not clparser['show-overridden']: 73 errs, data_files = self.overrides.check(errs, self.data_files) 74 try: 75 self.err_printer.print_error(errs, self.data_files) 76 except ErrorPrintingException, e: 77 raise CheckerException(e)
78
79 - def processing_print(self):
80 vprint(_("Processing file: %s") % os.path.split(self.file)[1], 1) 81 dprint(_("Processing file: %s") % os.path.split(self.file)[1])
82
83 -class CheckerException(Exception):
84 pass
85
86 -class ChangesUnpacker:
87 - def __init__(self):
88 self.lab = '' 89 self.information = ''
90
91 -class ChangesOverrides:
92 - def check(self, errs, data_files):
93 return [{}, {}]
94