Example #1
0
 def reset(self):
     del self._current_el
     del self._root
     self._current_el = None
     self._root = amara.create_document()
     self._current_el = self._root
     self._current_level = 0
Example #2
0
 def reset(self):
     del self._current_el
     del self._root
     self._current_el = None
     self._root = amara.create_document()
     self._current_el = self._root
     self._current_level = 0
Example #3
0
    def scan_content(filename, content, element_name, doc=None):
        """ This method scan the defined content to find any custom comment tags.
        
        It returns an xml document.
        """
        # Creating a doc if not defined
        if not doc:
            doc = amara.create_document(u"commentLog")
            
        # Search the file for any XML elements matching the given element name
        regex = string.Template(r"<${element_name}.*</${element_name}>").substitute(element_name=element_name)
        comment_elements = re.findall(regex, content, re.DOTALL)
        for comment in comment_elements:
            (_, file_type) = os.path.splitext(filename)
            file_type = file_type.lower()
            if COMMENT_SYMBOLS.has_key(file_type):
                for i in range(len(COMMENT_SYMBOLS[file_type])): 
                    comment = comment.replace(COMMENT_SYMBOLS[file_type][i], "")
            try:
                doc.commentLog.xml_append_fragment(comment)
                # Add a generic file attribute to the comment to label which file it comes from
                doc.commentLog.xml_children[-1].xml_set_attribute(u'file', unicode(filename))
            except Exception:
                _logger.warning("A comment in '%s' is not valid XML." % filename)

        #print doc.xml()
        return doc
Example #4
0
def build_document(game):
    doc = amara.create_document(u'sports-content')

    build_metadata(doc, game)
    build_event(doc, game)

    build_team(doc, doc.sports_content.sports_event, game, "away")
    build_team(doc, doc.sports_content.sports_event, game, "home")

    return doc
Example #5
0
    def scan(self):
        """ This method goes processes the input files.
        
        It returns an xml document.  """
        doc = amara.create_document(u"commentLog")
        for path in self.files:
            open_file = open(path)
            CommentParser.scan_content(path, open_file.read(), self.element_name, doc)
            open_file.close()

        #print doc.xml()
        return doc
Example #6
0
    def save_project(self, p_name, p_localization, p_m_list, p_date):
        """
            p_name: cadena de texto que representa el nombre del proyecto.
            p_localization: cadena de texto que representa el camino completo 
                            hasta la ubicacion del proyecto.
            p_m_list: lista que contiene el nombre de todos los archivos m 
                      incluidos en el proyecto.
            p_date: cadena de texto que representa la fecha en que fue creado 
                    el proyecto.            

            Metodo mediante el cual se guardan los datos del proyecto en 
            formato xml.
        """
        self.__doc = amara.create_document()
        self.__doc.xml_append(self.__doc.xml_create_element(u'project'))
        self.__doc.project.xml_append(
            self.__doc.xml_create_element(u"name_project"))
        self.__doc.project.name_project = u"%s" % (p_name)

        self.__doc.project.xml_append(
            self.__doc.xml_create_element(u"date_project"))
        self.__doc.project.date_project = u"%s" % (p_date)

        self.__doc.project.xml_append(self.__doc.xml_create_element(u"VAR"))
        self.__doc.project.VAR = u"vars.var"

        self.__doc.project.xml_append(self.__doc.xml_create_element(u"HIST"))
        self.__doc.project.HIST = u"hist.txt"

        self.__doc.project.xml_append(self.__doc.xml_create_element(u"SRC"))

        it = 0
        for i in p_m_list:
            self.__doc.project.SRC.xml_append(
                self.__doc.xml_create_element(u"m_file"))
            self.__doc.project.SRC.m_file[it] = u'%s' % (i)
            it += 1

        dir_ = os.path.join(p_localization, "build" + '.xml')
        f = open(dir_, 'w')
        f.write(self.__doc.xml())
        f.close()
