Beispiel #1
0
    def toXMLdoc(self):
        # get cues xml
        # self.cuelist = ET.parse('/home/mac/Shows/CharTest/CharTest_cuesx.xml')
        self.cuelist = ET.parse('/home/mac/Shows/Fiddler/Fiddler_cuesx.xml')
        self.cuelist_root = self.cuelist.getroot()
        self.cues = self.cuelist_root.findall(".cues/cue")
        # get char xml
        # self.charlist = ET.parse('/home/mac/Shows/CharTest/CharTest_char.xml')
        self.charlist = ET.parse(
            '/home/mac/Shows/Fiddler/FiddlerChar_char.xml')
        self.charlist_root = self.charlist.getroot()
        self.chars = self.charlist_root.findall(".chars/char")

        showcontrol = ET.Element('showcontrol')
        newcues = ET.SubElement(showcontrol, 'cues')
        ET.SubElement(newcues, 'version').text = '1.0'
        for cue in self.cues:
            cue_uuid = cue.get('uuid')

            cue = ET.SubElement(newcues, 'cue', attrib={'uuid': cue_uuid})
            for char in self.chars:
                char_uuid = char.get('uuid')
                newchar = ET.SubElement(cue,
                                        'char',
                                        attrib={'uuid': char_uuid})
                ET.SubElement(newchar, 'mute').text = '1'
                ET.SubElement(newchar, 'onstage').text = '0'
                ET.SubElement(newchar, 'level').text = '0'
                ET.SubElement(newchar, 'eq', attrib={'uuid': 'eq uuid'})
                ET.SubElement(newchar,
                              'routing',
                              attrib={'uuid': 'routing uuid'})
        return showcontrol
Beispiel #2
0
    def __init__(self, cfgdict):
        self.logger = logging.getLogger('ShowConf')
        self.logger.info('In ShowConf init.')
        self.cfgdict = cfgdict
        self.settings = {}
        self.equipment = {}
        showconf_file = self.cfgdict['configuration']['project'][
            'folder'] + '/' + self.cfgdict['configuration']['project']['file']
        self.logger.debug(showconf_file)
        tree = ET.parse(showconf_file)
        self.doc = tree.getroot()
        # print(doc)
        self.projecttodict()
        self.logger.info('settings dictionary: {}'.format(self.settings))
        self.equiptodict()
        self.logger.info('equipment dictionary: {}'.format(self.equipment))
        # #Get mixer chan to actor/char map file name
        # mxrmap = self.doc.find('mixermap')
        # attribs = mxrmap.attrib
        # self.settings["mxrmap"] = attribs['file']

        #Get mixer chan to actor/char map file name
        # cues = self.doc.find('cuefile')
        # attribs = cues.attrib
        # self.settings["cuefile"] = attribs['file']

        # print(self.settings)
        # self.name = self.doc.find('title')
        # print('ShowConf.__init__ name: ',self.name.text)
        # self.settings['title'] = self.name.text
        return
