Exemple #1
0
import sys
try:
    import xml.etree.cElementTree as ET
except ImportError:
    import xml.etree.ElementTree as ET

empRec = ET.Element('person')
empRec.attrib['empid'] = "12345"
empRec.attrib['ssn'] = "123456789"
first = ET.SubElement(empRec, 'first')
first.text = "Jack"
last = ET.SubElement(empRec, 'last')
last.text = "Doe"

tree = ET.ElementTree(empRec)
tree.write(sys.stdout)
Exemple #2
0
def metadata_gen(title, dateIni, dateEnd, geographicDesc, westBounding,
                 eastBounding, northBounding, southBounding, params):
    # EML-XML Header
    ET.register_namespace('eml',
                          "eml://ecoinformatics.org/eml-2.1.1")  # some name
    eml = ET.Element("{eml://ecoinformatics.org/eml-2.1.1}eml", system="knb")
    # -Access
    acceso = ET.SubElement(eml, "access", authSystem="knb", order="allowFirst")
    permiso = ET.SubElement(acceso, "allow")
    ET.SubElement(permiso, "principal").text = "public"
    ET.SubElement(permiso, "permission").text = "read"

    # -Dataset Module
    dataset = ET.SubElement(eml, "dataset")
    ET.SubElement(dataset, "title").text = title

    # --Coverage
    coverage = ET.SubElement(dataset, "coverage")

    # ---Geographic Coverage
    coverageG = ET.SubElement(coverage, "geographicCoverage", id='id')
    ET.SubElement(coverageG, "geographicDescription").text = geographicDesc
    ET.SubElement(coverageG, "westBoundingCoordinate").text = westBounding
    ET.SubElement(coverageG, "eastBoundingCoordinate").text = eastBounding
    ET.SubElement(coverageG, "northBoundingCoordinate").text = northBounding
    ET.SubElement(coverageG, "southBoundingCoordinate").text = southBounding

    # ---Temporal Coverage
    coverageT = ET.SubElement(coverage, "temporalCoverage")
    # ---SingleData
    # ----TODO
    # ---rangeOfDates
    rangeOfDates = ET.SubElement(coverageT, "rangeOfDates")
    # ----beginDate
    ET.SubElement(ET.SubElement(rangeOfDates, "beginDate"),
                  "calendarDate").text = dateIni
    # ---endDate
    ET.SubElement(ET.SubElement(rangeOfDates, "endDate"),
                  "calendarDate").text = dateEnd
    # --Dataset type
    fileFormat = "csv"
    if fileFormat == "csv":
        # filename.split(".")[-1]
        dataTable = ET.SubElement(dataset, "dataTable")
        ET.SubElement(dataTable, "FileName").text = title + ".csv"
        dataTable = file_block_csv(title, params, dataTable)

    tree = ET.ElementTree(eml)

    # Escribimos los datos en un archivo or onedata attachement
    fil = config.datasets_path + '/' + geographicDesc + '/' + title + ".xml"
    tree.write(fil, encoding='UTF-8', xml_declaration=True)
    if (config.onedata_mode == 1):
        try:
            token = os.environ['ONECLIENT_AUTHORIZATION_TOKEN']
        except KeyError:
            token = 'ICmASYmuGx6CSPHwkf3s9pXW2szUqJPBPoFEXIKOZ2L00Cg'
        header_json = {
            'X-Auth-Token': token,
            'Content-type': 'application/json'
        }
        try:
            print("%s%smetadata/json/%s/%s/%s" %
                  (config.onedata_url, config.onedata_api,
                   config.onedata_space, geographicDesc, title))
            print(
                eml_to_json("%s/%s/%s.xml" %
                            (config.datasets_path, geographicDesc, title)))
            r = requests.put("%s%smetadata/json/%s/%s/%s" %
                             (config.onedata_url, config.onedata_api,
                              config.onedata_space, geographicDesc, title),
                             headers=header_json,
                             data=eml_to_json(title + ".xml"))
            print("Metadata attachement: %i" % r.status_code)
            os.remove(title + ".xml")
        except requests.exceptions.RequestException as e:
            print(e)
    print(tree)
    def toXml(self, forExecution=False):
        graph = ET.Element("graph", {'id': "Graph"})
        version = ET.SubElement(graph, "version")
        version.text = "1.0"

        # If the XML is made to be saved then set parameters and outputs.
        # If it is made for execution then parameters and outputs are already set.
        if not forExecution:
            self.defineCharacteristics()

        # Set the connections between nodes
        for alg in self.algs.values():
            for output in alg.algorithm.outputs:
                output.setValue(alg.algorithm.nodeID)
            for param in alg.params:
                if isinstance(alg.params[param], ValueFromOutput):
                    alg.algorithm.getParameterFromName(param).setValue(
                        self.algs[alg.params[param].alg].algorithm.nodeID)

        # Save model algorithms
        for alg in self.algs.values():
            self.prepareAlgorithm(alg)

            graph = alg.algorithm.addGPFNode(graph)

            # Save custom names of model outputs
            for out in alg.algorithm.outputs:
                # Only Write operators can save raster outputs
                if alg.algorithm.operator != "Write" and isinstance(
                        out, OutputRaster):
                    if out.name in alg.outputs:
                        QMessageBox.warning(
                            None, self.tr('Unable to save model'),
                            self.
                            tr('Output rasters can only be saved by Write operator. Remove the value of raster output in %s algorithm or add a Write operator'
                               % (alg.algorithm.operator, )))
                        return
                outTag = graph.find('node[@id="' + alg.algorithm.nodeID +
                                    '"]/parameters/' + out.name)
                if outTag is not None:
                    safeOutName = self.getSafeNameForOutput(alg.name, out.name)
                    for modelOutput in self.outputs:
                        if modelOutput.name == safeOutName:
                            outTag.attrib["qgisModelOutputName"] = str(
                                modelOutput.description)
                            break

            # Save also the position and settings of model inputs.
            # They are saved as attributes of relevant parameter XML nodes.
            # This way they do not interfere with the model when it's opened
            # in SNAP.
            for param in alg.params.keys():
                paramValue = str(alg.params[param])
                if paramValue in self.inputs.keys():
                    # Only Read operators can read raster inputs
                    if re.match("sourceProduct\d*",
                                param) and alg.algorithm.operator != "Read":
                        QMessageBox.warning(
                            None, self.tr('Unable to save model'),
                            self.
                            tr('Input rasters can only be loaded by Read operator. Change the value of raster input in %s algorithm to an output of another algorithm'
                               % (alg.algorithm.operator, )))
                        return
                    paramTag = graph.find(
                        'node[@id="' + alg.algorithm.nodeID +
                        '"]/parameters/' +
                        param.replace('!', '').replace('>', '/'))
                    if paramTag is not None:
                        pos = self.inputs[paramValue].pos
                        paramTag.attrib["qgisModelInputPos"] = str(
                            pos.x()) + "," + str(pos.y())
                        paramTag.attrib["qgisModelInputVars"] = str(
                            self.inputs[paramValue].param.todict())

        # Save model layout
        presentation = ET.SubElement(graph, "applicationData", {
            "id": "Presentation",
            "name": self.name,
            "group": self.group
        })
        ET.SubElement(presentation, "Description")
        for alg in self.algs.values():
            node = ET.SubElement(presentation, "node",
                                 {"id": alg.algorithm.nodeID})
            ET.SubElement(node, "displayPosition", {
                "x": str(alg.pos.x()),
                "y": str(alg.pos.y())
            })

        # Make it look nice in text file
        GPFUtils.indentXML(graph)

        return ET.tostring(graph)
tweet_hash = {}
for tweet in tweets:
    tweet_hash[f'data/articles/foxnewspolitics/{tweet["id_str"]}'] = tweet

findex = 0

for fname in files[-25:]:
    tweet_id = fname.split('-')[0]
    f = open(fname, 'rb')
    data = f.read()
    f.close()

    soup = BeautifulSoup(data, 'html.parser')

    article_e = ET.Element("article")
    author_e = ET.SubElement(article_e, "author")
    div = soup.find(class_="author-byline")
    atext = ""
    if div:
        a = div.find("a")
        if a:
            atext = a.text.strip()
    author_e.text = atext
    orientation_e = ET.SubElement(article_e, "orientation")
    orientation_e.text = orientation

    portal_e = ET.SubElement(article_e, "portal")
    portal_e.text = portal

    v_e = ET.SubElement(article_e, "veracity")
Exemple #5
0
                                       str(im_num) + '.' + im_ext),
                          'wb') as wf:
                    for line in rf:
                        wf.write(line)
            # make imnum.xml

            # -get imsize(widht, height, depth)

            # Resimlerin olduğu klasör
            im_cv2 = cv2.imread(
                os.path.join(COCO_images, im_name + '.' + im_ext))
            height, width, depth = im_cv2.shape

            # Form the file

            annotation = ET.Element('annotation')
            ET.SubElement(annotation, 'folder').text = im_dir
            ET.SubElement(annotation,
                          'filename').text = str(im_num) + '.' + im_ext
            ET.SubElement(annotation, 'segmented').text = '0'
            size = ET.SubElement(annotation, 'size')
            ET.SubElement(size, 'width').text = str(width)
            ET.SubElement(size, 'height').text = str(height)
            ET.SubElement(size, 'depth').text = str(depth)

            ob = ET.SubElement(annotation, 'object')
            ET.SubElement(ob, 'name').text = cat_name
            ET.SubElement(ob, 'pose').text = 'Unspecified'
            ET.SubElement(ob, 'truncated').text = '0'
            ET.SubElement(ob, 'difficult').text = '0'
Exemple #6
0
 def test_parse_xml_validate(self):
     expected = ET.Element("test", {"foo": "bar"})
     actual = parse_xml(u"""<test foo="bar"/>""",
                        schema=validate.Schema(xml_element(tag="test", attrib={"foo": text})))
     self.assertEqual(expected.tag, actual.tag)
     self.assertEqual(expected.attrib, actual.attrib)
Exemple #7
0
 def test_parse_xml_ns_ignore(self):
     expected = ET.Element("test", {"foo": "bar"})
     actual = parse_xml(u"""<test foo="bar" xmlns="foo:bar"/>""",
                        ignore_ns=True)
     self.assertEqual(expected.tag, actual.tag)
     self.assertEqual(expected.attrib, actual.attrib)
Exemple #8
0
def dot2rnaml(cts, input_title, file_name):
    try:
        if re.match(">.*.dot", input_title[0]):
            title = input_title[0]
            title = title.replace('.dot', '').replace('>', '')
        else:
            title = "seq_name"

        seq = cts[0]
        pattern = cts[1]

        stack1 = []
        stack2 = []
        stack3 = []
        stack4 = []
        stack5 = []
        stack6 = []
        stack7 = []
        stack8 = []
        stack9 = []
        stack10 = []
        stack11 = []
        pairs = {}

        for i, c in enumerate(pattern):
            if c == '(':
                stack1.append(i + 1)
            elif c == '[':
                stack2.append(i + 1)
            elif c == '{':
                stack3.append(i + 1)
            elif c == '<':
                stack4.append(i + 1)
            elif c == 'A':
                stack5.append(i + 1)
            elif c == 'B':
                stack6.append(i + 1)
            elif c == 'C':
                stack7.append(i + 1)
            elif c == 'D':
                stack8.append(i + 1)
            elif c == 'E':
                stack9.append(i + 1)
            elif c == 'F':
                stack10.append(i + 1)
            elif c == 'G':
                stack11.append(i + 1)
            elif c == ')':
                pairs[i + 1] = stack1.pop()
                pairs[pairs[i + 1]] = i + 1
            elif c == ']':
                pairs[i + 1] = stack2.pop()
                pairs[pairs[i + 1]] = i + 1
            elif c == '}':
                pairs[i + 1] = stack3.pop()
                pairs[pairs[i + 1]] = i + 1
            elif c == '>':
                pairs[i + 1] = stack4.pop()
                pairs[pairs[i + 1]] = i + 1
            elif c == 'a':
                pairs[i + 1] = stack5.pop()
                pairs[pairs[i + 1]] = i + 1
            elif c == 'b':
                pairs[i + 1] = stack6.pop()
                pairs[pairs[i + 1]] = i + 1
            elif c == 'c':
                pairs[i + 1] = stack7.pop()
                pairs[pairs[i + 1]] = i + 1
            elif c == 'd':
                pairs[i + 1] = stack8.pop()
                pairs[pairs[i + 1]] = i + 1
            elif c == 'e':
                pairs[i + 1] = stack9.pop()
                pairs[pairs[i + 1]] = i + 1
            elif c == 'f':
                pairs[i + 1] = stack10.pop()
                pairs[pairs[i + 1]] = i + 1
            elif c == 'g':
                pairs[i + 1] = stack11.pop()
                pairs[pairs[i + 1]] = i + 1

        rnaml = ET.Element("rnaml")
        molecule = ET.SubElement(rnaml, "molecule")
        identity = ET.SubElement(molecule, "identity")
        name = ET.SubElement(identity, "name")
        name.text = str(title)
        sequence = ET.SubElement(molecule, "sequence")
        sequence.set("length", str(len(seq)))
        seq_data = ET.SubElement(sequence, "seq-data")
        seq_data.text = seq
        structure = ET.SubElement(molecule, "structure")

        for i in range(1, len(pattern) + 1):
            if i < pairs.get(i, 0):
                base_pair = ET.SubElement(structure, "base-pair")

                basep5 = ET.SubElement(base_pair, "base-id-p5")
                baseidp5 = ET.SubElement(basep5, "base-id")
                position5 = ET.SubElement(baseidp5, "position")
                position5.text = str(i)

                basep3 = ET.SubElement(base_pair, "base-id-p3")
                baseidp3 = ET.SubElement(basep3, "base-id")
                position3 = ET.SubElement(baseidp3, "position")
                position3.text = str(pairs.get(i, 0))

        tree = ET.ElementTree(rnaml)
        tree.write(file_name + ".xml")
        print("Conversion from (dot) to (rnaml) completed successfully!")
    except:
        print("Invalid input format")
