Exemple #1
0
 def process(self):
     enforce((self.__tree is None), 'Cannot execute processing while another processing or validation routine is still active.')
     self.validate_only = False
     self.__tree = ElementTree(file=self.file)
     self.__path = []
     self._process_child_elements(self.__tree.getroot())
     self.__tree = None
Exemple #2
0
 def __process(self, validate=False):
     background = self.getbool('bg', default=False)
     cachetag = self.element.get('cachetag', default=None)
     prompt = self.getbool('prompt', default=True)
     quiet = self.getbool('quiet', default=False)
     enforce((not (background and cachetag)), 'background and cachetag attributes of <command> are mutually exclusive.')
     command = self.element.text.strip()
     enforce((command in ALLOWED_COMMANDS), (lambda : ("'%s' is not a valid input for <command>." % command)))
     if (not validate):
         cmd = ops.cmd.getDszCommand(command)
         cmd.dszbackground = background
         cmd.dszquiet = quiet
         (issafe, msgs) = cmd.safetyCheck()
         if issafe:
             if (command not in ALLOWED_WITHOUT_WARNING):
                 ops.info(('%s has passed registered safety checks, but you should still make sure' % command))
                 for msg in msgs:
                     ops.info(msg)
         else:
             ops.warn(('"%s" has NOT passed registered safety checks' % command))
             for msg in msgs:
                 ops.error(msg)
             ops.warn(('"%s" will not be run at this time' % command))
             return True
         if prompt:
             if (not dsz.ui.Prompt(((("Do you want to run '%s'" + (' in the background' if background else '')) + '?') % command))):
                 return True
         result = cmd.execute()
         if ((cachetag is not None) and (result is not None)):
             voldb = ops.db.get_voldb()
             voldb.save_ops_object(result, tag=cachetag)
     return True
Exemple #3
0
 def __handle(self, validate=False):
     name = self.element.get('name')
     menu = (self.getbool('menu', default=False) or self.forcemenu)
     enforce((name is not None), '<section> tag requires a name attribute.')
     if ((menu or self.forcemenu) and (not validate)):
         if (not self.__menu()):
             return None
     return self.continue_processing(ignore=['preps'])
Exemple #4
0
 def __process(self, validate=False):
     file = self.element.get('file')
     section = self.element.get('section')
     enforce((file is not None), '<config> requires a file attribute.')
     enforce((section is not None), '<config> requires a section attribute.')
     if validate:
         return True
     for (resdir, fullpath) in ops.survey.locate_files(file, 'Data'):
         if dsz.ui.Prompt(('Execute configuration %s :: %s?' % (resdir, fullpath))):
             bugcatcher((lambda : ops.survey.engines.run(fullpath, sections=[section], forcemenu=True)), bug_critical=False)
     return True
Exemple #5
0
 def __process(self, validate=False):
     file = self.element.get('file')
     section = self.element.get('section')
     enforce((file is not None), '<config> requires a file attribute.')
     enforce((section is not None),
             '<config> requires a section attribute.')
     if validate:
         return True
     for (resdir, fullpath) in ops.survey.locate_files(file, 'Data'):
         if dsz.ui.Prompt(
             ('Execute configuration %s :: %s?' % (resdir, fullpath))):
             bugcatcher((lambda: ops.survey.engines.run(
                 fullpath, sections=[section], forcemenu=True)),
                        bug_critical=False)
     return True
Exemple #6
0
 def __init__(self, element, _processor=None, _marker=None, _period=None, _display=None, _error_marker=None):
     enforce((_processor is not None), 'Tag handler does not have all the required information.')
     enforce((element is not None), 'Tag handler does not have its element to process.')
     enforce((_display is not None), 'Display for error print out required.')
     enforce((_error_marker is not None), 'Error marker must be provided for error flow control.')
     self.__period = _period
     self.__marker = _marker
     self.__error_marker = _error_marker
     self.__display = _display
     self.element = element
     self.__processor = _processor