Beispiel #3
0
    def __init__(self, mixerconf_file, mixername, mixermodel):
        #
        # dictionary of input sliders, index format: [Chnn]
        # each entry is a InputControl object
        self.inputsliders = {}

        # dictionary of output sliders, index format: [Chnn]
        # each entry is a OutputControl object
        self.outputsliders = {}

        # dictionary of mutestyle for the mixer
        # mutestyle referes to how the mixer indicates the channel is muted
        # for example, the Yamaha 01V indicates a channel is un-muted with an illuminated light
        # other mixer indicate a muted channel with an illuminated light
        # mutestyle['mutestyle'] will be the string 'illuminated' or 'non-illumnated'
        #                        as read from <mixerdefs>.xml for each particular mixer
        # for mutestyle['illuminated'], mutestyle['mute'] will be 0, mutestyle['unmute'] will be 1
        # for mutestyle['non-illuminated'], mutestyle['mute'] will be 1, mutestyle['unmute'] will be 0
        self.mutestyle = {}

        mixerdefs = ET.parse(mixerconf_file)
        mixers = mixerdefs.getroot()
        #print('mixers: ' + str(mixers))
        for mixer in mixers:
            #print(mixer.attrib)
            mxattribs = mixer.attrib
            if 'model' in mxattribs.keys():
                if mxattribs['model'] == mixermodel and mxattribs['mfr'] == mixername:
                    #print('found')
                    break
        self.protocol = mixer.find('protocol').text
        #print('protocol: ' + self.protocol)
        self.mutestyle['mutestyle'] = mixer.find('mutestyle').text
        if self.mutestyle['mutestyle'] == 'illuminated':
            self.mutestyle['mute'] = 0
            self.mutestyle['unmute'] = 1
        else:
            self.mutestyle['mute'] = 1
            self.mutestyle['unmute'] = 0
        ports = mixer.findall('port')
        for port in ports:
            portattribs = port.attrib
            #print(portattribs)
            if portattribs['type'] == 'input':
                #print(portattribs['cnt'])
                self.input_count = int(portattribs['cnt'])
                #print(self.input_count)
                for x in  range(1, self.input_count + 1):
                    sldr = InputControl(x,'In' + '{0:02}'.format(x))
                    self.inputsliders['Ch' + '{0:02}'.format(x)] = sldr
            elif portattribs['type'] == 'output':
                #print(portattribs['cnt'])
                self.output_count = int(portattribs['cnt'])
                #print(self.output_count)
                for x in  range(1, self.output_count + 1):
                    sldr = OutputControl(x,'Out' + '{0:02}'.format(x))
                    self.outputsliders['Ch' + '{0:02}'.format(x)] = sldr 
                    
        #print(self.inputsliders)
 def __init__(self, cuefilename):
     '''
     Constructor
     cuelist is a tree object with all cues for the show
     '''
     self.cuelist = ET.parse(cuefilename)
     self.currentcueindex = 0
     self.previewcueindex = 0
Beispiel #5
0
 def __init__(self, cuefilename):
     '''
     Constructor
     cuelist is a tree object with all cues for the show
     '''
     self.cuelist = ET.parse(cuefilename)
     self.currentcueindex = 0
     self.previewcueindex = 0
    def __init__(self, mixerconf_file, mixername, mixermodel):
        #
        # dictionary of input sliders, index format: [Chnn]
        # each entry is a InputControl object
        self.inputsliders = {}

        # dictionary of output sliders, index format: [Chnn]
        # each entry is a OutputControl object
        self.outputsliders = {}

        # dictionary of mutestyle for the mixer
        # mutestyle referes to how the mixer indicates the channel is muted
        # for example, the Yamaha 01V indicates a channel is un-muted with an illuminated light
        # other mixer indicate a muted channel with an illuminated light
        # mutestyle['mutestyle'] will be the string 'illuminated' or 'non-illumnated'
        #                        as read from <mixerdefs>.xml for each particular mixer
        # for mutestyle['illuminated'], mutestyle['mute'] will be 0, mutestyle['unmute'] will be 1
        # for mutestyle['non-illuminated'], mutestyle['mute'] will be 1, mutestyle['unmute'] will be 0
        self.mutestyle = {}

        mixerdefs = ET.parse(mixerconf_file)
        mixers = mixerdefs.getroot()
        #print('mixers: ' + str(mixers))
        for mixer in mixers:
            #print(mixer.attrib)
            mxattribs = mixer.attrib
            if 'model' in mxattribs.keys():
                if mxattribs['model'] == mixermodel and mxattribs[
                        'mfr'] == mixername:
                    #print('found')
                    break
        self.protocol = mixer.find('protocol').text
        #print('protocol: ' + self.protocol)
        self.mutestyle['mutestyle'] = mixer.find('mutestyle').text
        if self.mutestyle['mutestyle'] == 'illuminated':
            self.mutestyle['mute'] = 0
            self.mutestyle['unmute'] = 1
        else:
            self.mutestyle['mute'] = 1
            self.mutestyle['unmute'] = 0
        ports = mixer.findall('port')
        for port in ports:
            portattribs = port.attrib
            #print(portattribs)
            if portattribs['type'] == 'input':
                #print(portattribs['cnt'])
                self.input_count = int(portattribs['cnt'])
                #print(self.input_count)
                for x in range(1, self.input_count + 1):
                    sldr = InputControl(x, 'In' + '{0:02}'.format(x))
                    self.inputsliders['Ch' + '{0:02}'.format(x)] = sldr
            elif portattribs['type'] == 'output':
                #print(portattribs['cnt'])
                self.output_count = int(portattribs['cnt'])
                #print(self.output_count)
                for x in range(1, self.output_count + 1):
                    sldr = OutputControl(x, 'Out' + '{0:02}'.format(x))
                    self.outputsliders['Ch' + '{0:02}'.format(x)] = sldr