Exemple #9
0
def write_xml(folder, img, objects, topleft, bottomright, savedir):
    image = cv2.imread(img.path)
    height, width, depth = image.shape

    # Building this xml structure
    """
	<annotation>
		<folder>VOC2007</folder>
		<filename>1.jpg</filename>
		<source>
			<database>The VOC2007 Database</database>
			<annotation>PASCAL VOC2007</annotation>
			<image>flickr</image>
			<flickrid>336426776</flickrid>
		</source>
		<owner>
			<flickrid>Elder Timothy Chaves</flickrid>
			<name>Tim Chaves</name>
		</owner>
		<size>
			<width>500</width>
			<height>375</height>
			<depth>3</depth>
		</size>
		<segmented>0</segmented>
		<object>
			<name>person</name>
			<pose>Left</pose>
			<truncated>0</truncated>
			<difficult>0</difficult>
			<bndbox>
				<xmin>135</xmin>
				<ymin>25</ymin>
				<xmax>236</xmax>
				<ymax>188</ymax>
			</bndbox>
		</object>
		<object>
			<name>bicycle</name>
			<pose>Left</pose>
			<truncated>0</truncated>
			<difficult>0</difficult>
			<bndbox>
				<xmin>95</xmin>
				<ymin>85</ymin>
				<xmax>232</xmax>
				<ymax>253</ymax>
			</bndbox>
		</object>
	</annotation>

	"""

    annotation = ET.Element('annotation')
    ET.SubElement(annotation, 'folder').text = folder
    ET.SubElement(annotation, 'filename').text = img.name
    ET.SubElement(annotation, 'segmented').text = '0'
    size = ET.SubElement(annotation, 'size')
    ET.SubElement(size, 'width').text = str(width)
    ET.SubElement(size, 'height').text = str(height)
    ET.SubElement(size, 'depth').text = str(depth)

    # Create Object elements
    for object_, tl, br in zip(objects, topleft, bottomright):
        object_tag = ET.SubElement(annotation, 'object')
        ET.SubElement(object_tag, 'name').text = object_
        ET.SubElement(object_tag, 'pose').text = 'unspecified'
        ET.SubElement(object_tag, 'truncated').text = '0'
        ET.SubElement(object_tag, 'difficult').text = '0'
        bndbox_tag = ET.SubElement(object_tag, 'bndbox')
        ET.SubElement(bndbox_tag, 'xmin').text = str(tl[0])
        ET.SubElement(bndbox_tag, 'ymin').text = str(tl[1])
        ET.SubElement(bndbox_tag, 'xmax').text = str(br[0])
        ET.SubElement(bndbox_tag, 'ymax').text = str(br[1])

    xml_str = ET.tostring(annotation)
    root = etree.fromstring(xml_str)
    xml_str = etree.tostring(root, pretty_print=True)
    if 'png' in img.name:
        save_path = os.path.join(savedir, img.name.replace('.png', '_png.xml'))
    elif 'jpg' in img.name:
        save_path = os.path.join(savedir, img.name.replace('.jpg', '_jpg.xml'))
    elif 'jpeg' in img.name:
        save_path = os.path.join(savedir,
                                 img.name.replace('.jpeg', '_jpeg.xml'))
    with open(save_path, 'wb') as temp_xml:
        temp_xml.write(xml_str)
    return xml_str
Exemple #10
0
# Neueda Task Python script.
# See PyCharm help at https://www.jetbrains.com/help/pycharm/

# Press Shift+F10 to execute it.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

import json as j
from cryptography.fernet import Fernet

with open("../json_file.json") as json_format_file:
    d = j.load(json_format_file)
import xml.etree.cElementTree as e
r = e.Element("Employee")
e.SubElement(r, "Name").text = d["Name"]
e.SubElement(r, "Designation").text = d["Designation"]
e.SubElement(r, "Salary").text = str(d["Salary"])
e.SubElement(r, "Age").text = str(d["Age"])
project = e.SubElement(r, "Projects")
for z in d["Projects"]:
    e.SubElement(project, "Topic").text = z["Topic"]
    e.SubElement(project, "Category").text = z["Category"]
    e.SubElement(project, "Months").text = str(z["Months"])
a = e.ElementTree(r)
a.write("../json_to_xml.xml")


def write_key():
    """Generates a key and save it into a file"""
    key = Fernet.generate_key()
    with open("../key.key", "wb") as key_file:
        key_file.write(key)
Exemple #11
0
def main(filename, verbose, output, logfn, show_data_chunks, xmldir, logdir):
    file = open(filename, 'rb')
    file_size = get_file_size(file)

    riff = chunk.Chunk(file, bigendian=False)

    # get the RIFF  'AVI ' chunk of the file
    riff_name = riff.getname()
    riff_size = riff.getsize()

    log_strings = list()
    if riff_size + 8 < file_size:
        log_s = "The file size ({}) is larger than RIFF 'AVI ' chunk size ({}).".format(
            file_size, riff_size + 8)
        print('WARNING: \n' + log_s)
        log_strings.append(log_s)

    riff_type = riff.read(4)
    riffchunk = ListChunk(riff_name, riff_size, riff_type)
    # parse the chunk. This is a recurrent function over the list chunks in the file
    avi_chunks = search_list(file, riff_size - 4)

    # add the collected chunks
    riffchunk.add_subchunks(avi_chunks)

    # xml root tag
    root = ET.Element("root")
    title = filename.split('/')[-1]
    root.set('filename', title)
    root.set('size', str(file_size))

    # xml tag for the RIFF chunk
    rifftree = ET.SubElement(root, "RIFF")
    rifftree.set('type', riff_type.decode('utf-8'))
    rifftree.set('size', str(riff_size))

    # recursive function to create xml tags and set the reltive attributes
    log_strings = populate_xml(riffchunk, rifftree, show_data_chunks, verbose)

    if riff_size + 8 < file_size:
        raw = file.read()
        unknown = LeafChunk("unknown", len(raw))
        unknown.add_rawdata(raw)

        node = ET.SubElement(root, "unknown")
        node.set('rawData', str(unknown.get_rawdata()))

    # write the xml file
    output_name = (title.split('.')[0] +
                   "-tree.xml") if output is None else output
    xmlfile = open(xmldir + output_name, 'w')
    data = ET.tostring(root, encoding="unicode")
    data = '<?xml version="1.0" encoding="UTF-8"?>' + data
    xmlfile.write(data)
    xmlfile.close()

    file.close

    # if log string where collected write a log file
    if len(log_strings) > 0:
        # create the log file
        output_log = (title.split('.')[0] +
                      "-log.txt") if logfn is None else logfn
        log_file = open(logdir + output_log, 'w')
        for ls in log_strings:
            log_file.write(ls + '\n')
        log_file.close()

    return None
Exemple #12
0
import json, sys, string, util
import xml.etree.cElementTree as ET

root = ET.Element("imagery")

for file in sys.argv[1:]:
    source = json.load(open(file))
    entry = ET.SubElement(root, "entry")

    name = ET.SubElement(entry, "name")
    name.text = source['name']

    type = ET.SubElement(entry, "type")
    type.text = source['type']

    url = ET.SubElement(entry, "url")
    url.text = source['url']

    if 'available_projections' in source:
        projections = ET.SubElement(entry, "projections")
        for projection in source['available_projections']:
            code = ET.SubElement(projections, "code")
            code.text = projection

    if 'attribution' in source:
        attribution = source['attribution']

        if attribution.get('text'):
            text = ET.SubElement(entry, "attribution-text")
            if attribution.get('required'):
                text.set('mandatory', 'true')
Exemple #13
0
    def _addtest(self, father, testElement, testList, fatherLevel):
        """ Add a html test element
            @param father: the  "group" father html  element.
            @param testElement: The test ET.element taken from a ctest Like xml
            @param testList: a list of the father's tests to find the correct position
                    where to place the test in alphabetical order.
        """
        container = self.seeker.findElement({"class": "testContainer"}, father,
                                            2)
        if container is None:
            # Make the container
            div = ET.SubElement(father, "div")
            if fatherLevel is not None:
                div.set("style", "display:none;")
            container = ET.SubElement(div, "ul", {"class": "testContainer"})
        # get the testName
        completeTestName = cleanSpace(
            cleanWebChar(testElement.find("Name").text))
        testName = cleanSpace(
            cleanWebChar(testElement.find("Name").text.split(".")[-1]))
        # Prepare the test
        # ,{"index":cleanBrackets(testName.lower())})
        span = ET.Element("span")

        # test
        li = ET.SubElement(span, "li", {"class": "test foldable"})
        span2 = ET.SubElement(li, "span", {"class": "clickable folded"})
        ET.SubElement(span2, "img", {"src": "images/plus.png"})
        ET.SubElement(span2, "span", {
            "id": cleanBrackets(testName),
            "class": "testid"
        }).text = testName + ": "

        # direct link
        link = ET.SubElement(
            li, "a", {
                "class":
                "permalink",
                "href":
                father.get("linkreference") + "//" + cleanBrackets(testName)
            })
        ET.SubElement(link, "img", {
            "title": "Direct link to the test",
            "src": "images/link.png"
        })

        status = testElement.get("Status")
        if status in self.status:
            status = self.status[status]
        else:
            status = cleanSpace(cleanWebChar(status))

        ET.SubElement(span2, "span", {"class": status}).text = status + " "

        # add status in groups
        groups = self._groups
        adresses = completeTestName.lower().split(".")[0:-1]
        if len(adresses) > 0:
            for adr in adresses:
                if status not in groups[adr]["Statistics"]:
                    groups[adr]["Statistics"][status] = 0
                groups[adr]["Statistics"][status] += 1
                groups = groups[adr]
        # field container
        ul = ET.SubElement(
            li, "ul", {
                "class": "fieldid",
                "testName": completeTestName,
                "style": "display: none;"
            })

        self._addField(ul, "start_time")
        self._addField(ul, "end_time")

        # find the well position
        index = bisect.bisect(testList, completeTestName.lower())
        testList.insert(index, completeTestName.lower())

        # insert the test
        container.insert(index, span)

        for namedMeasurment in testElement.find("Results").iter(
                "NamedMeasurement"):
            name = namedMeasurment.get("name")
            if name == 'Causes':
                cause = namedMeasurment.find("Value")
                if cause is not None:
                    ET.SubElement(span2, "span", {
                        "class": "cause"
                    }).text = cause.text + " "
                continue
            fieldName = cleanSpace(cleanWebChar(name)).lower()
            if fieldName in ('end_time', 'start_time', 'qmtest.cause',
                             'qmtest.target'):
                continue
            self._addField(ul, fieldName)

        self._addField(ul, "stdout")
Exemple #14
0
 def __init__(self, xml=None, _annotations=None, document=None):
     if xml is None:
         xml = ElementTree.Element("relation")
     ThymeMLAnnotation.__init__(self, xml, _annotations, document)
Exemple #15
0
    def _show_data(self, show_obj):
        """
        Creates an elementTree XML structure for a MediaBrowser-style series.xml
        returns the resulting data object.

        show_obj: a TVShow instance to create the NFO for
        """

        indexer_lang = show_obj.lang
        lINDEXER_API_PARMS = sickbeard.indexerApi(
            show_obj.indexer).api_params.copy()

        lINDEXER_API_PARMS['actors'] = True

        if indexer_lang and not indexer_lang == 'en':
            lINDEXER_API_PARMS['language'] = indexer_lang

        if show_obj.dvdorder != 0:
            lINDEXER_API_PARMS['dvdorder'] = True

        t = sickbeard.indexerApi(
            show_obj.indexer).indexer(**lINDEXER_API_PARMS)

        rootNode = etree.Element("details")
        tv_node = etree.SubElement(rootNode, "movie")
        tv_node.attrib["isExtra"] = "false"
        tv_node.attrib["isSet"] = "false"
        tv_node.attrib["isTV"] = "true"

        try:
            myShow = t[int(show_obj.indexerid)]
        except sickbeard.indexer_shownotfound:
            logger.log(
                u"Unable to find show with id " + str(show_obj.indexerid) +
                " on tvdb, skipping it", logger.ERROR)
            raise

        except sickbeard.indexer_error:
            logger.log(u"TVDB is down, can't use its data to make the NFO",
                       logger.ERROR)
            raise

        # check for title and id
        try:
            if getattr(myShow, 'seriesname', None) == None or getattr(
                    myShow, 'seriesname', "") == "" or getattr(
                        myShow, 'id', None) == None or getattr(
                            myShow, 'id', "") == "":
                logger.log(
                    u"Incomplete info for show with id " +
                    str(show_obj.indexerid) + " on tvdb, skipping it",
                    logger.ERROR)
                return False
        except sickbeard.indexer_attributenotfound:
            logger.log(
                u"Incomplete info for show with id " +
                str(show_obj.indexerid) + " on tvdb, skipping it",
                logger.ERROR)
            return False

        SeriesName = etree.SubElement(tv_node, "title")
        SeriesName.text = myShow['seriesname']

        Genres = etree.SubElement(tv_node, "genres")
        if getattr(myShow, "genre", None) != None:
            for genre in myShow['genre'].split('|'):
                if genre and genre.strip():
                    cur_genre = etree.SubElement(Genres, "Genre")
                    cur_genre.text = genre.strip()

        FirstAired = etree.SubElement(tv_node, "premiered")
        if getattr(myShow, 'firstaired', None) != None:
            FirstAired.text = myShow['firstaired']

        year = etree.SubElement(tv_node, "year")
        if getattr(myShow, "firstaired", None) != None:
            try:
                year_text = str(
                    datetime.datetime.strptime(myShow["firstaired"],
                                               '%Y-%m-%d').year)
                if year_text:
                    year.text = year_text
            except:
                pass
        plot = etree.SubElement(tv_node, "plot")
        if getattr(myShow, 'overview', None) is not None:
            plot.text = myShow["overview"]

        if getattr(myShow, 'rating', None) != None:
            try:
                rating = int((float(myShow['rating']) * 10))
            except ValueError:
                rating = 0
            Rating = etree.SubElement(tv_node, "rating")
            rating_text = str(rating)
            if rating_text != None:
                Rating.text = rating_text

        Status = etree.SubElement(tv_node, "status")
        if getattr(myShow, 'status', None) != None:
            Status.text = myShow['status']

        mpaa = etree.SubElement(tv_node, "mpaa")
        if getattr(myShow, "contentrating", None) != None:
            mpaa.text = myShow["contentrating"]

        IMDB_ID = etree.SubElement(tv_node, "id")
        if getattr(myShow, 'imdb_id', None) != None:
            IMDB_ID.attrib["moviedb"] = "imdb"
            IMDB_ID.text = myShow['imdb_id']

        indexerid = etree.SubElement(tv_node, "indexerid")
        if getattr(myShow, 'id', None) != None:
            indexerid.text = myShow['id']

        Runtime = etree.SubElement(tv_node, "runtime")
        if getattr(myShow, 'runtime', None) != None:
            Runtime.text = myShow['runtime']

        cast = etree.SubElement(tv_node, "cast")

        if getattr(myShow, '_actors', None) is not None:
            for actor in myShow['_actors']:
                cur_actor_name_text = getattr(actor, 'name', None)
                if cur_actor_name_text != None and cur_actor_name_text.strip():
                    cur_actor = etree.SubElement(cast, "actor")
                    cur_actor.text = cur_actor_name_text.strip()

        helpers.indentXML(rootNode)

        data = etree.ElementTree(rootNode)

        return data