Example #7
0
    def write(self, path):
        """ Write the BOM information to an XML file. """
        doc = amara.create_document(u'bom')
        # pylint: disable-msg=E1101
        doc.bom.xml_append(doc.xml_create_element(u'build', content=unicode(self._bom.config['build.id'])))
        doc.bom.xml_append(doc.xml_create_element(u'content'))
        for project in self._bom.projects:
            project_node = doc.xml_create_element(u'project')
            project_node.xml_append(doc.xml_create_element(u'name', content=unicode(project)))
            project_node.xml_append(doc.xml_create_element(u'database', content=unicode(self._bom.config['ccm.database'])))
            doc.bom.content.xml_append(project_node)
            _logger.debug('baselines dictionary: %s' % project.baselines)
            for baseline, baseline_attrs in sorted(project.baselines.iteritems()):
                _logger.debug('baseline: %s' % baseline)
                _logger.debug('baseline_attrs: %s' % baseline_attrs)
                project_node.xml_append(doc.xml_create_element(u'baseline', content=unicode(baseline), attributes=baseline_attrs))
            for folder in project.folders:
                folder_node = doc.xml_create_element(u'folder')
                folder_node.xml_append(doc.xml_create_element(u'name', content=unicode(folder.instance + "#" + folder.name + ": " + folder.description), \
                            attributes={u'overridden':u'true'}))
                project_node.xml_append(folder_node)
                for task in folder.tasks:
                    task_node = doc.xml_create_element(u'task', attributes={u'overridden':u'false'})
                    task_node.xml_append(doc.xml_create_element(u'id', content=(unicode(task['displayname']))))
                    task_node.xml_append(doc.xml_create_element(u'synopsis', content=(unicode(task['task_synopsis']))))
                    task_node.xml_append(doc.xml_create_element(u'owner', content=(unicode(task['owner']))))
                    #task_node.xml_append(doc.xml_create_element(u'completed', content=(unicode(self.parse_status_log(task['status_log'])))))
                    folder_node.xml_append(task_node)
            for task in project.tasks:
                task_node = doc.xml_create_element(u'task', attributes={u'overridden':u'true'})
                task_node.xml_append(doc.xml_create_element(u'id', content=(unicode(task['displayname']))))
                task_node.xml_append(doc.xml_create_element(u'synopsis', content=(unicode(task['task_synopsis']))))
                task_node.xml_append(doc.xml_create_element(u'owner', content=(unicode(task['owner']))))
                #task_node.xml_append(doc.xml_create_element(u'completed', content=(unicode(self.parse_status_log(task['status_log'])))))
                project_node.xml_append(task_node)
                
                fix = task.has_fixed()
                if fix != None:
                    fix_node = doc.xml_create_element(u'fix', content=(unicode(task)), attributes = {u'type': unicode(fix.__class__.__name__)})
                    project_node.xml_append(fix_node)

        if self._bom._icd_icfs != []:
            # Add ICD info to BOM
            doc.bom.content.xml_append(doc.xml_create_element(u'input'))
    
            # Add default values to unused fields so icds are visible in the BOM
            empty_bom_str = u'N/A'
            empty_bom_tm = u'0'
            doc.bom.content.input.xml_append(doc.xml_create_element(u'name', content=(unicode(empty_bom_str))))
            doc.bom.content.input.xml_append(doc.xml_create_element(u'year', content=(unicode(empty_bom_tm))))
            doc.bom.content.input.xml_append(doc.xml_create_element(u'week', content=(unicode(empty_bom_tm))))
            doc.bom.content.input.xml_append(doc.xml_create_element(u'version', content=(unicode(empty_bom_str))))
    
            doc.bom.content.input.xml_append(doc.xml_create_element(u'icds'))

        # pylint: disable-msg=R0914
        for i, icd in enumerate(self._bom._icd_icfs):
            doc.bom.content.input.icds.xml_append(doc.xml_create_element(u'icd'))
            doc.bom.content.input.icds.icd[i].xml_append(doc.xml_create_element(u'name', content=(unicode(icd))))
        #If currentRelease.xml exists then send s60 <input> tag to diamonds
        current_release_xml_path = self._bom.config['currentRelease.xml']
        if current_release_xml_path is not None and os.path.exists(current_release_xml_path):
            metadata = symrec.ReleaseMetadata(current_release_xml_path)
            service = metadata.service
            product = metadata.product
            release = metadata.release
            # Get name, year, week and version from baseline configuration
            s60_input_node = doc.xml_create_element(u'input')
            s60_version = self._bom.config['s60_version']
            s60_release = self._bom.config['s60_release']
            if s60_version != None:
                s60_year = s60_version[0:4]
                s60_week = s60_version[4:]
            else:
                s60_year = u'0'
                s60_week = u'0'
                if s60_version == None:
                    res = re.match(r'(.*)_(\d{4})(\d{2})_(.*)', release)
                    if res != None:
                        s60_release = res.group(1) + '_' + res.group(4)
                        s60_year = res.group(2)
                        s60_week = res.group(3)
            s60_input_node.xml_append(doc.xml_create_element(u'name', content=(unicode("s60"))))
            s60_input_node.xml_append(doc.xml_create_element(u'year', content=(unicode(s60_year))))
            s60_input_node.xml_append(doc.xml_create_element(u'week', content=(unicode(s60_week))))
            s60_input_node.xml_append(doc.xml_create_element(u'version', content=(unicode(s60_release))))

            s60_input_source = s60_input_node.xml_create_element(u'source')
            s60_input_source.xml_append(doc.xml_create_element(u'type', content=(unicode("grace"))))
            s60_input_source.xml_append(doc.xml_create_element(u'service', content=(unicode(service))))
            s60_input_source.xml_append(doc.xml_create_element(u'product', content=(unicode(product))))
            s60_input_source.xml_append(doc.xml_create_element(u'release', content=(unicode(release))))
            s60_input_node.xml_append(s60_input_source)
            doc.bom.content.xml_append(s60_input_node)
        out = open(path, 'w')
        doc.xml(out, indent='yes')
        out.close()