Beispiel #7
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)
 def __init__(self, mixerconf_file):
     self.mixerdefsorig = ET.parse(mixerconf_file)
     self.mixerdefs = copy.deepcopy(self.mixerdefsorig)
     self.mixers = self.mixerdefs.getroot()
     self.mixer_count = len(self.mixers)
     self.mfr_list = []
     self.model_list = []
     self.protocol = ''
     self.mutestyle = ''
     self.s_countbase = ''
     self.mixer_list()
     self.selected_mixer = None
     self.defs_modified = False
 def __init__(self):
     self.logger = logging.getLogger('Show')
     self.logger.info('In configuration.init')
     self.logger.info('message from configuration')
     self.settings = {}
     tree = ET.parse(CFG_PATH)
     self.doc = tree.getroot()
     self.logger.debug(ET.tostring(self.doc))
     #print('Root tag: {0}'.format(self.doc.tag))
     #print('{0} attribs: {1}'.format(self.doc.tag, self.doc.attrib))
     self.logger.debug('Root tag: {0}'.format(self.doc.tag))
     self.logger.debug('{0} attribs: {1}'.format(self.doc.tag,
                                                 self.doc.attrib))
     self.cfgdict = self.toDict()
     return
Beispiel #10
0
def getmixermap(mapfile):
    global firstuuid
    mixermap = ET.parse(mapfile)
    mixermap_root = mixermap.getroot()
    firstmap = mixermap_root.find('mixermap')
    firstuuid = firstmap.get('uuid')
    charcount = int(firstmap.get('charcount'))

    chars = firstmap.findall('input')
    chardict = {}
    for char in chars:
        cnum = int(char.attrib['chan'])
        mxrid = int(char.attrib['mixerid'])
        char = char.attrib['char']
        chardict[char] = 'M{0:1}ch{1:02}'.format(mxrid, cnum)
    return chardict
Beispiel #11
0
 def __init__(self, cuefilename, chancount):
     '''
     Constructor
     cuelist is a tree object with all cues for the show
     mutestate is a dictionary that maintains the current mute state
             based on what entrances and exits appear in the cuelist
     levelstate is a dictionary that maintains the current level of each slider
     currentindex is an integer that indicates the current cue
     previewcueindex is an integer that indicates the cue being previewed , if a preview is active 
     '''
     self.cuelist = ET.parse(cuefilename)
     self.mutestate = {}
     for x in range(1, chancount + 1):
         self.mutestate['ch' + '{0}'.format(x)] = 0
     self.levelstate = {}
     self.currentcueindex = 0
     self.previewcueindex = 0
    def toXMLdoc(self):
        # get cues xml
        # self.cuelist = ET.parse('/home/mac/Shows/CharTest/CharTest_cuesx.xml')
        self.cuelist = ET.parse('/home/mac/Shows/Fiddler/Fiddler_cuesx.xml')
        self.cuelist_root = self.cuelist.getroot()
        self.cues = self.cuelist_root.findall(".cues/cue")

        for cue in self.cues:
            cue_id_element = cue.find('.Id')
            cue_id = cue_id_element.text
            if '.' in cue_id:
                page, line = cue_id.split('.')
            else:
                page = ''
                line = cue_id
            print('integer: {}, fraction: {}'.format(page, line))
            cue_id_element.text = line
        return
Beispiel #13
0
 def __init__(self, mapfilename):
     '''
     Constructor
     '''
     logging.info('In MixerCharMap.')
     self.maptree = ET.parse(mapfilename)
     self.maproot = self.maptree.getroot()
     self.current_map_index = 0
     self.previous_map_index = 0
     maps = self.maproot.findall("./mixermap")
     self.map_list = []
     for key in range(len(maps)):
         print(key)
         map = self.maproot.find("./mixermap[@count='" + str(key) + "']")
         self.map_list.append(map.get('uuid'))
     print(self.map_list)
     self.mapcount = len(self.map_list)  # this is not the count= in the mixermap element,
                                         # but the count of mixermaps in the xml file
     maps = None
    def __init__(self, showconf_file):
        self.settings = {}
        tree = ET.parse(showconf_file)
        doc = tree.getroot()
        print(doc)

