Exemplo n.º 1
0
    def write(self, newxml,  revision=True, filename=''):
        """save a new characters file.
        If revision is true, save with a revision number
        i.e. this essentially makes a backup of the config file,
        typically call with revision=True before an add or insert
        If revision=False, save
        in the file specified by filename"""
        newdoctree = ET.ElementTree(newxml)
        if filename == '':
            logging.debug('Configuration not saved, no filename provided!')
            msgBox = QtWidgets.QMessageBox()
            msgBox.setText('Configuration not saved, no filename provided!')
            msgBox.exec_()
            return
        rev = 1
        if revision:
            oldroot, extension = path.splitext(filename)
            while path.isfile(oldroot + '-{0}'.format(rev) + extension):
                rev += 1
            shutil.copyfile(filename, oldroot + '-{0}'.format(rev) + extension)
            logging.debug('Configuration written to: ' + oldroot + '-{0}'.format(rev) + extension)
        newdoctree.write(filename, xml_declaration=True)
        logging.debug('Configuration written to: ' + filename)

        return
Exemplo n.º 2
0
 def setup_cues(self, cuefilename):
     logging.info('In CueList setup_cues')
     self.cuetree = ET.ElementTree(file=cuefilename)
     self.cuelist = ET.parse(cuefilename)
     self.cuelist_root = self.cuelist.getroot()
     self.currentcueindex = 0
     self.previouscueindex = 0
     self.previewcueindex = 0
     self.selectedcueindex = None
     #self.cues_element = self.cuelist_root.find('cues')
     #self.cuelist.find(".cues/cue[@num='001']")
     cues = self.cuelist.findall('.cues/cue')
     self.cuecount = len(cues)
Exemplo n.º 3
0
 def get_xml_for_string(cls, s):
     """ Returns a tuple containing the XML tree and root objects """
     root = ET.fromstring(s)
     return ET.ElementTree(element=root), root
Exemplo n.º 4
0
elem = ET.SubElement(root, "team_counter")
elem.text = "1"
elem = ET.SubElement(root, "attackpoints")
elem.text = "2"
elem = ET.SubElement(root, "keeperpoints")
elem.text = "3"

#for child in root:
#    print (child.tag, child.attrib)



outFilename = "./output.xml"
html = ET.Element("html")
body = ET.SubElement(html, "body")
ET.ElementTree(root).write(outFilename)
#ET.ElementTree(root).prettyprint(outFilename)
print(ET.tostring(root, pretty_print=True))

filename = "./TeamA.xml"

tree = ET.parse(filename)
elem = tree.getroot()

print ("------- child level by child level ------")
print("elem.tag=",elem.tag, "  elem.attrib=", elem.attrib)
for child in elem:
    if child.tag == "players" :
        print ("child.tag=", child.tag,
               " | child.attrib=",child.attrib,
               " | child.text=", child.text)
Exemplo n.º 5
0
                    logging.info('In {} Exits char: {} not found!'.format(row['Id'],char))
                if char != '' and char in mixermapdict:
                    mixerchan = mixermapdict[char.replace(' ','')]
                    mutes[mixerchan] = 0

            print('mutes: {0}'.format(mutes))
            # print('Entrances: {0}'.format(row['Entrances']))
            # print('Exits: {0}'.format(row['Exits']))
            field = row['OnStage'].replace(' ', '').replace('()', '').split(',')
            muteelementval = ''
            for muteval in mutes:
                muteelementval += '{0}:{1},'.format(muteval, mutes[muteval])
            muteelementval = muteelementval[:-1]
            mutes_sorted = sort_controls( muteelementval )
            newcueelements['Mutes'] = ','.join(mutes_sorted)
            # add dummy <levels> element
            newcueelements['Levels'] = level_val

            OS_clean = re.sub(r'\(.*?\)', '', row['OnStage']).replace(' ','')
            En_clean = re.sub(r'\(.*?\)', '', row['Entrances']).replace(' ','')
            Ex_clean = re.sub(r'\(.*?\)', '', row['Exits']).replace(' ', '')
            print('Onstage: {0}, Entrances: {1}, Exits: {2}'.format(row['OnStage'], row['Entrances'], row['Exits']))
            newcueelements['OnStage'] = OS_clean
            newcueelements['Entrances'] = En_clean
            newcueelements['Exits'] = Ex_clean
            putcuefile(newdoc, newcueelements, cue_num + cue_num_offset)

    newdoctree = ET.ElementTree(newdoc)
    newdoctree.write('/home/mac/Shows/Fiddler/Fiddler_cuesx_txt-1.xml')

    pass