Exemple #16
0
	def write(self, graph, fname, nodeAttributes = {}, edgeAttributes = {}):
		""" Writes a NetworKit graph to the specified file fname. 
			Parameters:
				- graph: a NetworKit::Graph python object 
				- fname: the desired file path and name to be written to
				- nodeAttributes: optional dictionary of node attributes in the form attribute name => list of attribute values
				- edgeAttributes: optional dictionary of edge attributes in the form attribute name => list of attribute values
		"""
		# reset some internal variables in case more graphs are written with the same instance
		self.edgeIdCounter = 0
		self.dir_str = ''

		if len(edgeAttributes) > 0 and not graph.hasEdgeIds():
			raise RuntimeError("Error, graph must have edge ids if edge attributes are given")

		# start with the root element and the right header information
		root = ET.Element('graphml')
		root.set("xmlnsi","http://graphml.graphdrawing.org/xmlns")
		root.set("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
		root.set("xsi:schemaLocation","http://graphml.graphdrawing.org/xmlns \
			http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd")

		maxAttrKey = 1
		# if the graph is weighted, add the attribute
		if graph.isWeighted():
			attrElement = ET.SubElement(root,'key')
			attrElement.set('for','edge')
			attrElement.set('id', 'd1')
			attrElement.set('attr.name','weight')
			attrElement.set('attr.type','double')
			maxAttrKey += 1

		attrKeys = {}
		import numbers
		import itertools
		for attType, attName, attData in itertools.chain(
			map(lambda d : ('node', d[0], d[1]), nodeAttributes.items()),
			map(lambda d : ('edge', d[0], d[1]), edgeAttributes.items())):

			attrElement = ET.SubElement(root, 'key')
			attrElement.set('for', attType)
			attrElement.set('id', 'd{0}'.format(maxAttrKey))
			attrKeys[(attType, attName)] = 'd{0}'.format(maxAttrKey)
			maxAttrKey += 1
			attrElement.set('attr.name', attName)
			if len(attData) == 0:
				attrElement.set('attr.type', 'int')
			elif isinstance(attData[0], bool):
				attrElement.set('attr.type', 'boolean')
				# special handling for boolean attributes: convert boolean into lowercase string
				if attType == 'edge':
					edgeAttributes[attName] = [ str(d).lower() for d in attData ]
				else:
					nodeAttributes[attName] = [ str(d).lower() for d in attData ]
			elif isinstance(attData[0], numbers.Integral):
				attrElement.set('attr.type', 'int')
			elif isinstance(attData[0], numbers.Real):
				attrElement.set('attr.type', 'double')
			else:
				attrElement.set('attr.type', 'string')


		# create graph element with appropriate information
		graphElement = ET.SubElement(root,"graph")
		if graph.isDirected():
			graphElement.set('edgedefault', 'directed')
			self.dir_str = 'true'
		else:
			graphElement.set('edgedefault', 'undirected')
			self.dir_str = 'false'
		graphElement.set('id', graph.getName())

		# Add nodes
		for n in graph.iterNodes():
			nodeElement = ET.SubElement(graphElement,'node')
			nodeElement.set('id', str(n))
			for attName, attData in nodeAttributes.items():
				dataElement = ET.SubElement(nodeElement, 'data')
				dataElement.set('key', attrKeys[('node', attName)])
				dataElement.text = str(attData[n])

		# in the future: more attributes
	        #for a in n.attributes():
        	#    if a != 'label':
	        #        data = doc.createElement('data')
        	#        data.setAttribute('key', a)
	        #        data.appendChild(doc.createTextNode(str(n[a])))
        	#        node.appendChild(data)

		# Add edges
		def addEdge(u, v, w, eid):
			edgeElement = ET.SubElement(graphElement,'edge')
			edgeElement.set('directed', self.dir_str)
			edgeElement.set('target', str(v))
			edgeElement.set('source', str(u))
			if graph.hasEdgeIds():
				edgeElement.set('id', "e{0}".format(eid))
			else:
				edgeElement.set('id', "e{0}".format(self.edgeIdCounter))
				self.edgeIdCounter += 1
			if graph.isWeighted():
				# add edge weight
				dataElement = ET.SubElement(edgeElement,'data')
				dataElement.set('key','d1')
				dataElement.text = str(w)
			for attName, attData in edgeAttributes.items():
				dataElement = ET.SubElement(edgeElement, 'data')
				dataElement.set('key', attrKeys[('edge', attName)])
				dataElement.text = str(attData[eid])
		graph.forEdges(addEdge)

	#TODO: optional prettify function for formatted output of xml files
		tree = ET.ElementTree(root)
		tree.write(fname,"utf-8",True)
                    str(recipe.skill_levels[0])
                ]
                if recipe.skill_names[1] != "None" and recipe.skill_levels[
                        1] > 0:
                    skill_list.extend([
                        "/", recipe.skill_names[1],
                        str(recipe.skill_levels[1])
                    ])
            f.write("{0:30} {1:25} Time: {2:2} {3}\n".format(
                recipe.crafted_item.name, ' '.join(skill_list), recipe.time,
                ', '.join(recipe.resource_names)))