Exemple #7
0
 def __process(self, validate=False):
     background = self.getbool('bg', default=False)
     cachetag = self.element.get('cachetag', default=None)
     prompt = self.getbool('prompt', default=True)
     quiet = self.getbool('quiet', default=False)
     enforce((
         not (background and cachetag)
     ), 'background and cachetag attributes of <command> are mutually exclusive.'
             )
     command = self.element.text.strip()
     enforce((command in ALLOWED_COMMANDS),
             (lambda:
              ("'%s' is not a valid input for <command>." % command)))
     if (not validate):
         cmd = ops.cmd.getDszCommand(command)
         cmd.dszbackground = background
         cmd.dszquiet = quiet
         (issafe, msgs) = cmd.safetyCheck()
         if issafe:
             if (command not in ALLOWED_WITHOUT_WARNING):
                 ops.info((
                     '%s has passed registered safety checks, but you should still make sure'
                     % command))
                 for msg in msgs:
                     ops.info(msg)
         else:
             ops.warn(
                 ('"%s" has NOT passed registered safety checks' % command))
             for msg in msgs:
                 ops.error(msg)
             ops.warn(('"%s" will not be run at this time' % command))
             return True
         if prompt:
             if (not dsz.ui.Prompt(
                 ((("Do you want to run '%s'" +
                    (' in the background' if background else '')) + '?') %
                  command))):
                 return True
         result = cmd.execute()
         if ((cachetag is not None) and (result is not None)):
             voldb = ops.db.get_voldb()
             voldb.save_ops_object(result, tag=cachetag)
     return True
Exemple #8
0
 def _process_child_elements(self, element, ignore=[]):
     self.__path.append(None)
     for e in element:
         self.__path.pop()
         dsz.script.CheckStop()
         if (e.tag in ignore):
             continue
         self.__path.append(e.tag)
         modname = '.'.join(([self.namespace] + self.__path))
         try:
             __import__(modname)
         except ImportError as exc:
             enforce(False, (lambda : ("Tag handler '%s' not found for element '<%s>'; reason: %s." % (modname, e.tag, exc))))
         handler = sys.modules[modname]
         marker = e.get('marker')
         display = e.get('name')
         generic_display = ('"%s": ["attribs": %s, "text": %s]' % (e.tag, e.attrib, repr(e.text)))
         if (display is None):
             display = generic_display
         error_marker = (marker if (marker is not None) else ((('__generic_error_marker__::' + self.file) + '::') + generic_display))
         period = e.get('period')
         if (period is not None):
             period = self.__interval.match(period)
             enforce((period is not None), (lambda : ('%s -- error in period time delta format string.' % display)))
             qc = (lambda x: (int(x) if (x is not None) else 0))
             period = datetime.timedelta(weeks=qc(period.group(2)), days=qc(period.group(4)), hours=qc(period.group(6)), minutes=qc(period.group(8)), seconds=qc(period.group(10)))
         taghandler = eval((('handler.' + e.tag.title()) + 'TagHandler(element=e, _processor=self, _marker=marker, _period=period, _display=display, _error_marker=error_marker)'))
         if self.validate_only:
             enforce(taghandler.validate(), (lambda : ("Validation error for tag '<%s>'; text='%s'; attributes=%s" % (e.tag, repr(e.text), e.attrib))))
         else:
             if (not taghandler.marker_check()):
                 continue
             try:
                 ret = taghandler.process()
                 if (ret == True):
                     if ((marker is not None) or (marker != 'None')):
                         ops.survey.complete(marker)
                     else:
                         ops.survey.complete(error_marker)
                 elif (ret == False):
                     if ((marker is not None) and (marker != 'None')):
                         ops.survey.error(marker)
                     else:
                         ops.survey.error(error_marker)
             except:
                 if ((marker is not None) and (marker != 'None')):
                     ops.survey.error(marker)
                 else:
                     ops.survey.error(error_marker)
                 raise 
     self.__path.pop()
     return True
Exemple #9
0
 def validate(self):
     enforce(False, (lambda : ("XML element handeler 'validate' not implemented for %s" % self.__class__)))
Exemple #10
0
 def process(self):
     enforce(False, (lambda : ("XML element handler 'process' not implemented for %s" % self.__class__)))