#Get mixer info
        mixer = doc.find('mixer')
        print('ShowConf::', mixer.attrib)
        mxattribs = mixer.attrib
        try:
            print(mxattribs['model'])
            self.settings['mxrmodel'] = mxattribs['model'] 
        except:
            self.settings['mxrmodel'] = ''
            print('No Mixer model defined')
        if self.settings['mxrmodel'] == '':
            self.settings['mxrmodel'] = ''
        try:
            print(mxattribs['mfr'])
            self.settings['mxrmfr'] = mxattribs['mfr']
        except:
            self.settings['mxrmfr'] = 'Default'
            print('No Mixer manufacturer defined')
        if self.settings['mxrmfr'] == '':
            self.settings['mxrmfr'] = 'Default'

        #Get mixer chan to actor/char map file name
        mxrmap = doc.find('mixermap')
        attribs = mxrmap.attrib
        self.settings["mxrmap"] = attribs['file']

        #Get mixer chan to actor/char map file name
        mxrcues = doc.find('mixercues')
        attribs = mxrcues.attrib
        self.settings["mxrcue"] = attribs['file']
        
        print(self.settings)
        self.name = doc.find('name')
        print('ShowConf.__init__ name: ',self.name.text)
        self.settings['name'] = self.name.text
Beispiel #15
0
 def setup_cast(self, charfilename):
     """Load the specified xml file """
     logging.info('In Chars setup_cast')
     if not path.isfile(charfilename):
         of = open(charfilename, mode='w')
         of.write('<?xml version="1.0" encoding="UTF-8"?>\n')
         of.write('<show_control>\n')
         of.write('    <version>1.0</version >\n')
         of.write('    <chars>\n')
         of.write('      <char uuid="{}">\n'.format(uuid.uuid4()))
         of.write('       <name>""</name>\n')
         of.write('       <actor>""</actor>\n')
         of.write('      </char>\n')
         of.write('    </chars>\n')
         of.write('</show_control>\n')
         of.close()
     self.char_element_tree = ET.parse(charfilename)
     self.charlist_root = self.char_element_tree.getroot()
     self.chars_element = self.charlist_root.find('chars')
     self.char_element_list = self.chars_element.findall('char')
     self.charcount = len(self.char_element_list)
     return
Beispiel #16
0
    def build_char_file(self):
        self.maptree = ET.parse('/home/mac/SharedData/ShowSetups/Shows/Fiddler/MixerMap.xml')
        self.maproot = self.maptree.getroot()
        maps = self.maproot.findall("./mixermap")
        self.map_list = []
        map = self.maproot.find("./mixermap[@count='0']")
        inputs = map.findall('input')
        # build file name
        name = 'FiddlerChar'
        cf = os.path.join('/home/mac/SharedData/ShowSetups/Shows/Fiddler/', '{}_char.xml'.format(name))
        of = open(cf,mode='w')
        of.write('<?xml version="1.0" encoding="UTF-8"?>\n')
        of.write('<show_control>\n')
        of.write('    <version>1.0</version >\n')
        of.write('    <chars>\n')
        for mxrin in inputs:
            actor = mxrin.get('actor')
            char = mxrin.get('char')
            print(actor,char)
            of.write('      <char uuid="{}">\n'.format(uuid.uuid4()))
            of.write('       <name>"{}"</name>\n'.format(char))
            of.write('       <actor>"{}"</actor>\n'.format(actor))
            of.write('      </char>\n')
        of.write('    </chars>\n')
        of.write('</show_control>\n')
        of.close()

        # self.mm_element_list = ET.parse('/home/mac/SharedData/ShowSetups/Shows/CharTest/MixerMap.xml')
        # self.mm_list_root = self.char_element_list.getroot()
        # self.mm__element = self.charlist_root.find('showcontrol')
        # self.char_element_list = self.chars_element.findall('char')
        # tf = os.path.join(SHOWS, 'CharTest', '{}_char.xml'.format('FromMixerMap'))
        #
        # for char in self.char_element_list:
        #     print()
        return
 def reload(self):
     tree = ET.parse(CFG_PATH)
     self.doc = tree.getroot()