elif args.output_format == "xml":

    import xml.etree.cElementTree as ET
    root = ET.Element("crafting_recipies")
    for recipe in crafting_recipes:
        entry = ET.SubElement(root, "recipe")
        item = ET.SubElement(entry, "crafted_item")
        ET.SubElement(item, "identifier").text = recipe.crafted_item.identifier
        ET.SubElement(item, "name").text = recipe.crafted_item.name
        ET.SubElement(item, "mesh").text = recipe.crafted_item.mesh
        ET.SubElement(item, "price").text = str(recipe.crafted_item.price)
        ET.SubElement(item, "weight").text = str(recipe.crafted_item.weight)
        ET.SubElement(item,
                      "difficulty").text = str(recipe.crafted_item.difficulty)
        ET.SubElement(item,
                      "head_armor").text = str(recipe.crafted_item.head_armor)
        ET.SubElement(item,
                      "body_armor").text = str(recipe.crafted_item.body_armor)
        ET.SubElement(item,
Exemple #18
0
 def compose_raw_message(self, payload):
     message = ET.Element('message')
     gcm = ET.SubElement(message, 'gcm', xmlns='google:mobile:data')
     gcm.text = json.dumps(payload)
     return ET.tostring(message)
Exemple #19
0
def eadheader(EAD, CSheet):
    eadheader_root = EAD[0]

    #update GUI progress bar
    from wx.lib.pubsub import pub
    wx.CallAfter(pub.sendMessage,
                 "update_spread",
                 msg="Reading <eadheader>...")

    # <eadheader> @findaidstatus
    if "findaidstatus" in eadheader_root.attrib:
        CSheet.find(
            'DraftStatus').text = eadheader_root.attrib['findaidstatus']

    #<eadid> @countrycode and @url
    if 'countrycode' in eadheader_root.find('eadid').attrib:
        CSheet.find('CountryCode').text = eadheader_root.find(
            'eadid').attrib['countrycode']
    if 'url' in eadheader_root.find('eadid').attrib:
        CSheet.find('URL').text = eadheader_root.find('eadid').attrib['url']

    #<filedesc>
    if eadheader_root.find('filedesc') is None:
        error(
            "Your EAD finding aid does not contain a <filedesc> tag. Since this is a required element in EAD2002, EADMachine is unable to convert the file. Please correct your EAD file and try again.",
            True)

    #<titlestmt>
    if eadheader_root.find('filedesc/titlestmt') is None:
        error(
            "Your EAD finding aid does not contain a <titlestmt> tag. Since this is a required element in EAD2002, EADMachine is unable to convert the file. Please correct your EAD file and try again.",
            True)
        titlestmt_element = ET.Element('titlestmt')

    #<titleproper>
    if eadheader_root.find('filedesc/titlestmt/titleproper') is None:
        error(
            "Your EAD finding aid does not contain a <titleproper> tag. Since this is a required element in EAD2002, EADMachine is unable to convert the file. Please correct your EAD file and try again.",
            True)

    #<date>
    if eadheader_root.find('filedesc/titlestmt/titleproper/date') is None:
        pass
    else:
        if 'type' in eadheader_root.find(
                'filedesc/titlestmt/titleproper/date').attrib:
            if eadheader_root.find('filedesc/titlestmt/titleproper/date'
                                   ).attrib['type'].lower() == 'bulk':
                CSheet.find('DateBulk').text = eadheader_root.find(
                    'filedesc/titlestmt/titleproper/date').text
                if 'normal' in eadheader_root.find(
                        'filedesc/titlestmt/titleproper/date').attrib:
                    CSheet.find('DateBulkNormal').text = eadheader_root.find(
                        'filedesc/titlestmt/titleproper/date').attrib['normal']
            else:
                CSheet.find('DateInclusive').text = eadheader_root.find(
                    'filedesc/titlestmt/titleproper/date').text
                if 'normal' in eadheader_root.find(
                        'filedesc/titlestmt/titleproper/date').attrib:
                    CSheet.find(
                        'DateInclusiveNormal').text = eadheader_root.find(
                            'filedesc/titlestmt/titleproper/date'
                        ).attrib['normal']
        else:
            CSheet.find('DateInclusive').text = eadheader_root.find(
                'filedesc/titlestmt/titleproper/date').text
            if 'normal' in eadheader_root.find(
                    'filedesc/titlestmt/titleproper/date').attrib:
                CSheet.find('DateInclusiveNormal').text = eadheader_root.find(
                    'filedesc/titlestmt/titleproper/date').attrib['normal']

    #<subtitle>
    if eadheader_root.find('filedesc/titlestmt/subtitle') is None:
        if EAD.find('frontmatter/titlepage/subtitle') is None:
            pass
        else:
            CSheet.find('Subtitle').text = EAD.find(
                'frontmatter/titlepage/subtitle').text
    else:
        CSheet.find('Subtitle').text = eadheader_root.find(
            'filedesc/titlestmt/subtitle').text

    #<author>
    if eadheader_root.find('filedesc/titlestmt/author') is None:
        if EAD.find('frontmatter/titlepage/author') is None:
            pass
        else:
            CSheet.find('ProcessedBy').text = EAD.find(
                'frontmatter/titlepage/author').text
    else:
        CSheet.find('ProcessedBy').text = eadheader_root.find(
            'filedesc/titlestmt/author').text

    #<sponsor>
    if eadheader_root.find('filedesc/titlestmt/sponsor') is None:
        if EAD.find('frontmatter/titlepage/sponsor') is None:
            pass
        else:
            CSheet.find('Sponsor').text = EAD.find(
                'frontmatter/titlepage/sponsor').text
    else:
        CSheet.find('Sponsor').text = eadheader_root.find(
            'filedesc/titlestmt/sponsor').text

    # Edition Statement Section
    from editionstmt import editionstmt
    editionstmt(eadheader_root, CSheet)

    # Publication Statement Section
    from publicationstmt import publicationstmt
    publicationstmt(eadheader_root, CSheet)
    if CSheet.find('Publisher/PublisherName') is None:
        if EAD.find('frontmatter/titlepage/publisher') is None:
            pass
        else:
            if EAD.find('frontmatter/titlepage/publisher').text:
                CSheet.find('Publisher/PublisherName').text = EAD.find(
                    'frontmatter/titlepage/publisher').text
    else:
        if CSheet.find('Publisher/PublisherName').text:
            pass
        else:
            if EAD.find('frontmatter/titlepage/publisher') is None:
                pass
            else:
                CSheet.find('Publisher/PublisherName').text = EAD.find(
                    'frontmatter/titlepage/publisher').text
    if CSheet.find('PublicationDate').text:
        pass
    else:
        if EAD.find('frontmatter/titlepage/date') is None:
            pass
        else:
            CSheet.find('PublicationDate').text = EAD.find(
                'frontmatter/titlepage/date').text
            if 'normal' in EAD.find('frontmatter/titlepage/date').attrib:
                CSheet.find('PublicationDateNormal').text = EAD.find(
                    'frontmatter/titlepage/date').attrib['normal']

    # Series Statement Section
    from seriesstmt import seriesstmt
    seriesstmt(eadheader_root, CSheet)

    # Note Statement Section
    if eadheader_root.find('filedesc/notestmt') is None:
        pass
    else:
        for note in eadheader_root.find('filedesc/notestmt').iter('p'):
            if note.text:
                note_element = ET.Element('NoteStatement')
                CSheet.find('NoteStatements').append(note_element)
                note_element.text = note.text

    # Profile Description
    if eadheader_root.find('profiledesc') is None:
        pass
    else:
        # EAD creation and EAD creation date
        if eadheader_root.find('profiledesc/creation') is None:
            pass
        else:
            CSheet.find('EADCreator').text = eadheader_root.find(
                'profiledesc/creation').text
            if eadheader_root.find('profiledesc/creation/date') is None:
                pass
            else:
                if eadheader_root.find('profiledesc/creation/date').tail:
                    CSheet.find('EADCreator').text = CSheet.find(
                        'EADCreator').text + eadheader_root.find(
                            'profiledesc/creation/date').tail
                CSheet.find('EADCreationDate').text = eadheader_root.find(
                    'profiledesc/creation/date').text
                if 'normal' in eadheader_root.find(
                        'profiledesc/creation/date').attrib:
                    CSheet.find(
                        'EADCreationDateNormal').text = eadheader_root.find(
                            'profiledesc/creation/date').attrib['normal']
        # Finding Aid Languages
        if eadheader_root.find('profiledesc/langusage') is None:
            pass
        else:
            if eadheader_root.find('profiledesc/langusage/language') is None:
                if eadheader_root.find('profiledesc/langusage').text:
                    CSheet.find('FindingAidLanguages/FALanguage/Lang'
                                ).text = eadheader_root.find(
                                    'profiledesc/langusage').text
            else:
                CSheet.find('FindingAidLanguages').clear()
                for lang in eadheader_root.find('profiledesc/langusage'):
                    if lang.tag == "language":
                        FALanguage_element = ET.Element('FALanguage')
                        CSheet.find('FindingAidLanguages').append(
                            FALanguage_element)
                        Lang_element = ET.Element('Lang')
                        FALanguage_element.append(Lang_element)
                        Lang_element.text = lang.text
                        LangCode_element = ET.Element('LangCode')
                        FALanguage_element.append(LangCode_element)
                        if "langcode" in lang.attrib:
                            LangCode_element.text = lang.attrib['langcode']
                        Script_element = ET.Element('Script')
                        FALanguage_element.append(Script_element)
                        ScriptCode_element = ET.Element('ScriptCode')
                        FALanguage_element.append(ScriptCode_element)
                        LangNote_element = ET.Element('LangNote')
                        FALanguage_element.append(LangNote_element)
                        if eadheader_root.find('profiledesc/langusage').text:
                            LangNote_element.text = eadheader_root.find(
                                'profiledesc/langusage').text
                        if len(
                                eadheader_root.find('profiledesc/langusage').
                                tail.strip()) >= 1:
                            LangNote_element.text = LangNote_element.text + eadheader_root.find(
                                'profiledesc/langusage').tail

        # Description Rules
        if eadheader_root.find('profiledesc/descrules') is None:
            pass
        else:
            CSheet.find(
                'LocalConventions/Convention/Citation').text = mixed_content(
                    eadheader_root.find('profiledesc/descrules'))

    # Revisions
    if eadheader_root.find('revisiondesc') is None:
        pass
    else:
        revision_root = eadheader_root.find('revisiondesc')
        if revision_root.find('change') is None:
            if revision_root.find('list') is None:
                pass
            else:  #if list
                CSheet.find('Revisions').clear()
                for item in revision_root.find('list'):
                    Event_element = ET.Element('Event')
                    CSheet.find('Revisions').append(Event_element)
                    Type_element = ET.Element('Type')
                    Event_element.append(Type_element)
                    Date_element = ET.Element('Date')
                    Event_element.append(Date_element)
                    DateNormal_element = ET.Element('DateNormal')
                    Event_element.append(DateNormal_element)
                    AgentType_element = ET.Element('AgentType')
                    Event_element.append(AgentType_element)
                    Agent_element = ET.Element('Agent')
                    Event_element.append(Agent_element)
                    Description_element = ET.Element('Description')
                    Event_element.append(Description_element)
                    if item.find('date') is None:
                        pass
                    else:
                        Date_element.text = item.find('date').text
                        if 'normal' in item.find('date').attrib:
                            DateNormal_element.text = item.find(
                                'date').attrib['normal']
                    if item.text:
                        Description_element.text = item.text
                    if item.tail:
                        Description_element.text = Description_element.text + item.tail
        else:  # if change
            if revision_root.find('list') is None:
                CSheet.find('Revisions').clear()
                for change in revision_root:
                    if change.tag == "change":
                        Event_element = ET.Element('Event')
                        CSheet.find('Revisions').append(Event_element)
                        Type_element = ET.Element('Type')
                        Event_element.append(Type_element)
                        Date_element = ET.Element('Date')
                        Event_element.append(Date_element)
                        DateNormal_element = ET.Element('DateNormal')
                        Event_element.append(DateNormal_element)
                        AgentType_element = ET.Element('AgentType')
                        Event_element.append(AgentType_element)
                        Agent_element = ET.Element('Agent')
                        Event_element.append(Agent_element)
                        Description_element = ET.Element('Description')
                        Event_element.append(Description_element)
                        if change.find('date') is None:
                            pass
                        else:
                            Date_element.text = change.find('date').text
                            if 'normal' in change.find('date').attrib:
                                DateNormal_element.text = change.find(
                                    'date').attrib['normal']
                        if change.find('item') is None:
                            pass
                        else:
                            Description_element.text = change.find('item').text
            else:  #if list and change
                CSheet.find('Revisions').clear()
                for change in revision_root.find('change'):
                    Event_element = ET.Element('Event')
                    CSheet.find('Revisions').append(Event_element)
                    Type_element = ET.Element('Type')
                    Event_element.append(Type_element)
                    Date_element = ET.Element('Date')
                    Event_element.append(Date_element)
                    DateNormal_element = ET.Element('DateNormal')
                    Event_element.append(DateNormal_element)
                    AgentType_element = ET.Element('AgentType')
                    Event_element.append(AgentType_element)
                    Agent_element = ET.Element('Agent')
                    Event_element.append(Agent_element)
                    Description_element = ET.Element('Description')
                    Event_element.append(Description_element)
                    if change.find('date') is None:
                        pass
                    else:
                        Date_element.text = change.find('date').text
                        if 'normal' in change.find('date').attrib:
                            DateNormal_element.text = change.find(
                                'date').attrib['normal']
                    if change.find('item') is None:
                        pass
                    else:
                        Description_element.text = change.find('item').text
                for item in revision_root.find('list'):
                    Event_element = ET.Element('Event')
                    CSheet.find('Revisions').append(Event_element)
                    Type_element = ET.Element('Type')
                    Event_element.append(Type_element)
                    Date_element = ET.Element('Date')
                    Event_element.append(Date_element)
                    DateNormal_element = ET.Element('DateNormal')
                    Event_element.append(DateNormal_element)
                    AgentType_element = ET.Element('AgentType')
                    Event_element.append(AgentType_element)
                    Agent_element = ET.Element('Agent')
                    Event_element.append(Agent_element)
                    Description_element = ET.Element('Description')
                    Event_element.append(Description_element)
                    if item.find('date') is None:
                        pass
                    else:
                        Date_element.text = item.find('date').text
                        if 'normal' in item.find('date').attrib:
                            DateNormal_element.text = item.find(
                                'date').attrib['normal']
                    if item.text:
                        Description_element.text = item.text
                    if item.tail:
                        Description_element.text = Description_element.text + item.tail
Exemple #20
0
def components(cmpnt_root, CSheet, SeriesSheet, level, child_tag, version):

    #<unittitle>
    if cmpnt_root.find('did/unittitle') is None:
        pass
    else:
        SeriesSheet.find('SeriesName').text = mixed_content(
            cmpnt_root.find('did/unittitle'))

    #<unitid>
    if cmpnt_root.find('did/unitid') is None:
        if "id" in cmpnt_root.attrib:
            SeriesSheet.find('SeriesNumber').text = cmpnt_root.attrib['id']
        else:
            if cmpnt_root.find('did') is None:
                pass
            else:
                if "id" in cmpnt_root.find('did').attrib:
                    SeriesSheet.find('SeriesNumber').text = cmpnt_root.find(
                        'did').attrib['id']
    else:
        SeriesSheet.find('SeriesNumber').text = mixed_content(
            cmpnt_root.find('did/unitid'))
    SeriesSheet.find('SeriesLevel').text = level

    #<unitdate> and <unitdatestructured>
    from unitdate import unitdate
    if cmpnt_root.find('did') is None:
        pass
    else:
        unitdate(cmpnt_root.find('did'), SeriesSheet, "series", version)

    #<physdesc> and <physdescstructured>
    if cmpnt_root.find('physdesc') is None:
        pass
    else:
        from physdesc import simple
        simple(cmpnt_root, SeriesSheet, version)
    if cmpnt_root.find('physdescstructured') is None:
        pass
    else:
        from physdesc import structured
        structured(cmpnt_root, SeriesSheet)

    #<arrangement>
    if cmpnt_root.find('arrangement') is None:
        pass
    else:
        SeriesSheet.find('Arrangement').clear()
        for arr_para in cmpnt_root.find('arrangement'):
            if arr_para.tag == "p":
                p_element = ET.Element('p')
                SeriesSheet.find('Arrangement').append(p_element)
                p_element.text = mixed_content(arr_para)

    #<scopecontent>
    if cmpnt_root.find('scopecontent') is None:
        pass
    else:
        SeriesSheet.find('Description').clear()
        for arr_para in cmpnt_root.find('scopecontent'):
            if arr_para.tag == "p":
                p_element = ET.Element('p')
                SeriesSheet.find('Description').append(p_element)
                p_element.text = mixed_content(arr_para)

    #<archdesc> elements at series level
    archdesc_lower(cmpnt_root, CSheet, version)

    if child_tag == "c":
        pass
    else:
        if "level" in cmpnt_root.find(child_tag).attrib:
            SeriesSheet.find('DescriptionLevel').text = cmpnt_root.find(
                child_tag).attrib['level']

    for old_record in SeriesSheet.findall('Record'):
        SeriesSheet.remove(old_record)

    next_level_name = child_tag[1:]
    if len(next_level_name) > 1:
        if int(next_level_name) < 10:
            next_level = "c0" + str(int(next_level_name) + 1)
        else:
            next_level = "c" + str(int(next_level_name) + 1)
    else:
        next_level = "c"

    for file_root in cmpnt_root:
        if file_root.tag == child_tag or file_root.tag == "c" or file_root.tag == "c01":
            if file_root.find(next_level) is None:
                Record_element = ET.Element('Record')
                SeriesSheet.append(Record_element)
                RecordID_element = ET.Element('RecordID')
                Record_element.append(RecordID_element)
                BoxName_element = ET.Element('BoxName')
                Record_element.append(BoxName_element)
                BoxNumber_element = ET.Element('BoxNumber')
                Record_element.append(BoxNumber_element)
                Unit_element = ET.Element('Unit')
                Record_element.append(Unit_element)
                UnitNumber_element = ET.Element('UnitNumber')
                Record_element.append(UnitNumber_element)
                UnitTitle_element = ET.Element('UnitTitle')
                Record_element.append(UnitTitle_element)
                Date1_element = ET.Element('Date1')
                Record_element.append(Date1_element)
                Date1Normal_element = ET.Element('Date1Normal')
                Record_element.append(Date1Normal_element)
                Date2_element = ET.Element('Date2')
                Record_element.append(Date2_element)
                Date2Normal_element = ET.Element('Date2Normal')
                Record_element.append(Date2Normal_element)
                Date3_element = ET.Element('Date3')
                Record_element.append(Date3_element)
                Date3Normal_element = ET.Element('Date3Normal')
                Record_element.append(Date3Normal_element)
                Date4_element = ET.Element('Date4')
                Record_element.append(Date4_element)
                Date4Normal_element = ET.Element('Date4Normal')
                Record_element.append(Date4Normal_element)
                Date5_element = ET.Element('Date5')
                Record_element.append(Date5_element)
                Date5Normal_element = ET.Element('Date5Normal')
                Record_element.append(Date5Normal_element)
                Coverage_element = ET.Element('Coverage')
                Record_element.append(Coverage_element)
                Type_element = ET.Element('Type')
                Record_element.append(Type_element)
                Approximate_element = ET.Element('Approximate')
                Record_element.append(Approximate_element)
                Quantity_element = ET.Element('Quantity')
                Record_element.append(Quantity_element)
                UnitType_element = ET.Element('UnitType')
                Record_element.append(UnitType_element)
                PhysicalFacet_element = ET.Element('PhysicalFacet')
                Record_element.append(PhysicalFacet_element)
                Dimensions_element = ET.Element('Dimensions')
                Record_element.append(Dimensions_element)
                DimensionsUnit_element = ET.Element('DimensionsUnit')
                Record_element.append(DimensionsUnit_element)
                PhysDescNote_element = ET.Element('PhysDescNote')
                Record_element.append(PhysDescNote_element)
                DigitalObjectType_element = ET.Element('DigitalObjectType')
                Record_element.append(DigitalObjectType_element)
                DigitalObjectID_element = ET.Element('DigitalObjectID')
                Record_element.append(DigitalObjectID_element)
                DigitalObjectLink_element = ET.Element('DigitalObjectLink')
                Record_element.append(DigitalObjectLink_element)
                DigitalObjectLocalName_element = ET.Element(
                    'DigitalObjectLocalName')
                Record_element.append(DigitalObjectLocalName_element)
                DigitalObjectNote_element = ET.Element('DigitalObjectNote')
                Record_element.append(DigitalObjectNote_element)

                if len(file_root.findall('did/container')) == 2:
                    BoxNumber_element.text = file_root.find(
                        'did/container[1]').text
                    if "type" in file_root.find('did/container[1]').attrib:
                        BoxName_element.text = file_root.find(
                            'did/container[1]').attrib['type']
                    UnitNumber_element.text = file_root.find(
                        'did/container[2]').text
                    if "type" in file_root.find('did/container[2]').attrib:
                        Unit_element.text = file_root.find(
                            'did/container[2]').attrib['type']
                    if file_root.find('did/unitid') is None:
                        if "id" in file_root.attrib:
                            RecordID_element.text = file_root.attrib['id']
                    else:
                        RecordID_element.text = file_root.find(
                            'did/unitid').text
                elif len(file_root.findall('did/container')) == 1:
                    if file_root.find('did/physloc') is None:
                        if "type" in file_root.find('did/container').attrib:
                            if file_root.find(
                                    'did/container'
                            ).attrib['type'].lower(
                            ) == "oversized" or "artifact-box" or "flat-file":
                                BoxNumber_element.text = file_root.find(
                                    'did/container').text
                                if "type" in file_root.find(
                                        'did/container').attrib:
                                    BoxName_element.text = file_root.find(
                                        'did/container').attrib['type']
                                if file_root.find('did/unitid') is None:
                                    if "id" in file_root.attrib:
                                        RecordID_element.text = file_root.attrib[
                                            'id']
                                else:
                                    RecordID_element.text = file_root.find(
                                        'did/unitid').text
                            else:
                                UnitNumber_element.text = file_root.find(
                                    'did/container').text
                                if "type" in file_root.find(
                                        'did/container').attrib:
                                    Unit_element.text = file_root.find(
                                        'did/container').attrib['type']
                                if file_root.find('did/unitid') is None:
                                    if "id" in file_root.attrib:
                                        RecordID_element.text = file_root.attrib[
                                            'id']
                                else:
                                    RecordID_element.text = file_root.find(
                                        'did/unitid').text
                        else:
                            UnitNumber_element.text = file_root.find(
                                'did/container').text
                            if "type" in file_root.find(
                                    'did/container').attrib:
                                Unit_element.text = file_root.find(
                                    'did/container').attrib['type']
                            if file_root.find('did/unitid') is None:
                                if "id" in file_root.attrib:
                                    RecordID_element.text = file_root.attrib[
                                        'id']
                            else:
                                RecordID_element.text = file_root.find(
                                    'did/unitid').text
                    else:
                        if file_root.find('did/unitid') is None:
                            if "id" in file_root.attrib:
                                #physloc, container, id
                                RecordID_element.text = file_root.attrib['id']
                                BoxNumber_element.text = file_root.find(
                                    'did/container').text
                                if "type" in file_root.find(
                                        'did/container').attrib:
                                    BoxName_element.text = file_root.find(
                                        'did/container').attrib['type']
                                UnitNumber_element.text = file_root.find(
                                    'did/physloc').text
                            else:
                                #physloc, container
                                BoxNumber_element.text = file_root.find(
                                    'did/container').text
                                if "type" in file_root.find(
                                        'did/container').attrib:
                                    BoxName_element.text = file_root.find(
                                        'did/container').attrib['type']
                                UnitNumber_element.text = file_root.find(
                                    'did/physloc').text
                        else:
                            #physloc, container and unitid
                            if "id" in file_root.attrib:
                                RecordID_element.text = file_root.attrib['id']
                                BoxNumber_element.text = file_root.find(
                                    'did/container').text
                                if "type" in file_root.find(
                                        'did/container').attrib:
                                    BoxName_element.text = file_root.find(
                                        'did/container').attrib['type']
                                Unit_element.text = file_root.find(
                                    'did/physloc').text
                                UnitNumber_element.text = file_root.find(
                                    'did/unitid').text
                            else:
                                RecordID_element.text = file_root.find(
                                    'did/physloc').text
                                BoxNumber_element.text = file_root.find(
                                    'did/container').text
                                if "type" in file_root.find(
                                        'did/container').attrib:
                                    BoxName_element.text = file_root.find(
                                        'did/container').attrib['type']
                                UnitNumber_element.text = file_root.find(
                                    'did/unitid').text
                elif len(file_root.findall('did/container')) == 0:
                    if "id" in file_root.attrib:
                        RecordID_element.text = file_root.attrib['id']
                    if file_root.find('did/unitid') is None:
                        pass
                    else:
                        UnitNumber_element.text = file_root.find(
                            'did/unitid').text

                #Container IDs
                if file_root.find('did/container') is None:
                    pass
                else:
                    for cont in file_root.find('did'):
                        if cont.tag == 'container':
                            if "id" in cont.attrib:
                                if file_root.find('did/unitid') is None:
                                    if "id" in file_root.attrib:
                                        parent_id = file_root.attrib['id']
                                    else:
                                        parent_id = ""
                                else:
                                    parent_id = file_root.find(
                                        'did/unitid').text
                                if "type" in file_root.find(
                                        'did/container').attrib:
                                    cont_label = file_root.find(
                                        'did/container').attrib['type']
                                else:
                                    cont_label = ""
                                cont_num = cont.text
                                match_count = 0
                                for Cont_Sheet in CSheet.find('ContainerData'):
                                    if len(parent_id) > 0 and Cont_Sheet.find(
                                            'ContainerParent').text:
                                        if parent_id == Cont_Sheet.find(
                                                'ContainerParent').text:
                                            if len(cont_num
                                                   ) > 0 and Cont_Sheet.find(
                                                       'ContainerNumber').text:
                                                if cont_num == Cont_Sheet.find(
                                                        'ContainerNumber'
                                                ).text:
                                                    if len(
                                                            cont_label
                                                    ) > 1 and Cont_Sheet.find(
                                                            'ContainerLabel'
                                                    ).text:
                                                        if cont_label.lower(
                                                        ) == Cont_Sheet.find(
                                                                'ContainerLabel'
                                                        ).text.lower():
                                                            pass
                                                        else:
                                                            match_count = match_count + 1
                                                    else:
                                                        match_count = match_count + 1
                                    else:
                                        if len(cont_num
                                               ) > 0 and Cont_Sheet.find(
                                                   'ContainerNumber').text:
                                            if cont_num == Cont_Sheet.find(
                                                    'ContainerNumber').text:
                                                if len(
                                                        cont_label
                                                ) > 1 and Cont_Sheet.find(
                                                        'ContainerLabel').text:
                                                    if cont_label.lower(
                                                    ) == Cont_Sheet.find(
                                                            'ContainerLabel'
                                                    ).text.lower():
                                                        pass
                                                    else:
                                                        match_count = match_count + 1
                                                else:
                                                    match_count = match_count + 1
                                if match_count < 1:
                                    Container_element = ET.Element('Container')
                                    CSheet.find('ContainerData').append(
                                        Container_element)
                                    ContainerParent_element = ET.Element(
                                        'ContainerParent')
                                    Container_element.append(
                                        ContainerParent_element)
                                    ContainerLabel_element = ET.Element(
                                        'ContainerLabel')
                                    Container_element.append(
                                        ContainerLabel_element)
                                    ContainerNumber_element = ET.Element(
                                        'ContainerNumber')
                                    Container_element.append(
                                        ContainerNumber_element)
                                    ContainerID_element = ET.Element(
                                        'ContainerID')
                                    Container_element.append(
                                        ContainerID_element)
                                    ContainerParent_element.text = parent_id
                                    ContainerLabel_element.text = cont_label
                                    ContainerNumber_element.text = cont_num
                                    ContainerID_element.text = cont.attrib[
                                        'id']

                #<unitdate>
                if file_root.find('did/unittitle/unitdate') is None:
                    pass
                else:
                    Date1_element.text = file_root.find(
                        'did/unittitle/unitdate').text
                    if "normal" in file_root.find(
                            'did/unittitle/unitdate').attrib:
                        Date1Normal_element.text = file_root.find(
                            'did/unittitle/unitdate').attrib['normal']

                if file_root.find('did/unittitle') is None:
                    if file_root.find('did/odd/p') is None:
                        pass
                    else:
                        UnitTitle_element.text = mixed_content(
                            file_root.find('did/odd/p'))
                else:
                    if file_root.find('did/unittitle/unitdate') is None:
                        UnitTitle_element.text = mixed_content(
                            file_root.find('did/unittitle'))
                    else:
                        file_root.find('did/unittitle').remove(
                            file_root.find('did/unittitle/unitdate'))
                        UnitTitle_element.text = mixed_content(
                            file_root.find('did/unittitle'))

                date_count = 0
                for date in file_root.find('did'):
                    if date.tag == "unitdate":
                        date_count = date_count + 1
                        if date_count == 1:
                            Date1_element.text = date.text
                            if "normal" in date.attrib:
                                Date1Normal_element.text = date.attrib[
                                    'normal']
                        if date_count == 2:
                            Date2_element.text = date.text
                            if "normal" in date.attrib:
                                Date2Normal_element.text = date.attrib[
                                    'normal']
                        if date_count == 3:
                            Date3_element.text = date.text
                            if "normal" in date.attrib:
                                Date3Normal_element.text = date.attrib[
                                    'normal']
                        if date_count == 4:
                            Date4_element.text = date.text
                            if "normal" in date.attrib:
                                Date4Normal_element.text = date.attrib[
                                    'normal']
                        if date_count == 5:
                            Date5_element.text = date.text
                            if "normal" in date.attrib:
                                Date5Normal_element.text = date.attrib[
                                    'normal']
                        if date_count > 5:
                            Date5_element.text = Date5_element.text + ", " + date.text
                            if "normal" in date.attrib:
                                Date5Normal_element.text = Date5Normal_element.text + "," + date.attrib[
                                    'normal']

                #<physdesc>
                if file_root.find('did/physdesc') is None:
                    pass
                else:
                    if file_root.find('did/physdesc/extent') is None:
                        Quantity_element.text = file_root.find(
                            'did/physdesc').text
                    else:
                        Quantity_element.text = file_root.find(
                            'did/physdesc/extent').text
                        if "unit" in file_root.find(
                                'did/physdesc/extent').attrib:
                            UnitType_element.text = file_root.find(
                                'did/physdesc/extent').attrib['unit']
                    if file_root.find('did/physdesc/dimensions') is None:
                        pass
                    else:
                        Dimensions_element.text = file_root.find(
                            'did/physdesc/dimensions').text
                        if "unit" in file_root.find(
                                'did/physdesc/dimensions').attrib:
                            DimensionsUnit_element.text = file_root.find(
                                'did/physdesc/dimensions').attrib['unit']
                    if file_root.find('did//physdesc/physfacet') is None:
                        pass
                    else:
                        PhysicalFacet_element.text = file_root.find(
                            'did/physdesc/physfacet').text

                #<physdescstructured>
                if version == "ead3":
                    if file_root.find('did/physdescstructured') is None:
                        pass
                    else:
                        if "coverage" in file_root.find(
                                'did/physdescstructured').attrib:
                            Coverage_element.text = file_root.find(
                                'did/physdescstructured').attrib['coverage']
                        if "physdescstructuredtype" in file_root.find(
                                'did/physdescstructured').attrib:
                            Type_element.text = file_root.find(
                                'did/physdescstructured'
                            ).attrib['physdescstructuredtype']
                        if file_root.find(
                                'did/physdescstructured/quantity') is None:
                            pass
                        else:
                            Quantity_element.text = file_root.find(
                                'did/physdescstructured/quantity').text
                            if "approximate" in file_root.find(
                                    'did/physdescstructured/quantity').attrib:
                                Approximate_element.text = file_root.find(
                                    'did/physdescstructured/quantity'
                                ).attrib['approximate']
                        if file_root.find(
                                'did/physdescstructured/unittype') is None:
                            pass
                        else:
                            UnitType_element = file_root.find(
                                'did/physdescstructured/unittype').text
                        if file_root.find(
                                'did/physdescstructured/dimensions') is None:
                            pass
                        else:
                            Dimensions_element.text = file_root.find(
                                'did/physdescstructured/dimensions').text
                        if "unit" in file_root.find(
                                'did/physdescstructured/dimensions').attrib:
                            DimensionsUnit_element.text = file_root.find(
                                'did/physdescstructured/dimensions'
                            ).attrib['unit']
                        if file_root.find(
                                'did/physdescstructured/physfacet') is None:
                            pass
                        else:
                            PhysicalFacet_element.text = file_root.find(
                                'did/physdescstructured/physfacet').text

                #notes
                if file_root.find('did/note/p') is None:
                    pass
                else:
                    PhysDescNote_element.text = mixed_content(
                        file_root.find('did/note/p'))

                #digital objects
                if file_root.find('did/dao') is None:
                    pass
                else:
                    if "daotype" in file_root.find('did/dao').attrib:
                        DigitalObjectType_element.text = file_root.find(
                            'did/dao').attrib['daotype']
                    if 'identifier' in file_root.find('did/dao').attrib:
                        DigitalObjectID_element.text = file_root.find(
                            'did/dao').attrib['identifier']
                    if 'id' in file_root.find('did/dao').attrib:
                        DigitalObjectID_element.text = file_root.find(
                            'did/dao').attrib['id']
                    if 'href' in file_root.find('did/dao').attrib:
                        DigitalObjectLink_element.text = file_root.find(
                            'did/dao').attrib['href']
                    if 'localtype' in file_root.find('did/dao').attrib:
                        DigitalObjectLocalName_element.text = file_root.find(
                            'did/dao').attrib['localtype']
                    if 'title' in file_root.find('did/dao').attrib:
                        DigitalObjectLocalName_element.text = file_root.find(
                            'did/dao').attrib['title']
                    if file_root.find('did/dao/daodesc/p') is None:
                        pass
                    else:
                        DigitalObjectNote_element.text = mixed_content(
                            file_root.find('did/dao/daodesc/p'))
                    if file_root.find('did/dao/descriptivenote/p') is None:
                        pass
                    else:
                        DigitalObjectNote_element.text = mixed_content(
                            file_root.find('did/dao/descriptivenote/p'))
                if file_root.find('did/daogrp') is None:
                    pass
                else:
                    if 'id' in file_root.find('did/daogrp').attrib:
                        DigitalObjectID_element.text = file_root.find(
                            'did/daogrp').attrib['id']
                    if file_root.find('did/daogrp/daoloc') is None:
                        pass
                    else:
                        if 'href' in file_root.find(
                                'did/daogrp/daoloc').attrib:
                            DigitalObjectLink_element.text = file_root.find(
                                'did/daogrp/daoloc').attrib['href']
                    if 'title' in file_root.find('did/daogrp').attrib:
                        DigitalObjectLocalName_element.text = file_root.find(
                            'did/daogrp').attrib['title']
                    if file_root.find('did/dao/daodesc/p') is None:
                        pass
                    else:
                        DigitalObjectNote_element.text = mixed_content(
                            file_root.find('did/dao/daodesc/p'))
                    if file_root.find('did/dao/descriptivenote/p') is None:
                        pass
                    else:
                        DigitalObjectNote_element.text = mixed_content(
                            file_root.find('did/dao/descriptivenote/p'))

                #lower level <archdesc> elements
                archdesc_lower(cmpnt_root, CSheet, version)
Exemple #21
0
 def test_parse_xml_ns(self):
     expected = ET.Element("{foo:bar}test", {"foo": "bar"})
     actual = parse_xml(u"""<h:test foo="bar" xmlns:h="foo:bar"/>""")
     self.assertEqual(expected.tag, actual.tag)
     self.assertEqual(expected.attrib, actual.attrib)
Exemple #22
0
def createXML(inputFilepath, outputFilepath, classes, boundingBoxes):

    annotation = ET.Element("annotation")

    folder = ET.SubElement(annotation, "folder")
    folder.text = basename(str(Path(inputFilepath).parent))

    filename = ET.SubElement(annotation, "filename")
    filename.text = basename(inputFilepath)

    path = ET.SubElement(annotation, "path")
    path.text = inputFilepath
    # path.text = '/home/msardonini/mnt/superSmashCnn/imagesFromNet/' + basename(inputFilepath)

    source = ET.SubElement(annotation, "source")
    ET.SubElement(source, "database").text = "Unknown"

    size = ET.SubElement(annotation, "size")
    ET.SubElement(size, "width").text = "720"
    ET.SubElement(size, "height").text = "480"
    ET.SubElement(size, "depth").text = "3"

    segmented = ET.SubElement(annotation, "segmented")
    segmented.text = "0"

    for i in range(len(classes)):
        objectE = ET.SubElement(annotation, "object")

        if (classes[i] == 0):
            ET.SubElement(objectE, "name").text = "luigi"
        elif (classes[i] == 1):
            ET.SubElement(objectE, "name").text = "yoshi"
        elif (classes[i] == 2):
            ET.SubElement(objectE, "name").text = "DK"
        elif (classes[i] == 3):
            ET.SubElement(objectE, "name").text = "ness"
        elif (classes[i] == 4):
            ET.SubElement(objectE, "name").text = "mario"
        elif (classes[i] == 5):
            ET.SubElement(objectE, "name").text = "link"
        elif (classes[i] == 6):
            ET.SubElement(objectE, "name").text = "falcon"
        elif (classes[i] == 7):
            ET.SubElement(objectE, "name").text = "samus"
        elif (classes[i] == 8):
            ET.SubElement(objectE, "name").text = "kirby"
        elif (classes[i] == 9):
            ET.SubElement(objectE, "name").text = "pikachu"
        elif (classes[i] == 10):
            ET.SubElement(objectE, "name").text = "jigglypuff"
        elif (classes[i] == 11):
            ET.SubElement(objectE, "name").text = "fox"

        ET.SubElement(objectE, "pose").text = "Unspecified"
        ET.SubElement(objectE, "truncated").text = "0"
        ET.SubElement(objectE, "difficult").text = "0"
        bndBox = ET.SubElement(objectE, "bndbox")
        ET.SubElement(bndBox, "xmin").text = str(int(boundingBoxes[i][1]))
        ET.SubElement(bndBox, "xmax").text = str(int(boundingBoxes[i][3]))
        ET.SubElement(bndBox, "ymin").text = str(int(boundingBoxes[i][0]))
        ET.SubElement(bndBox, "ymax").text = str(int(boundingBoxes[i][2]))

    rough_string = ET.tostring(annotation)
    reparsed = minidom.parseString(rough_string)

    myStr = (reparsed.toprettyxml(indent="\t"))

    outputFile = open(outputFilepath, 'w+')
    outputFile.write(myStr)
 def add_point(self, name, localization_type, coordinates, metadata=None):
     if localization_type == kmlOutput.SCAN_TYPE_WIFI:
         extended_data = ET.Element("ExtendedData")
         if metadata:
             instant_scan = metadata[0].instant_scan
             # extended_data = ET.Element("ExtendedData")
             data = ET.SubElement(extended_data, "Data", name="date")
             ET.SubElement(data, "value").text = "{}".format(instant_scan)
             id_result = 0
             data = ET.SubElement(extended_data, "Data", name="count")
             ET.SubElement(data, "value").text = "{}".format(len(metadata))
             for result in metadata:
                 data = ET.SubElement(
                     extended_data,
                     "Data",
                     id="wifi_{}".format(id_result),
                     name="data",
                 )
                 ET.SubElement(data, "value").text = "{};{};{};{}".format(
                     result.mac_address,
                     result.rssi,
                     result.wifi_channel,
                     result.wifi_type,
                 )
                 id_result += 1
         else:
             instant_scan = None
         self.__add_kml_point(
             name,
             self._folder_wifi,
             coordinates,
             self._style_orange,
             extended_data,
             timestamp=instant_scan,
         )
     elif localization_type == kmlOutput.SCAN_TYPE_GNSS:
         extended_data = ET.Element("ExtendedData")
         if metadata:
             date = metadata[0].instant_scan.strftime("%Y-%m-%d %H:%M:%S")
             data = ET.SubElement(extended_data, "Data", name="date")
             ET.SubElement(data, "value").text = "{}".format(date)
             data = ET.SubElement(extended_data, "Data", name="count")
             ET.SubElement(data, "value").text = "{}".format(len(metadata))
             for index, nav in enumerate(metadata):
                 data = ET.SubElement(
                     extended_data,
                     "Data",
                     id="gnss_{}".format(index),
                     name="data",
                 )
                 ET.SubElement(data, "value").text = "{}".format(",".join(
                     "{}-{}: {}dB".format(sat.constellation,
                                          sat.satellite_id, sat.snr)
                     for sat in nav.satellite_details))
             timestamp = metadata[0].instant_scan
         else:
             timestamp = None
         self.__add_kml_point(
             name,
             self._folder_gnss,
             coordinates,
             self._style_green,
             extended_data,
             timestamp=timestamp,
         )
     elif localization_type == self.SCAN_TYPE_REFERENCE_COORDINATES:
         extended_data = ET.Element("ExtendedData")
         ET.SubElement(extended_data, "Data",
                       name="date").text = "{}".format(metadata)
         self.__add_kml_point(
             name,
             self._folder_reference,
             coordinates,
             self._style_black,
             extended_data,
         )
     else:
         raise NotImplementedError(
             "Type '{}' is not supported'".format(localization_type))

    # write corresponding XDMF meta data file
    # for further info visit
    # https://pymotw.com/2/xml/etree/ElementTree/create.html
    # http://www.xdmf.org/index.php/XDMF_Model_and_Format
    import xml.etree.cElementTree as ET
    from xml.dom import minidom

    def prettify(elem):
        # """Return a pretty-printed XML string for the Element."""
        rough_string = ET.tostring(elem, 'utf-8')
        reparsed = minidom.parseString(rough_string)
        return reparsed.toprettyxml(indent="  ")

    root = ET.Element(" ")
    root.append(ET.Comment('DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []'))

    xdmf = ET.Element('Xdmf')
    xdmf.set("version", "2.0")
    domain=ET.SubElement(xdmf, "Domain")
    grid=ET.SubElement(domain, "Grid")#, {"Topology":"3DRectMesh"})

    topology=ET.SubElement(grid,'Topology')#('''<root><Topology ToplogyType="3DRectMesh" /></root>''')#ET.SubElement
    topology.set("TopologyType","3DRectMesh")
    topology.set("Dimensions",str(nr)+" "+str(nz)+" "+str(nth))

    grid.extend(topology)
    grid.set("Name", "mesh")
    grid.set("GridType", "Uniform")
Exemple #25
0
        if not test_case in language.unimplemented_test_cases():
          test_job = cloud_to_cloud_jobspec(language,
                                            test_case,
                                            server_name,
                                            server_host,
                                            server_port,
                                            docker_image=docker_images.get(str(language)))
          jobs.append(test_job)

  if not jobs:
    print 'No jobs to run.'
    for image in docker_images.itervalues():
      dockerjob.remove_image(image, skip_nonexistent=True)
    sys.exit(1)

  root = ET.Element('testsuites')
  testsuite = ET.SubElement(root, 'testsuite', id='1', package='grpc', name='tests')

  num_failures, resultset = jobset.run(jobs, newline_on_success=True, 
                                       maxjobs=args.jobs, xml_report=testsuite)
  if num_failures:
    jobset.message('FAILED', 'Some tests failed', do_newline=True)
  else:
    jobset.message('SUCCESS', 'All tests passed', do_newline=True)

  tree = ET.ElementTree(root)
  tree.write('report.xml', encoding='UTF-8')
  
  # Generate HTML report.
  render_html_report(set([str(l) for l in languages]), servers,
                     resultset, num_failures)
def xmlConverter(someFile, nameFile, timeSig):
    class Note:
        letter = ''
        Octave = ''
        duration = ''
        typeOfNote = ''  # type of note
        alter = 'not_altered'  # sharp or not
        string = ''
        fret = ''
        voice = '1'
        grace = False

        def __init__(self, letter, Octave):
            self.letter = letter
            self.Octave = Octave

        def setDuration(self, duration):
            self.duration = str(duration)

        def setTypeOfNote(self, typeOfNote):
            self.typeOfNote = typeOfNote

        def isChord(self):
            return False

        def getType(self):
            return self.typeOfNote

        def setAlter(self):
            self.alter = '1'

        def getAlter(self):
            return self.alter

        def setString(self, string):
            self.string = string

        def setFret(self, fret):
            self.fret = str(fret)

        def setVoice(self, voice):
            self.voice = voice

    def whatOctave(string, fret):
        tempoctave = 0

        if string == 5:
            if fret <= 7:  # indexed E = 0 and b = 7 for me -alp: kalin e teli bu
                tempoctave = 2
            else:
                tempoctave = 3
        elif string == 4:  # A
            if fret <= 3:
                tempoctave = 2
            else:
                tempoctave = 3
        elif string == 3:  # D
            if fret <= 9:
                tempoctave = 3
            else:
                tempoctave = 4
        elif string == 2:
            if fret <= 4:
                tempoctave = 3
            else:
                tempoctave = 4
        elif string == 1:
            if fret == 0:
                tempoctave = 3
            elif fret <= 12:
                tempoctave = 4
            else:
                tempoctave = 5
        elif string == 0:
            if fret <= 7:
                tempoctave = 4
            else:
                tempoctave = 5
        else:
            print("String input might be wrong")
        # print string, 'string whattt'
        # print fret, 'fret'

        # print(tempoctave)
        return str(tempoctave)

    # function for type calculation and selection gonna do something later
    def totalTime(timeSelection):
        if timeSelection == '4/4':
            return 4
        elif timeSelection == '3/4':
            return 3
        elif timeSelection == '2/4':
            return 2

    # ======== GONNA CHANGE IT LATER
    def noteTypeHelper(note, whatType):
        typeOfNotes = ["16th", "eighth", "quarter", "half", "whole"]

        if whatType <= 0.3:
            note.setTypeOfNote(typeOfNotes[0])
            note.setDuration("0.5")  # 1th
        elif whatType <= 0.6:
            note.setTypeOfNote(typeOfNotes[1])  # eight
            note.setDuration(1)
        elif whatType <= 1.3:
            note.setTypeOfNote(typeOfNotes[2])  # quarter
            note.setDuration(2)
        elif whatType <= 2.3:
            note.setTypeOfNote(typeOfNotes[3])  # half
            note.setDuration(4)
        elif whatType <= 4:
            note.setTypeOfNote(typeOfNotes[4])  # whole
            note.setDuration(8)

    def noteTypeCalculator(arrOfNotes, lengthOfBar):
        typeOfNotes = ["16th", "eighth", "quarter", "half", "whole"]
        # trying something out here with the length
        tempLength = lengthOfBar - 1
        totalQuarterNoteTime = totalTime("4/4")

        for j in range(0, len(arrOfNotes)):
            # it takes 4 quarter notes to play
            if arrOfNotes[j] != 'measure':
                notePosition = arrOfNotes[j][1]
                note = arrOfNotes[j][0]
                nextNotePosition = -1

                if j != len(arrOfNotes) - 2:
                    if arrOfNotes[j + 1] == 'measure':
                        nextNotePosition = arrOfNotes[j + 2][1]
                    else:
                        nextNotePosition = arrOfNotes[j + 1][1]

                    if nextNotePosition <= notePosition:
                        nextNotePosition = lengthOfBar

                # if there are no notes until the next | which resets the numbers
                else:
                    nextNotePosition = lengthOfBar
                # variables are set for comparison
                # print nextNotePosition, 'next note'
                # print notePosition, 'not position 2'
                difference = (nextNotePosition - notePosition)
                how_much_ratio = float(difference) / tempLength
                whatType = how_much_ratio * totalQuarterNoteTime
                if len(arrOfNotes[j]) > 2:
                    # later idea below
                    # for i in range(0, len(arrOfNotes[j]) - 1, 2):
                    # min = whatType
                    for i in range(
                            0, len(arrOfNotes[j]), 2
                    ):  # need to increment by 2 for chords because i am sleepy and i f****d up
                        noteTypeHelper(arrOfNotes[j][i], whatType)
                else:
                    noteTypeHelper(note, whatType)

    f = open(someFile, "r")
    text = f.read().split()
    textarr = []

    # Python3 program to Split string into characters
    for t in text:
        textarr.append(list(t))

    numpy_array = np.array(textarr)
    transpose = numpy_array.T
    transpose_list = transpose.tolist()

    def duration(fret):  # find the next occurence of a number
        dur = 0

        for i in range(fret, len(transpose_list)):
            if transpose_list[i][0] == "-" and len(
                    set(transpose_list[i])
            ) == 1:  # if the first "|" occurs, then the first measure starts
                dur += 1
            else:
                break
        if dur > 8:
            return 8
        else:
            return dur

    durations = []
    for i in range(len(transpose_list)):
        durations.append(duration(i))

    notes = []

    ##function gets the name of the note that was played
    def noteFun(_string, fret):
        enote = [
            "F", "F#", "G", "G#", "A", "A#", "B", "C", "C#", "D", "D#", "E"
        ]

        enote = [
            "F", "F#", "G", "G#", "A", "A#", "B", "C", "C#", "D", "D#", "E"
        ]

        switcher = {  # default tuning mapping based of string.
            0: ["E", "F", "F#", "G", "G#", "A", "A#", "B", "C", "C#", "D", "D#", "E"],
            1: ["B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"],
            2: ["G", "G#", "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G"],
            3: ["D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "C", "C#", "D"],
            4: ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A"],
            5: ["E", "F", "F#", "G", "G#", "A", "A#", "B", "C", "C#", "D", "D#", "E"],
        }

        return switcher.get(_string)[fret]

    def isChord(fret):
        if len(set(fret)) > 2:
            return True
        else:
            return False

    def isNum(x):
        num = [
            "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "13",
            "14"
        ]
        return x in num

    def numToString(n):
        letters = ["E", "A", "D", "G", "B", "E"]
        return letters[n]

    score_partwise = ET.Element("score-partwise", version="3.1")
    part_list = ET.SubElement(score_partwise, "part-list")

    score_part = ET.SubElement(part_list, "score-part", id="P1")

    part_name = ET.SubElement(
        score_part, "part-name"
    ).text = "Classical Guitar"  # input part name here from user

    part = ET.SubElement(score_partwise, "part", id="P1")

    tree = ET.ElementTree(score_partwise)

    # place notes

    def makeNote(letter, octave):
        return Note(letter, octave)

    def isAlter(alterednote):
        arrOfAlter = ['F#', 'G#', 'A#', 'C#', 'D#']
        arrOfNonAlter = ['F', 'G', 'A', 'C', 'D']
        if alterednote in arrOfAlter:
            return arrOfNonAlter[arrOfAlter.index(alterednote)]
        else:
            return False

    def isLetter(string):
        arr = ['h', 'p', 'g']
        if string in arr:
            return True
        else:
            return False

    # function that takes one line until the '|' and sets everything for that line only, call a for loop later
    def noteArrayMaker(tra_list):
        notesAndChords = []
        position = -1
        length = 0
        barNumber = -1
        for idx, vertLine in enumerate(tra_list):
            if idx == len(tra_list) - 1:
                notesAndChords.append('measure')
                barNumber += 1
            else:
                if vertLine[1] != '|':
                    position += 1
                    length += 1
                else:
                    barNumber += 1
                    position = -1
                    notesAndChords.append('measure')
                tempList = []

                # the list of chars are tralist [[][][][][]]
                for i in range(0, len(vertLine)):
                    isItLetters = False
                    isGrace = False
                    string = vertLine[i]
                    backString = tra_list[idx - 1][i]
                    if isNum(string):
                        nextString = tra_list[idx + 1][i]
                        nextNextString = tra_list[idx + 2][i]

                        if isNum(backString):
                            pass
                        else:
                            if isLetter(backString):
                                if backString == 'g':
                                    isGrace = True

                            if isNum(nextString):
                                string = string + nextString

                            if not isAlter(noteFun(i, int(string))):
                                tempNote = makeNote(noteFun(i, int(string)),
                                                    whatOctave(i, int(string)))
                                # print tempNote.letter
                                tempNote.setString(i)
                                tempNote.setFret(string)
                                tempList.append(tempNote)
                                if isGrace:
                                    tempNote.grace = True
                            else:
                                # makes a note with the parameter type (the letter) and the octave of that note which are set
                                tempNote = makeNote(
                                    isAlter(noteFun(i, int(string))),
                                    whatOctave(i, int(string)))
                                tempNote.setAlter()
                                tempNote.setString(i)
                                tempNote.setFret(int(string))
                                tempList.append(tempNote)
                                if isGrace:
                                    tempNote.grace = True
                            tempList.append(position)

                if len(tempList) >= 1:
                    notesAndChords.append(tempList)
            # end of first for loop
        # after all the notes are done the second for loop

        noteTypeCalculator(notesAndChords, length / barNumber, "4/4")
        return notesAndChords

    def startProgram(arr):
        m = 1
        chordPresent = False
        for idx, lists in enumerate(noteArrayMaker(arr)):
            if lists == 'measure':
                if idx != len(noteArrayMaker(arr)) - 1:
                    measure = ET.SubElement(part, "measure",
                                            number=str(m))  # place a measure
                if m == 1:
                    attributes = ET.SubElement(measure, "attributes")
                    divisions = ET.SubElement(attributes,
                                              "divisions").text = str(2)
                    key = ET.SubElement(attributes, "key")
                    fifths = ET.SubElement(key, "fifths").text = str(0)
                    t = ET.SubElement(attributes, "time")
                    if timeSig[0] == "1/4":
                        _beats = ET.SubElement(t, "beats").text = str(1)
                        beats_type = ET.SubElement(t,
                                                   "beats_type").text = str(4)
                    elif timeSig[0] == "2/4":
                        _beats = ET.SubElement(t, "beats").text = str(2)
                        beats_type = ET.SubElement(t,
                                                   "beats_type").text = str(4)
                    elif timeSig[0] == "3/4":
                        _beats = ET.SubElement(t, "beats").text = str(3)
                        beats_type = ET.SubElement(t,
                                                   "beats_type").text = str(4)
                    elif timeSig[0] == "4/4":
                        _beats = ET.SubElement(t, "beats").text = str(4)
                        beats_type = ET.SubElement(t,
                                                   "beats_type").text = str(4)

                    clef = ET.SubElement(attributes, "clef")
                    sign = ET.SubElement(clef, "sign").text = "TAB"
                    line = ET.SubElement(clef, "line").text = str(5)
                    staff_details = ET.SubElement(attributes, "staff-details")
                    staff_lines = ET.SubElement(staff_details,
                                                "staff-lines").text = "6"
                    for i in range(6):
                        staff_tuning_line = ET.SubElement(staff_details,
                                                          "staff-tuning",
                                                          line="{}".format(
                                                              (i + 1)))
                        tuning_step = ET.SubElement(
                            staff_tuning_line,
                            "tuning-step").text = numToString(i)
                        switcher = {  # default tuning mapping based of string.
                            0: "2",
                            1: "2",
                            2: "3",
                            3: "3",
                            4: "3",
                            5: "4",
                        }
                        tuning_octave = ET.SubElement(
                            staff_tuning_line,
                            "tuning-octave").text = switcher.get(i)
                m += 1
            else:
                if len(lists) > 2:
                    for i in range(0, len(lists), 2):
                        # note definition for chords
                        noteObject = lists[i]
                        note = ET.SubElement(measure, "note")

                        # trying the chord thing out
                        if not chordPresent:
                            chordPresent = True
                        else:
                            chord = ET.SubElement(note, "chord")
                        pitch = ET.SubElement(note, "pitch")
                        step = ET.SubElement(pitch,
                                             "step").text = noteObject.letter
                        if noteObject.alter != 'not_altered':
                            alter = ET.SubElement(
                                pitch, "alter").text = noteObject.alter
                        octave = ET.SubElement(
                            pitch, "octave").text = noteObject.Octave
                        ET.SubElement(note,
                                      "duration").text = noteObject.duration
                        voice = ET.SubElement(note,
                                              "voice").text = noteObject.voice
                        type = ET.SubElement(
                            note, "type").text = noteObject.typeOfNote
                        notations = ET.SubElement(note, "notations")
                        technical = ET.SubElement(notations, "technical")
                        string = ET.SubElement(
                            technical,
                            "string").text = str(int(noteObject.string) + 1)
                        fret = ET.SubElement(technical, "fret").text = str(
                            noteObject.fret)
                else:
                    chordPresent = False
                    noteObject = lists[0]
                    note = ET.SubElement(measure, "note")
                    if noteObject.grace:
                        ET.SubElement(note, "grace")
                    pitch = ET.SubElement(note, "pitch")
                    step = ET.SubElement(pitch,
                                         "step").text = noteObject.letter
                    if noteObject.alter != 'not_altered':
                        alter = ET.SubElement(pitch,
                                              "alter").text = noteObject.alter
                    octave = ET.SubElement(pitch,
                                           "octave").text = noteObject.Octave
                    ET.SubElement(note, "duration").text = noteObject.duration
                    voice = ET.SubElement(note,
                                          "voice").text = noteObject.voice
                    type = ET.SubElement(note,
                                         "type").text = noteObject.typeOfNote
                    notations = ET.SubElement(note, "notations")
                    technical = ET.SubElement(notations, "technical")
                    string = ET.SubElement(
                        technical,
                        "string").text = str(int(noteObject.string) + 1)
                    fret = ET.SubElement(technical,
                                         "fret").text = noteObject.fret

    # methods for object to xml
    # for note in range(0, len(noteArrayMaker(transpose_list)[0]) - 1, 2):
    # print noteArrayMaker(transpose_list)[0][note].getType()
    startProgram(transpose_list)

    xmlstr = minidom.parseString(
        ET.tostring(score_partwise)).toprettyxml(indent="   ")

    tree.write(nameFile)

    with open(nameFile, "w") as f:
        f.write(xmlstr)
Exemple #27
0
def eadheader(eadheader_root, CSheet):

    #update GUI progress bar
    if "ask_gui" in globals.new_elements:
        import wx
        from wx.lib.pubsub import pub
        wx.CallAfter(pub.sendMessage, "update", msg="Writing <eadheader>...")

    # <eadheader> @findaidstatus
    if CSheet.find('DraftStatus').text:
        eadheader_root.set('findaidstatus', CSheet.find('DraftStatus').text)
    elif "findaidstatus" in eadheader_root.attrib:
        eadheader_root.set('findaidstatus', "")

    #<eadid>
    if eadheader_root.find('eadid') is None:
        error(
            "The EAD template you used does not contained an <eadid> tag. Since this is a required element in EAD2002, one will be added.",
            False)
        eadid_element = ET.Element('eadid')
        eadheader_root.insert(0, eadid_element)
    template_id = eadheader_root.find('eadid')
    if CSheet.find('CollectionID').text:
        template_id.text = CSheet.find('CollectionID').text
    else:
        error(
            "You did not enter a CollectionID. The <eadid> tag will be empty.",
            False)
        template_id.text = ""
    if CSheet.find('URL').text:
        template_id.set('url', CSheet.find('URL').text)
    elif "url" in template_id.attrib:
        template_id.set('url', "")
    if CSheet.find('CountryCode').text:
        template_id.set('countrycode', CSheet.find('CountryCode').text)

    #<filedesc>
    if eadheader_root.find('filedesc') is None:
        error(
            "The EAD template you used does not contain a <filedesc> tag. Since this is a required element in EAD2002, one will be added.",
            False)
        filedesc_element = ET.Element('filedesc')
        eadheader_root.insert(1, filedesc_element)
    #<titlestmt>
    if eadheader_root.find('filedesc/titlestmt') is None:
        error(
            "The EAD template you used does not contain a <titlestmt> tag. Since this is a required element in EAD2002, one will be added.",
            False)
        titlestmt_element = ET.Element('titlestmt')
        eadheader_root.find('filedesc').insert(0, titlestmt_element)
    #<titleproper>
    if eadheader_root.find('filedesc/titlestmt/titleproper') is None:
        error(
            "The EAD template you used does not contain a <titleproper> tag. Since this is a required element in EAD2002, one will be added.",
            False)
        titleproper_element = ET.Element('titleproper')
        eadheader_root.find('filedesc/titlestmt').insert(
            0, titleproper_element)
    template_titleproper = eadheader_root.find(
        'filedesc/titlestmt/titleproper')
    if CSheet.find('CollectionName').text:
        if "ask_ualbany" in globals.new_elements:
            if "nam_" in CSheet.find('CollectionID').text:
                CID_only = CSheet.find('CollectionID').text.split('_')[1]
            else:
                CID_only = CSheet.find('CollectionID').text
            if CID_only.lower().startswith('ua'):
                Coll_number = CID_only.replace('ua', '')
                display_CID = "UA-" + Coll_number
            elif CID_only.lower().startswith('apap'):
                Coll_number = CID_only.replace('apap', '')
                display_CID = "APAP-" + Coll_number
            elif CID_only.lower().startswith('mss'):
                Coll_number = CID_only.replace('mss', '')
                display_CID = "MSS-" + Coll_number
            elif CID_only.lower().startswith('ger'):
                Coll_number = CID_only.replace('ger', '')
                display_CID = "GER-" + Coll_number
            else:
                display_CID = CID_only
            ualbany_titleproper = CSheet.find('CollectionName').text.upper(
            ) + " (" + display_CID.upper() + "),"
            template_titleproper.text = ualbany_titleproper
        else:
            template_titleproper.text = CSheet.find('CollectionName').text
    else:
        template_titleproper.text = ""

    #<date>
    if eadheader_root.find('filedesc/titlestmt/titleproper/date') is None:
        pass
    else:
        template_date = eadheader_root.find(
            'filedesc/titlestmt/titleproper/date')
        if CSheet.find('DateInclusive').text:
            template_date.text = CSheet.find('DateInclusive').text
            if CSheet.find('DateInclusiveNormal').text:
                template_date.attrib['normal'] = CSheet.find(
                    'DateInclusiveNormal').text
            else:
                template_date.attrib['normal'] = CSheet.find(
                    'DateInclusive').text
        else:
            if eadheader_root.find(
                    'filedesc/titlestmt/titleproper/date') is None:
                pass
            else:
                eadheader_root.find(
                    'filedesc/titlestmt/titleproper/date').text = ""

    #<subtitle>
    if CSheet.find('Subtitle').text:
        if eadheader_root.find('filedesc/titlestmt/subtitle') is None:
            if "add_subtitle" in globals.new_elements or "add-all" in globals.add_all:
                subtitle_element = ET.Element('subtitle')
                eadheader_root.find('filedesc/titlestmt').insert(
                    1, subtitle_element)
                subtitle_element.text = CSheet.find('Subtitle').text
        else:
            old_sub_list = eadheader_root.find('filedesc/titlestmt').findall(
                'subtitle')
            for old_sub in old_sub_list:
                eadheader_root.find('filedesc/titlestmt').remove(old_sub)
            subtitle_element = ET.Element('subtitle')
            eadheader_root.find('filedesc/titlestmt').insert(
                1, subtitle_element)
            subtitle_element.text = CSheet.find('Subtitle').text
    else:
        old_sub_list = eadheader_root.find('filedesc/titlestmt').findall(
            'subtitle')
        for old_sub in old_sub_list:
            eadheader_root.find('filedesc/titlestmt').remove(old_sub)

    #<author>
    if CSheet.find('ProcessedBy').text:
        if eadheader_root.find('filedesc/titlestmt/author') is None:
            if "add_author" in globals.new_elements or "add-all" in globals.add_all:
                author_element = ET.Element('author')
                if eadheader_root.find('filedesc/titlestmt/subtitle') is None:
                    author_index = 1
                else:
                    author_index = 2
                eadheader_root.find('filedesc/titlestmt').insert(
                    author_index, author_element)
                author_element.text = CSheet.find('ProcessedBy').text
        else:
            eadheader_root.find('filedesc/titlestmt/author'
                                ).text = CSheet.find('ProcessedBy').text
    else:
        old_auth_list = eadheader_root.find('filedesc/titlestmt').findall(
            'author')
        for old_auth in old_auth_list:
            eadheader_root.find('filedesc/titlestmt').remove(old_auth)

    #<sponsor>
    if CSheet.find('Sponsor').text:
        if eadheader_root.find('filedesc/titlestmt/sponsor') is None:
            if "add_sponsor" in globals.new_elements or "add-all" in globals.add_all:
                sponsor_element = ET.Element('sponsor')
                eadheader_root.find('filedesc/titlestmt').append(
                    sponsor_element)
                sponsor_element.text = CSheet.find('Sponsor').text
        else:
            eadheader_root.find('filedesc/titlestmt/sponsor'
                                ).text = CSheet.find("Sponsor").text
    else:
        old_spon_list = eadheader_root.find('filedesc/titlestmt').findall(
            'sponsor')
        for old_spon in old_spon_list:
            eadheader_root.find('filedesc/titlestmt').remove(old_spon)

    # Edition Statement Section
    from editionstmt import editionstmt
    editionstmt(eadheader_root, CSheet)

    # Publication Statement Section
    from publicationstmt import publicationstmt
    publicationstmt(eadheader_root, CSheet)

    # Series Statement Section
    from seriesstmt import seriesstmt
    seriesstmt(eadheader_root, CSheet)

    # Note Statement Section
    if CSheet.find('NoteStatements/NoteStatement') is None:
        pass
    else:
        if CSheet.find('NoteStatements/NoteStatement').text:
            if eadheader_root.find('filedesc/notestmt') is None:
                if "add_notestmt" in globals.new_elements or "add-all" in globals.add_all:
                    notestmt_element = ET.Element('notestmt')
                    eadheader_root.find('filedesc').append(notestmt_element)
                    notestmt = eadheader_root.find('filedesc/notestmt')
                    for note_info in CSheet.find('NoteStatements'):
                        cnote_element = ET.Element('note')
                        p_element = ET.Element('p')
                        notestmt.append(cnote_element)
                        cnote_element.append(p_element)
                        p_element.text = note_info.text
            else:
                notestmt = eadheader_root.find('filedesc/notestmt')
                notestmt.clear()
                for note_info in CSheet.find('NoteStatements'):
                    cnote_element = ET.Element('note')
                    p_element = ET.Element('p')
                    notestmt.append(cnote_element)
                    cnote_element.append(p_element)
                    p_element.text = note_info.text

    # Profile Description
    if CSheet.find('EADCreator').text or CSheet.find(
            'EADCreationDate').text or CSheet.find(
                'FindingAidLanguages/FALanguage/Lang').text or CSheet.find(
                    'StandardConventions/Convention/Citation'
                ).text or CSheet.find(
                    'LocalConventions/Convention/Citation').text:
        if eadheader_root.find('profiledesc') is None:
            if "add_profile" in globals.new_elements or "add-all" in globals.add_all:
                profile_element = ET.Element('profiledesc')
                last_filedesc = eadheader_root.getchildren().index(
                    eadheader_root.find('filedesc')) + 1
                eadheader_root.insert(last_filedesc, profile_element)
    else:
        if eadheader_root.find('profiledesc') is None:
            pass
        else:
            eadheader_root.find('profiledesc').clear()

    # EAD creation and EAD creation date
    if CSheet.find('EADCreator').text or CSheet.find('EADCreationDate').text:
        if eadheader_root.find('profiledesc') is None:
            pass
        else:
            if eadheader_root.find('profiledesc/creation') is None:
                if "add_eadcre" in globals.new_elements or "add-all" in globals.add_all:
                    creator_element = ET.Element('creation')
                    eadheader_root.find('profiledesc').insert(
                        0, creator_element)
                    if CSheet.find('EADCreator').text:
                        creator_element.text = CSheet.find('EADCreator').text
                    if CSheet.find('EADCreationDate').text:
                        credate_element = ET.Element('date')
                        creator_element.append(credate_element)
                        credate_element.text = CSheet.find(
                            'EADCreationDate').text
                        if CSheet.find('EADCreationDateNormal').text is None:
                            credate_element.attrib['normal'] = CSheet.find(
                                'EADCreationDate').text
                        else:
                            credate_element.attrib['normal'] = CSheet.find(
                                'EADCreationDateNormal').text
            else:
                template_creator = eadheader_root.find('profiledesc/creation')
                if CSheet.find('EADCreator').text:
                    template_creator.text = CSheet.find('EADCreator').text
                if CSheet.find('EADCreationDate').text:
                    if template_creator.find('date') is None:
                        template_creator.text = template_creator.text + " - " + CSheet.find(
                            'EADCreationDate').text
                    else:
                        template_creatordate = template_creator.find('date')
                        template_creatordate.text = CSheet.find(
                            'EADCreationDate').text
                        if CSheet.find('EADCreationDateNormal').text is None:
                            template_creatordate.attrib[
                                'normal'] = CSheet.find('EADCreationDate').text
                        else:
                            template_creatordate.attrib[
                                'normal'] = CSheet.find(
                                    'EADCreationDateNormal').text

    # Languages
    if CSheet.find('FindingAidLanguages/FALanguage/Lang').text:
        if eadheader_root.find('profiledesc') is None:
            pass
        else:
            if eadheader_root.find('profiledesc/langusage') is None:
                if "add_lang1" in globals.new_elements or "add-all" in globals.add_all:
                    langusage_element = ET.Element('langusage')
                    eadheader_root.find('profiledesc').append(
                        langusage_element)
                    for lang in CSheet.find('FindingAidLanguages'):
                        if lang.find('Lang').text:
                            lang_element = ET.Element('language')
                            eadheader_root.find(
                                'profiledesc/langusage').append(lang_element)
                            lang_element.text = lang.find('Lang').text
                            if lang.find('LangCode').text:
                                lang_element.set('langcode',
                                                 lang.find('LangCode').text)
                            if lang.find('LangNote').text:
                                lang_element.tail = ", " + lang.find(
                                    'LangNote').text
            else:
                if eadheader_root.find(
                        'profiledesc/langusage/language') is None:
                    for lang in CSheet.find('FindingA:idLanguages'):
                        if lang.find('Lang').text:
                            lang_element = ET.Element('language')
                            eadheader_root.find(
                                'profiledesc/langusage').append(lang_element)
                            lang_element.text = lang.find('Lang').text
                            if lang.find('LangCode').text:
                                lang_element.set('langcode',
                                                 lang.find('LangCode').text)
                            if lang.find('LangNote').text:
                                lang_element.tail = ", " + lang.find(
                                    'LangNote').text
                else:
                    lang_attrib = eadheader_root.find(
                        'profiledesc/langusage/language').attrib.get(
                            "encodinganalog", None)
                    eadheader_root.find('profiledesc/langusage').clear()
                    for lang in CSheet.find('FindingAidLanguages'):
                        if lang.find('Lang').text:
                            lang_element = ET.Element('language')
                            if lang_attrib is None:
                                pass
                            else:
                                if len(lang_attrib) > 0:
                                    lang_element.set('encodinganalog',
                                                     lang_attrib)
                            eadheader_root.find(
                                'profiledesc/langusage').append(lang_element)
                            lang_element.text = lang.find('Lang').text
                            if lang.find('LangCode').text:
                                lang_element.set('langcode',
                                                 lang.find('LangCode').text)
                            if lang.find('LangNote').text:
                                lang_element.tail = ", " + lang.find(
                                    'LangNote').text

    #update GUI progress bar
    if "ask_gui" in globals.new_elements:
        import wx
        from wx.lib.pubsub import pub
        wx.CallAfter(pub.sendMessage,
                     "update",
                     msg="Writing description rules...")

    # Description Rules
    if CSheet.find(
            'StandardConventions/Convention/Citation').text or CSheet.find(
                'LocalConventions/Convention/Citation').text:
        if eadheader_root.find('profiledesc') is None:
            pass
        else:
            if eadheader_root.find('profiledesc/descrules') is None:
                if "add_descrule" in globals.new_elements or "add-all" in globals.add_all:
                    descrule_element = ET.Element('descrules')
                    eadheader_root.find('profiledesc').append(descrule_element)
                    for rule in CSheet.find('StandardConventions'):
                        if rule.find('Citation').text:
                            if rule.find('Abbreviation').text:
                                if eadheader_root.find(
                                        'profiledesc/descrules').text:
                                    eadheader_root.find(
                                        'profiledesc/descrules'
                                    ).text = eadheader_root.find(
                                        'profiledesc/descrules'
                                    ).text + ", " + rule.find(
                                        'Citation').text + " (" + rule.find(
                                            'Abbreviation').text + ")"
                                else:
                                    eadheader_root.find(
                                        'profiledesc/descrules'
                                    ).text = rule.find(
                                        'Citation').text + " (" + rule.find(
                                            'Abbreviation').text + ")"
                            else:
                                if eadheader_root.find(
                                        'profiledesc/descrules').text:
                                    eadheader_root.find(
                                        'profiledesc/descrules'
                                    ).text = eadheader_root.find(
                                        'profiledesc/descrules'
                                    ).text + ", " + rule.find('Citation').text
                                else:
                                    eadheader_root.find('profiledesc/descrules'
                                                        ).text = rule.find(
                                                            'Citation').text
                            if rule.find('ConventionLink').text:
                                eadheader_root.find(
                                    'profiledesc/descrules'
                                ).text = eadheader_root.find(
                                    'profiledesc/descrules'
                                ).text + ": " + rule.find(
                                    'ConventionLink').text
                    for rule in CSheet.find('LocalConventions'):
                        if rule.find('Citation').text:
                            if rule.find('Abbreviation').text:
                                if eadheader_root.find(
                                        'profiledesc/descrules').text:
                                    eadheader_root.find(
                                        'profiledesc/descrules'
                                    ).text = eadheader_root.find(
                                        'profiledesc/descrules'
                                    ).text + ", " + rule.find(
                                        'Citation').text + " (" + rule.find(
                                            'Abbreviation').text + ")"
                                else:
                                    eadheader_root.find(
                                        'profiledesc/descrules'
                                    ).text = rule.find(
                                        'Citation').text + " (" + rule.find(
                                            'Abbreviation').text + ")"
                            else:
                                if eadheader_root.find(
                                        'profiledesc/descrules').text:
                                    eadheader_root.find(
                                        'profiledesc/descrules'
                                    ).text = eadheader_root.find(
                                        'profiledesc/descrules'
                                    ).text + ", " + rule.find('Citation').text
                                else:
                                    eadheader_root.find('profiledesc/descrules'
                                                        ).text = rule.find(
                                                            'Citation').text
                            if rule.find('ConventionLink').text:
                                eadheader_root.find(
                                    'profiledesc/descrules'
                                ).text = eadheader_root.find(
                                    'profiledesc/descrules'
                                ).text + ": " + rule.find(
                                    'ConventionLink').text
            else:
                eadheader_root.find('profiledesc/descrules').clear()
                for rule in CSheet.find('StandardConventions'):
                    if rule.find('Citation').text:
                        if rule.find('Abbreviation').text:
                            if eadheader_root.find(
                                    'profiledesc/descrules').text:
                                eadheader_root.find(
                                    'profiledesc/descrules'
                                ).text = eadheader_root.find(
                                    'profiledesc/descrules'
                                ).text + ", " + rule.find(
                                    'Citation').text + " (" + rule.find(
                                        'Abbreviation').text + ")"
                            else:
                                eadheader_root.find(
                                    'profiledesc/descrules').text = rule.find(
                                        'Citation').text + " (" + rule.find(
                                            'Abbreviation').text + ")"
                        else:
                            if eadheader_root.find(
                                    'profiledesc/descrules').text:
                                eadheader_root.find(
                                    'profiledesc/descrules'
                                ).text = eadheader_root.find(
                                    'profiledesc/descrules'
                                ).text + ", " + rule.find('Citation').text
                            else:
                                eadheader_root.find(
                                    'profiledesc/descrules').text = rule.find(
                                        'Citation').text
                        if rule.find('ConventionLink').text:
                            eadheader_root.find(
                                'profiledesc/descrules'
                            ).text = eadheader_root.find(
                                'profiledesc/descrules'
                            ).text + ": " + rule.find('ConventionLink').text
                for rule in CSheet.find('LocalConventions'):
                    if rule.find('Citation').text:
                        if rule.find('Abbreviation').text:
                            if eadheader_root.find(
                                    'profiledesc/descrules').text:
                                eadheader_root.find(
                                    'profiledesc/descrules'
                                ).text = eadheader_root.find(
                                    'profiledesc/descrules'
                                ).text + ", " + rule.find(
                                    'Citation').text + " (" + rule.find(
                                        'Abbreviation').text + ")"
                            else:
                                eadheader_root.find(
                                    'profiledesc/descrules').text = rule.find(
                                        'Citation').text + " (" + rule.find(
                                            'Abbreviation').text + ")"
                        else:
                            if eadheader_root.find(
                                    'profiledesc/descrules').text:
                                eadheader_root.find(
                                    'profiledesc/descrules'
                                ).text = eadheader_root.find(
                                    'profiledesc/descrules'
                                ).text + ", " + rule.find('Citation').text
                            else:
                                eadheader_root.find(
                                    'profiledesc/descrules').text = rule.find(
                                        'Citation').text
                        if rule.find('ConventionLink').text:
                            eadheader_root.find(
                                'profiledesc/descrules'
                            ).text = eadheader_root.find(
                                'profiledesc/descrules'
                            ).text + ": " + rule.find('ConventionLink').text

    if "ask_gui" in globals.new_elements:
        wx.CallAfter(pub.sendMessage,
                     "update",
                     msg="Writing <revisiondesc>...")
    # revision
    if CSheet.find('Revisions/Event/Date') is None:
        pass
    else:
        if CSheet.find('Revisions/Event/Date').text:
            if eadheader_root.find('revisiondesc') is None:
                if "add_revisions" in globals.new_elements or "add-all" in globals.add_all:
                    rev_element = ET.Element('revisiondesc')
                    if eadheader_root.find('profiledesc') is None:
                        revision_place = 2
                    else:
                        revision_place = 3
                    eadheader_root.insert(revision_place, rev_element)
                    revision_root = eadheader_root.find('revisiondesc')
                    for event in CSheet.find('Revisions'):
                        change_element = ET.Element('change')
                        revision_root.append(change_element)
                        date_element = ET.Element('date')
                        change_element.append(date_element)
                        date_element.text = event.find('Date').text
                        if event.find('DateNormal').text:
                            date_element.set('normal',
                                             event.find('DateNormal').text)
                        else:
                            date_element.set('normal', event.find('Date').text)
                        item_element = ET.Element('item')
                        change_element.append(item_element)
                        if event.find('Type').text:
                            item_element.text = event.find('Type').text
                            if event.find('Description').text:
                                item_element.text = item_element.text + ': ' + event.find(
                                    'Description').text
                                if event.find('Agent').text:
                                    item_element.text = item_element.text + ' (' + event.find(
                                        'Agent').text + ')'
                        elif event.find('Description').text:
                            item_element.text = event.find('Description').text
                            if event.find('Agent').text:
                                item_element.text = item_element.text + ' (' + event.find(
                                    'Agent').text + ')'
            else:
                revision_root = eadheader_root.find('revisiondesc')
                if revision_root.find('list') is None and revision_root.find(
                        'change') is None:  #if nothing
                    for event in CSheet.find('Revisions'):
                        change_element = ET.Element('change')
                        revision_root.append(change_element)
                        date_element = ET.Element('date')
                        change_element.append(date_element)
                        date_element.text = event.find('Date').text
                        if event.find('DateNormal').text:
                            date_element.set('normal',
                                             event.find('DateNormal').text)
                        item_element = ET.Element('item')
                        change_element.append(item_element)
                        if event.find('Type').text:
                            item_element.text = event.find('Type').text
                            if event.find('Description').text:
                                item_element.text = item_element.text + ': ' + event.find(
                                    'Description').text
                                if event.find('Agent').text:
                                    item_element.text = item_element.text + ' (' + event.find(
                                        'Agent').text + ')'
                        elif event.find('Description').text:
                            item_element.text = event.find('Description').text
                            if event.find('Agent').text:
                                item_element.text = item_element.text + ' (' + event.find(
                                    'Agent').text + ')'
                elif revision_root.find('change') is None:  #if list
                    revision_root.find('list').clear()
                    for event in CSheet.find('Revisions'):
                        item_element = ET.Element('item')
                        revision_root.find('list').append(item_element)
                        date_element = ET.Element('date')
                        item_element.append(date_element)
                        date_element.text = event.find('Date').text
                        if event.find('DateNormal').text:
                            date_element.set('normal',
                                             event.find('DateNormal').text)
                        if event.find('Type').text:
                            item_element.text = event.find('Type').text
                            if event.find('Description').text:
                                item_element.text = item_element.text + ': ' + event.find(
                                    'Description').text
                                if event.find('Agent').text:
                                    item_element.text = item_element.text + ' (' + event.find(
                                        'Agent').text + ')'
                        elif event.find('Description').text:
                            item_element.text = event.find('Description').text
                            if event.find('Agent').text:
                                item_element.text = item_element.text + ' (' + event.find(
                                    'Agent').text + ')'
                else:  # if change
                    revision_root.clear()
                    for event in CSheet.find('Revisions'):
                        change_element = ET.Element('change')
                        revision_root.append(change_element)
                        date_element = ET.Element('date')
                        change_element.append(date_element)
                        date_element.text = event.find('Date').text
                        if event.find('DateNormal').text:
                            date_element.set('normal',
                                             event.find('DateNormal').text)
                        item_element = ET.Element('item')
                        change_element.append(item_element)
                        if event.find('Type').text:
                            item_element.text = event.find('Type').text
                            if event.find('Description').text:
                                item_element.text = item_element.text + ': ' + event.find(
                                    'Description').text
                                if event.find('Agent').text:
                                    item_element.text = item_element.text + ' (' + event.find(
                                        'Agent').text + ')'
                        elif event.find('Description').text:
                            item_element.text = event.find('Description').text
                            if event.find('Agent').text:
                                item_element.text = item_element.text + ' (' + event.find(
                                    'Agent').text + ')'
Exemple #28
0
            if ep_obj.show.dvdorder != 0:
                lINDEXER_API_PARMS['dvdorder'] = True

            t = sickbeard.indexerApi(
                ep_obj.show.indexer).indexer(**lINDEXER_API_PARMS)
            myShow = t[ep_obj.show.indexerid]
        except sickbeard.indexer_shownotfound, e:
            raise exceptions.ShowNotFoundException(e.message)
        except sickbeard.indexer_error, e:
            logger.log(
                u"Unable to connect to TVDB while creating meta files - skipping - "
                + ex(e), logger.ERROR)
            return False

        rootNode = etree.Element("details")
        movie = etree.SubElement(rootNode, "movie")

        movie.attrib["isExtra"] = "false"
        movie.attrib["isSet"] = "false"
        movie.attrib["isTV"] = "true"

        # write an MediaBrowser XML containing info for all matching episodes
        for curEpToWrite in eps_to_write:

            try:
                myEp = myShow[curEpToWrite.season][curEpToWrite.episode]
            except (sickbeard.indexer_episodenotfound,
                    sickbeard.indexer_seasonnotfound):
                logger.log(
                    u"Unable to find episode " + str(curEpToWrite.season) +
Exemple #29
0
def _saveSceneShots(sceneName, shots):
    sceneFile = os.path.join(ScenesPath(), sceneName + SCENE_EXT)
    xScene = ParseXMLWithIncludes(sceneFile)

    # save user camera position per scene
    userFile = ProjectFile() + '.user'
    if fileutil.exists(userFile):
        xUser = ParseXMLWithIncludes(userFile)
    else:
        xUser = cElementTree.Element('user')
    if sceneFile in Scene.cache:
        cameraData = Scene.cache[sceneFile].cameraData()
        if cameraData:
            for xSub in xUser:
                if xSub.tag == 'scene' and xSub.attrib['name'] == sceneName:
                    xSub.attrib['camera'] = ','.join(
                        [str(x) for x in cameraData])
                    break
            else:
                cElementTree.SubElement(
                    xUser, 'scene', {
                        'name': sceneName,
                        'camera': ','.join([str(x) for x in cameraData])
                    })
    with fileutil.edit(userFile) as fh:
        fh.write(toPrettyXml(xUser))

    # remove old shots
    r = []
    for xShot in xScene:
        r.append(xShot)
    for s in r:
        xScene.remove(s)

    targets = []
    for shot in shots:
        if shot.sceneName == sceneName:
            targets.append(shot)

    for shot in targets:
        xShot = cElementTree.SubElement(
            xScene, 'Shot', {
                'name': shot.name,
                'scene': sceneName,
                'start': str(shot.start),
                'end': str(shot.end),
                'enabled': str(shot.enabled),
                'speed': str(shot.speed),
                'preroll': str(shot.preroll)
            })
        for curveName in shot.curves:
            xChannel = cElementTree.SubElement(xShot, 'Channel', {
                'name': curveName,
                'mode': 'hermite'
            })
            data = []
            for key in shot.curves[curveName]:
                data.append(str(key.inTangent.x))
                data.append(str(key.inTangent.y))
                data.append(str(key.point().x))
                data.append(str(key.point().y))
                data.append(str(key.outTangent.x))
                data.append(str(key.outTangent.y))
                data.append(str(int(key.tangentBroken)))
                data.append(str(key.tangentMode))
            xChannel.text = ','.join(data)
        for texName in shot.textures:
            cElementTree.SubElement(xShot, 'Texture', {
                'name': texName,
                'path': shot.textures[texName]
            })

    with fileutil.edit(sceneFile) as fh:
        fh.write(toPrettyXml(xScene))
Exemple #30
0
    def write(self, graph, fname, eventStream=[]):
        """
			Writes a NetworKit::Graph to the specified file fname.
			Parameters:
				- graph: a NetworKit::Graph python object
				- fname: the desired file path and name to be written to
				- eventStream: stream of events
		"""
        #0. Reset internal vars
        self.__init__()

        #1. Start with the root element and the right header information
        root = ET.Element('gexf')
        root.set("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
        root.set(
            "xsi:schemaLocation",
            "http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd"
        )
        root.set('version', '1.2')

        #2. Create graph element with appropriate information
        graphElement = ET.SubElement(root, "graph")
        if graph.isDirected():
            graphElement.set('defaultedgetype', 'directed')
        else:
            graphElement.set('defaultedgetype', 'undirected')
        if len(eventStream) > 0:
            graphElement.set('mode', 'dynamic')
            graphElement.set('timeformat', 'double')
            for event in eventStream:
                if event.type == GraphEvent.EDGE_WEIGHT_UPDATE:
                    dynamicAtt = ET.SubElement(graphElement, "attributes")
                    dynamicAtt.set('class', 'edge')
                    dynamicAtt.set('mode', 'dynamic')
                    dynamicWeight = ET.SubElement(dynamicAtt, "attribute")
                    dynamicWeight.set('id', 'weight')
                    dynamicWeight.set('title', 'Weight')
                    dynamicWeight.set('type', 'float')
                    self.hasDynamicWeight = True
                    break
        else:
            graphElement.set('mode', 'static')

        #3. Add nodes
        nodesElement = ET.SubElement(graphElement, "nodes")
        nNodes = 0
        #3.1 Count the # of nodes (inital + dynamic nodes)
        for event in eventStream:
            if event.type == GraphEvent.NODE_ADDITION:
                nNodes += 1
        nNodes += len(graph.nodes())
        #3.2 Write nodes to the gexf file
        for n in range(nNodes):
            nodeElement = ET.SubElement(nodesElement, 'node')
            nodeElement.set('id', str(n))
            self.writeEvent(nodeElement, eventStream, n)

        #4. Add edges
        edgesElement = ET.SubElement(graphElement, "edges")
        #4.1 Put all edges into a queue(inital + dynamic edges)
        for e in graph.edges():
            self.q.put((e[0], e[1], graph.weight(e[0], e[1])))
        for event in eventStream:
            if event.type == GraphEvent.EDGE_ADDITION:
                self.q.put((event.u, event.v, event.w))
        #4.2 Write edges to the gexf file
        while not self.q.empty():
            edgeElement = ET.SubElement(edgesElement, 'edge')
            e = self.q.get()
            edgeElement.set('source', str(e[0]))
            edgeElement.set('target', str(e[1]))
            edgeElement.set('id', "{0}".format(self.edgeIdctr))
            self.edgeIdctr += 1
            if graph.isWeighted():
                edgeElement.set('weight', str(e[2]))
            self.writeEvent(edgeElement, eventStream, e)

        #5. Write the generated tree to the file
        tree = ET.ElementTree(root)
        tree.write(fname, "utf-8", True)