Example #8
0
    def write(self, path):
        """ Write the BOM delta information to an XML file. """
        bom_log = amara.parse(open(self._bom_log, 'r'))
        doc = amara.create_document(u'bomDelta')
        # pylint: disable-msg=E1101
        doc.bomDelta.xml_append(doc.xml_create_element(u'buildFrom', content=unicode(bom_log.bom.build)))
        doc.bomDelta.xml_append(doc.xml_create_element(u'buildTo', content=unicode(self._bom.config['build.id'])))
        content_node = doc.xml_create_element(u'content')
        doc.bomDelta.xml_append(content_node)
        
        old_baselines = {}
        baselines = {}
        old_folders = {}
        folders = {}
        old_tasks = {}
        tasks = {}
        if hasattr(bom_log.bom.content, 'project'):
            for project in bom_log.bom.content.project:
                if hasattr(project, 'baseline'):
                    for baseline in project.baseline:
                        if not old_baselines.has_key(unicode(baseline)):
                            old_baselines[unicode(baseline)] = {}
                        if hasattr(baseline, 'xml_attributes'):
                            _logger.debug('baseline.xml_attributes: %s' % baseline.xml_attributes)
                            for attr_name, junk_tuple in sorted(baseline.xml_attributes.iteritems()):
                                _logger.debug('attr_name: %s' % attr_name)
                                old_baselines[unicode(baseline)][unicode(attr_name)] = unicode(getattr(baseline, attr_name))
                if hasattr(project, 'folder'):
                    for folder in project.folder:
                        if hasattr(folder, 'name'):
                            for name in folder.name:
                                folder_name = unicode(name)
                                _logger.debug('folder_name: %s' % folder_name)
                            if not old_folders.has_key(unicode(folder_name)):
                                old_folders[unicode(folder_name)] = {}
                            if hasattr(name, 'xml_attributes'):
                                for attr_name, junk_tuple in sorted(name.xml_attributes.iteritems()):
                                    _logger.debug('attr_name: %s' % attr_name)
                                    old_folders[unicode(folder_name)][unicode(attr_name)] = unicode(getattr(name, attr_name))
        for task in recursive_node_scan(bom_log.bom.content, u'task'):
            _logger.debug('task: %s' % task)
            _logger.debug('task: %s' % task.id)
            _logger.debug('task: %s' % task.synopsis)
            task_id = u"%s: %s" % (task.id, task.synopsis)
            if not old_tasks.has_key(task_id):
                old_tasks[task_id] = {}
            if hasattr(task, 'xml_attributes'):
                for attr_name, junk_tuple in sorted(task.xml_attributes.iteritems()):
                    _logger.debug('attr_name: %s' % attr_name)
                    old_tasks[task_id][unicode(attr_name)] = unicode(getattr(task, attr_name))
        for project in self._bom.projects:
            for folder in project.folders:
                folders[unicode(folder.instance + "#" + folder.name + ": " + folder.description)] = {u'overridden':u'true'}
                for task in folder.tasks:
                    _logger.debug("task_bom:'%s'" % unicode(task))
                    tasks[unicode(task)] = {u'overridden':u'false'}
            for task in project.tasks:
                _logger.debug("task_bom:'%s'" % unicode(task))
                tasks[unicode(task)] = {u'overridden':u'true'}

        baselines = self._bom.all_baselines()

        self._write_items_with_attributes(content_node, u'baseline', baselines, old_baselines)
        self._write_items_with_attributes(content_node, u'folder', folders, old_folders)
        self._write_items_with_attributes(content_node, u'task', tasks, old_tasks)
        
        out = open(path, 'w')
        doc.xml(out, indent='yes')
        out.close()
Example #9
0
 def startDocument(self):
     self._root = amara.create_document()
     self._current_el = self._root
     self._current_level = 0
Example #10
0
 def __init__(self, out, encoding=ENCODING):
     xss.XMLGenerator.__init__(self, out, encoding)
     self._root = amara.create_document()
     self._current_el = self._root
     self._current_level = 0
Example #11
0
 def startDocument(self):
     self._root = amara.create_document()
     self._current_el = self._root
     self._current_level = 0
Example #12
0
 def __init__(self, out, encoding=ENCODING):
     xss.XMLGenerator.__init__(self, out, encoding)
     self._root = amara.create_document()
     self._current_el = self._root
     self._current_level = 0