Beispiel #18
0
 chan_name_list = list(a['name'].lower() for a in mixers[0].mxrconsole)
 level_list = []
 for count, chan in enumerate(chan_name_list):
     level_list.append('M{0}{1}:0'.format(0,chan))
 level_val = ','.join(level_list)
 mixermapdict = getmixermap('/home/mac/Shows/Fiddler/MixerMap_full.xml')
 mutes = {}
 for chan in chan_name_list:
     print('Chan Name: {}'.format(chan))
     mxrchnnam = 'M{0}{1}'.format(0,chan)
     mutes[mxrchnnam] = 0
 # for chan in mixermapdict:
 #     print('Char: {0} Chan: {1}'.format(chan, mixermapdict[chan]))
 #     mutes[mixermapdict[chan]] = 0
 # newdoc = ET.Element('show_control')
 templatedoc = ET.parse('/home/mac/Shows/Fiddler/Template_cues.xml')
 newdoc = templatedoc.getroot()
 templatecues = newdoc.findall('./Cue')
 cue_num_offset = len(templatecues)
 with open('/home/mac/Shows/Fiddler/Fiddler_katie_txt-1.csv', newline='') as f:
     cuereader = csv.DictReader(f)
     for cue_num, row in enumerate(cuereader):
         print('{0},{1},{2},{3}'.format(row['A'],row['S'],row['Page'],row['Id']))
         newcue = {}
         #newcue['cue'] = {'uuid' : '{0}'.format(uuid.uuid4()), 'num' : '{0:003}'.format(cue_num)}
         newcueelements = {}
         newcueelements['Id'] = row['Id']
         newcueelements['Act'] = row['A']
         newcueelements['Scene'] = row['S']
         newcueelements['Page'] = row['Page']
         newcueelements['Title'] = row['Title']
Beispiel #19
0
    def equiptodict(self):
        equip_files_dict = self.settings['equipment']
        key_list = list(equip_files_dict.keys())
        key_list.sort()
        key_count = len(key_list)
        mixer_dict = {}
        program_dict = {}
        for key in key_list:
            print(equip_files_dict[key])
            equipment_file = self.cfgdict['configuration']['project'][
                'folder'] + '/' + equip_files_dict[key]
            tree = ET.parse(equipment_file)
            equipdoc = tree.getroot()
            # print(doc)
            version_element = equipdoc.find('./equipment/version')
            version = version_element.text
            self.equipment['version'] = version
            # handle mixers
            mixers_dict = equipdoc.findall('./equipment/mixers/mixer')
            for mixer in mixers_dict:
                # if there is one or more mixer elements
                # the following elements are required to be there
                id = int(mixer.get('id'))
                mfr = mixer.find('./mfr').text
                model = mixer.find('./model').text

                # check for IP_address
                try:
                    IP_address = mixer.find('./IP_address').text
                except AttributeError:
                    # if there is none and the mixer was previously found use that value
                    if id in mixer_dict:
                        IP_address = mixer_dict[id]['IP_address']
                    else:
                        IP_address = None

                try:
                    port = mixer.find('./port').text
                except AttributeError:
                    # if there is none and the mixer was previously found use that value
                    if id in mixer_dict:
                        port = mixer_dict[id]['port']
                    else:
                        port = None

                # check this element for a MIDI address
                try:
                    midi_address = mixer.find('./MIDI_address').text
                except AttributeError:
                    # if there is none and the mixer was previously found use that value
                    if id in mixer_dict:
                        midi_address = mixer_dict[id]['MIDI_address']
                    else:
                        # else just set it to None
                        midi_address = None
                mixer_dict[id] = {
                    'mfr': mfr,
                    'model': model,
                    'IP_address': IP_address,
                    'port': port,
                    'MIDI_address': midi_address
                }
                pass
            self.equipment['mixers'] = mixer_dict
            # handle programs
            programs_dict = equipdoc.findall('./equipment/program')
            for program in programs_dict:
                id = program.get('id')
                if id not in self.equipment:
                    try:
                        app = program.find('./app').get('href')
                    except:
                        app = None
                    try:
                        args = program.find('./args').text
                    except:
                        args = None
                    try:
                        setup = program.find('./setup').text
                    except:
                        setup = None
                    portnum = program.find('./port').text
                    IP_address = program.find('./IP_address').text
                    midi_address = program.find('./MIDI_address').text
                    program_dict[id] = {
                        'port': portnum,
                        'IP_address': IP_address,
                        'MIDI_address': midi_address,
                        'app': app,
                        'args': args,
                        'setup': setup
                    }
                    pass
                else:
                    # todo - mac throw warning second find ignored
                    pass
        self.equipment['program'] = program_dict

        return
Beispiel #20
0
#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)
        for subchild in child:
            print ("subchild.tag=", subchild.tag,
               " | subchild.attrib=",subchild.attrib,
               " | subchild.text=", subchild.text)
    else:
        print ("child.tag=", child.tag,
Beispiel #21
0
 def get_xml_for_file(cls, f):
     """ Returns a tuple containing the XML tree and root objects """
     tree = ET.parse(f)
     return tree, tree.getroot()
Beispiel #22
0
######################################

lumi = 0  # integrated luminosity, in fb^-1
signalregions = {}

analysisinfo_path = analysis_path + "/Build/SampleAnalyzer/User/Analyzer/" + \
    analysis_name + ".info"

try:
    info_input = open(analysisinfo_path)
except IOError as e:
    print 'I/O error({0}): {1}'.format(e.errno, e.strerror)
    print 'Cannot open the XML info file "' + analysisinfo_path + '".'
    sys.exit()

info_tree = ET.parse(info_input)
info_input.close()

info_root = info_tree.getroot()
if info_root.tag != "analysis":
    print 'Invalid XML info file "' + analysisinfo_path + '".'
    print 'Root tag should be <analysis>, not <' + info_root.tag + '>.'
    sys.exit()
if info_root.attrib["id"] != analysis_name:
    print 'Invalid XML info file "' + analysisinfo_path + '".'
    print 'Analysis id in root tag <analysis> should be "' + analysis_name + \
          '", not "' + info_root.attrib["id"] + '".'
    sys.exit()

for child in info_root:
    # for <lumi> tag
Beispiel #23
0
 def __init__(self, mapfilename):
     '''
     Constructor
     '''
     self.maplist = ET.parse(mapfilename)
     
Beispiel #24
0
 def setup_cuechar(self, filename):
     logging.info('In CueList setup_cues')
     self.cuecharlist = ET.parse(filename)
     self.cuecharlist_root = self.cuecharlist.getroot()
     cues = self.cuecharlist.findall('.cues/cue')
     self.cuecharcount = len(cues)
Beispiel #25
0
            #level1_dict[child_attribs['id']] = ''
        else:  # this element has no children
            # check for text and attributes
            level1_attribs = level1_element.attrib
            print('tag: {0} text: {1}'.format(level1_element.tag,
                                              level1_element.text.strip()))
            gen_dict[level1_element.tag] = level1_element.text.strip()
    for item in t_iter:
        itmtag = item.tag
        itmtxt = item.text.strip()
        itmatrb = item.attrib
        itmchildrn = list(item)
        print(itmtag, itmtxt, itmatrb)
    return 10


def todict(item):
    cdict = {}
    for v, k in item:
        cdict[v] = k
    print(cdict)
    return cdict


if __name__ == "__main__":
    tree = ET.parse(CFG_PATH)
    d = etree_to_dict2(tree)
    tree = ET.parse('/home/mac/Shows (copy 1)/Pauline/MixerMap.xml')
    d = etree_to_dict2(tree)

    pass
Beispiel #26
0
    def __init__(self, mixerconf_file, mixername, mixermodel, mixeraddress):
        logging.info('MixerConf __init__')
        self.mutestyle = {}
        ''' dictionary of mutestyle  and values that activate a mute or unmute for the mixer
        mutestyle referes to how the mixer indicates the channel is muted
        for example, the Yamaha 01V indicates a channel is un-muted with an illuminated light
        other mixer indicate a muted channel with an illuminated light
        mutestyle['mutestyle'] will be the string 'illuminated' or 'dark'
                               as read from <mixerdefs>.xml for each particular mixer
        for mutestyle['mute'] will be the value to send to mute the mixer
        for mutestyle['unmute'] will be the value to send to unmute the mixer'''
        '''mxrstrips is a dictionary of controls for a type of strip.
        mxrstrips will have a key for each strip type (input, output, auuxin, etc.)
        each strip type will have a dictionary of it's associated control objects.
        Controls objects are based on the protocol of the mixer. (See MixerControl.py)'''
        self.mxrstrips = {}
        '''mxrconsole is a list of all the strips on the mixer.
        This is used for the layout on the GUI and to work on a sigle strip
        or interate through all strips on the mixer.
        Each element of the list will have a dictionary with the strip name and strip type'''
        self.mxrconsole = []

        mixerdefs = ET.parse(mixerconf_file)
        mixers = mixerdefs.getroot()
        #print('mixers: ' + str(mixers))
        for mixer in mixers:
            print(mixer.attrib)
            mxattribs = mixer.attrib
            if 'model' in mxattribs.keys():
                if mxattribs['model'] == mixermodel and mxattribs[
                        'mfr'] == mixername:
                    #print('found')
                    break
        self.protocol = mixer.find('protocol').text
        #print('protocol: ' + self.protocol)
        self.IP = ''
        self.PORT = 0
        self.MIDICHAN = 0
        if self.protocol == 'osc':
            self.IP, port = mixeraddress.split(',')
            self.PORT = int(port)
        elif self.protocol == 'midi':
            self.MIDICHAN = int(mixeraddress)
        mutestyleattribs = mixer.find('mutestyle').attrib
        if 'illuminated' in mutestyleattribs:
            self.mutestyle['mutestyle'] = 'illuminated'
        else:
            self.mutestyle['mutestyle'] = 'dark'
        self.mutestyle['mute'] = int(mutestyleattribs['mute'])
        self.mutestyle['unmute'] = int(mutestyleattribs['unmute'])

        s_countbase = mixer.find('countbase').text
        i_countbase = int(s_countbase.replace('\"', ''))
        firstchan = 1  # wonky way to fix issue with X32: CH1 >> 01, yamaha: CH1 is 0 offset from a midi value
        if i_countbase == 1:
            firstchan = 0
        strips = mixer.findall('strip')
        for strip in strips:
            stripattribs = strip.attrib
            self.mxrstrips[stripattribs['type']] = {}
            for cntrltype in supported_controls:
                try:
                    cntrl = strip.find(cntrltype)
                    cntrlattribs = cntrl.attrib
                    cntrlcls = ControlFactory.create_control(
                        cntrltype, self.protocol)
                    commandstring = cntrlattribs['cmd']
                    if self.protocol == 'midi' and cntrlattribs['cmd'] != '':
                        controlchange, changenumbase, val = cntrlattribs[
                            'cmd'].split(',')
                        commandstring = '{0},{1},{2}'.\
                                            format(controlchange.replace('#', '{:1x}'.format(self.MIDICHAN)),\
                                            changenumbase, val)
                    cntrlcls.fill(cntrlattribs['cmdtyp'], commandstring,
                                  cntrlattribs['range'], cntrlattribs['anoms'])
                    self.mxrstrips[stripattribs['type']].update(
                        {cntrltype: cntrlcls})
                except:
                    pass
            self.cntrlcount = int(stripattribs['cnt'])
            for x in range(i_countbase, self.cntrlcount + i_countbase):
                self.mxrconsole.append({
                    'name':
                    stripattribs['name'] + '{0:02}'.format(x + firstchan),
                    'type':
                    stripattribs['type'],
                    'channum':
                    x
                })
 def __init__(self, mapfilename):
     '''
     Constructor
     '''
     self.maplist = ET.parse(mapfilename)
Beispiel #28
0
                result = { "$" : parseChildren(x.getchildren()) }
            else:
                result = dict(prepend.items() + { "$" : parseChildren(x.getchildren()) }.items())

        if tag in final:
            if type(final[tag]) is not types.ListType:
                final[tag] = [final[tag]]

            final[tag].append(result)
        else:
            final[tag] = result

    return final

#print parseChildren([ET.XML('<tag>txt-value</tag>')])
#print parseChildren([ET.XML('<tag><tag2>txt-value</tag2></tag>')])
#print parseChildren([ET.XML('<tag><tag2>txt-value1</tag2><tag2>txt-value2</tag2></tag>')])
#print parseChildren([ET.XML('<tag ns="ns-value" />')])
#print parseChildren([ET.XML('<tag xmlns:ns="ns-value" />')])
#print parseChildren([ET.XML('<tag xmlns="root-value" xmlns:ns="ns-value" />')])
#print parseChildren([ET.XML('<ns:tag attr="attr-value" />')])
#print parseChildren([ET.XML('<tag attr="attr-value">txt-value</tag>')])
#print parseChildren([ET.XML('<ns:tag attr="attr-value">txt-value</tag>')])
import sys

x = ET.parse(sys.argv[1]).getroot()
print parseChildren([x])
print ET.tostring(x)


Beispiel #29
0
    def GetCLs(self, PADdir, dirname, analysislist, name, xsection, setname):
        self.logger.info('   Calculation of the exclusion CLs')
        if xsection <= 0:
            self.logger.info(
                '   Signal xsection not defined. The 95% excluded xsection will be calculated.'
            )
        try:
            from lxml import ET
        except:
            try:
                import xml.etree.ElementTree as ET
            except:
                self.logger.warning(
                    'lxml or xml not available... the CLs module cannot be used'
                )
                return False
        ## preparing the output file
        if os.path.isfile(dirname + '/Output/' + setname + '/CLs_output.dat'):
            mysummary = open(
                dirname + '/Output/' + setname + '/CLs_output.dat', 'a')
        else:
            mysummary = open(
                dirname + '/Output/' + setname + '/CLs_output.dat', 'w')
            if xsection <= 0:
                mysummary.write("# analysis name".ljust(30, ' ') + "signal region".ljust(50,' ') + \
                 'sig95(exp)'.ljust(15, ' ') + 'sig95(obs)'.ljust(15, ' ') +' ||    ' + 'efficiency'.ljust(15,' ') +\
                 "stat. unc.".ljust(15,' ') + "syst. unc.".ljust(15," ") + "tot. unc.".ljust(15," ") + '\n')

            else:
                mysummary.write("# analysis name".ljust(30, ' ') + "signal region".ljust(50,' ') + \
                 "best?".ljust(10,' ') + 'sig95(exp)'.ljust(15,' ') + 'sig95(obs)'.ljust(15, ' ') +\
                 'CLs'.ljust(10,' ') + ' ||    ' + 'efficiency'.ljust(15,' ') +\
                 "stat. unc.".ljust(15,' ') + "syst. unc.".ljust(15," ") + "tot. unc.".ljust(15," ") + '\n')
        ## running over all analysis
        for analysis in analysislist:
            ## Reading the info file
            if not os.path.isfile(PADdir +
                                  '/Build/SampleAnalyzer/User/Analyzer/' +
                                  analysis + '.info'):
                self.logger.warning('Info file missing for the ' + analysis +
                                    ' analysis. Skipping the CLs calculation')
                return False
            info_input = open(PADdir + '/Build/SampleAnalyzer/User/Analyzer/' +
                              analysis + '.info')
            try:
                info_tree = ET.parse(info_input)
            except:
                self.logger.warning(
                    'Info file for ' + analysis +
                    ' corrupted. Skipping the CLs calculation.')
                return False
            info_input.close()
            lumi, regions, regiondata = self.ReadInfoFile(info_tree, analysis)
            if lumi == -1 or regions == -1 or regiondata == -1:
                self.logger.warning(
                    'Info file for ' + analysis +
                    ' corrupted. Skipping the CLs calculation.')
                return False
            ## reading the cutflow information
            regiondata = self.ReadCutflow(
                dirname + '/Output/' + name + '/' + analysis + '/Cutflows',
                regions, regiondata)
            if regiondata == -1:
                self.logger.warning(
                    'Info file for ' + analysis +
                    ' corrupted. Skipping the CLs calculation.')
                return False
            ## performing the calculation
            regiondata = self.ComputesigCLs(regiondata, regions, lumi, "exp")
            regiondata = self.ComputesigCLs(regiondata, regions, lumi, "obs")
            xsflag = True
            if xsection > 0:
                xsflag = False
                regiondata = self.ComputeCLs(regiondata, regions, xsection,
                                             lumi)
            ## writing the output file
            self.WriteCLs(dirname, analysis, regions, regiondata, mysummary,
                          xsflag)
            mysummary.write('\n')

        ## closing the output file
        mysummary.close()

        return True