Exemple #1
0
def change_all_res_file(res_file_list):
    """Search in all the resource XML files a resource reference"""
    change_meta(u.load_manifest().getroot())
    for res_file in res_file_list:  # For each XML file
        if u.base_name(res_file) == 'strings.xml':  # Edit only the strings/colors resources
                ori_file_name = res_file
                purge_xml_tag_file(ori_file_name)
                res_file = res_file.replace(u.base_dir(), '')
                res_xml = u.load_xml(res_file)
                res_root = res_xml.getroot()
                change_match_res_string_file(res_root)
                u.save_xml(res_file, res_xml)
        if u.base_name(res_file) == 'arrays.xml' or u.base_name(res_file) == 'plurals.xml':  # Edit only the arrays/plurals resources
                ori_file_name = res_file
                purge_xml_tag_file(ori_file_name)
                res_file = res_file.replace(u.base_dir(), '')
                res_xml = u.load_xml(res_file)
                res_root = res_xml.getroot()
                change_match_res_array_file(res_root)
                u.save_xml(res_file, res_xml)
Exemple #2
0
    def load_query(cls, path: Union[str, None], **kwargs) -> Union[str, None]:
        if path:
            if not os.path.exists(path):
                path = os.path.join(cls.query_basepath, path)

            try:
                return util.load_xml(path).format(**kwargs)
            except KeyError:
                raise
            except FileNotFoundError as fe:
                logger.error(f"Failed to load xml file {path} -- {fe}")
                raise
        else:
            return None
Exemple #3
0
def change_all_res_file(res_file_list):
    """Search in all the resource XML files a resource reference"""
    change_meta(u.load_manifest().getroot())
    for res_file in res_file_list:  # For each XML file
        if u.base_name(
                res_file
        ) == 'strings.xml':  # Edit only the strings/colors resources
            ori_file_name = res_file
            purge_xml_tag_file(ori_file_name)
            res_file = res_file.replace(u.base_dir(), '')
            res_xml = u.load_xml(res_file)
            res_root = res_xml.getroot()
            change_match_res_string_file(res_root)
            u.save_xml(res_file, res_xml)
        if u.base_name(res_file) == 'arrays.xml' or u.base_name(
                res_file
        ) == 'plurals.xml':  # Edit only the arrays/plurals resources
            ori_file_name = res_file
            purge_xml_tag_file(ori_file_name)
            res_file = res_file.replace(u.base_dir(), '')
            res_xml = u.load_xml(res_file)
            res_root = res_xml.getroot()
            change_match_res_array_file(res_root)
            u.save_xml(res_file, res_xml)
Exemple #4
0
	def parse(self,path,file_name):
		
		tree = util.load_xml(path,file_name)
		
		root = tree.getroot()
		
		data = {}
		
		# STORE THE GENERAL INFORMATIONS
		# SUCH AS ID, NAME AND CITATION NAMES
		
		general_info = {}
		try:
			general_info['ID'] = root.get('NUMERO-IDENTIFICADOR').encode('utf-8')
			info = root.find('DADOS-GERAIS')
			general_info['COMPLETE-NAME'] = info.get('NOME-COMPLETO').encode('utf-8')
			name =  info.get('NOME-COMPLETO').replace(" ","")
			general_info['CITATION-NAMES'] = info.get('NOME-EM-CITACOES-BIBLIOGRAFICAS').encode('utf-8')#.split(",")
			
			general_info['PHD-BEGGINING'] = info.find('FORMACAO-ACADEMICA-TITULACAO').find('DOUTORADO').get('ANO-DE-INICIO')
			general_info['PHD-ENDING'] = info.find('FORMACAO-ACADEMICA-TITULACAO').find('DOUTORADO').get('ANO-DE-CONCLUSAO')
			
			data['GENERAL-INFORMATION'] = general_info
		except:
			#fail(str(file))
			return 
		
		articles_data = []
		# CONTINUE
		for child in root:
			
			ok = next((child.tag for x in white_list if x in child.tag),False)
			#print child.tag
			
			# GO FURTHER
			if(ok):
				articles = []
				self.rem(child, 0, articles)
				articles_data = articles_data+articles
				
		data['ARTICLES'] = articles_data
		util.data2json(name,data)
		return name
def tei_to_mp4(input_tei_path, 
        input_smil_path, 
        input_audio_path, 
        config_path,
        output_path):

    # make sure files exist before going through the trouble of rendering
    for path in [input_tei_path, 
                input_smil_path, 
                input_audio_path, 
                config_path ]:
        if not os.path.exists(path):
            logging.error(f"Input {path} does not exist")
            return

    config = load_json(config_path)
    if "bg-image" in config:
        bg_filename = config["bg-image"]
        if not os.path.exists(bg_filename):
            logging.error(f"Background image {bg_filename} does not exist")
            return 

    # determine some basic parameters like duration and fps
    audio_clip = mp.AudioFileClip(input_audio_path)
    total_duration = audio_clip.duration
    fps = config.get("fps", 60)

    # adjust timing of the SMIL to reflect amplitude
    smil = load_xml(input_smil_path)
    smil_dir = os.path.dirname(input_smil_path)
    bounce_begin = config.get("bounce-begin", 0.1)
    bounce_end = config.get("bounce-end", 0.8)
    smil = adjust_timing(smil, smil_dir, bounce_begin, bounce_end)


    clips = []
    current_time = 0
    fade_duration = 0.5

    # parse the TEI and turn it into a slideshow object
    tree = et.parse(input_tei_path)
    config = load_json(config_path)
    slideshow = Slideshow(tree.getroot(), config)
    slideshow.layout()
    slideshow.add_all_timestamps(smil)
    slideshow.pad_slides(total_duration)
    slide_clip_paths = []
    for slide_idx, slide in enumerate(slideshow.children):
        subslideshow = Slideshow(tree.getroot(), config)
        subslideshow.layout()
        subslideshow.add_all_timestamps(smil)
        subslideshow.pad_slides(total_duration)
        svg = subslideshow.asSVG(slide_idx)
        save_xml(f"temp/slide{slide_idx}.svg", svg)
        slide_clip_path = f"temp/slide.{slide_idx}.mp4"
        svg_to_mp4(svg, "", config_path, slide_clip_path, slide.begin_time, slide.end_time, fade_duration)
        slide_clip_paths.append(slide_clip_path)

    for clip_path in slide_clip_paths:
        clip = mp.VideoFileClip(clip_path) #.crossfadeout(fade_duration)
        if current_time != 0:
            current_time -= fade_duration
            clip = clip.set_start(current_time).crossfadein(fade_duration)
        current_time += clip.duration
        clips.append(clip)
    
    video = mp.CompositeVideoClip(clips)
    video.audio = audio_clip
    video.write_videofile(output_path, fps=fps, codec="png") #, threads=4)
Exemple #6
0
def load_encodings(doc):
  result = []
  for enc in doc.query["amqp/section/type/encoding",
                       lambda n: n.parent["@class"] == "primitive"]:
    type_name = pythonize(enc.parent["@name"])
    if enc["@name"]:
      enc_name = "%s_%s" % (type_name, pythonize(enc["@name"]))
    else:
      enc_name = type_name
    code = int(enc["@code"], 0)
    category = pythonize(enc["@category"])
    width = int(enc["@width"], 0)
    result.append(Encoding(enc_name, Primitive(type_name), code, category, width))
  return result

TYPES = load_xml("types.xml")
ENCODINGS = load_encodings(TYPES)

WIDTH_CODES = {
  1: "B",
  2: "H",
  4: "I"
  }

class TypeEncoder:

  def __init__(self, encodings=ENCODINGS):
    self.encodings = {}
    self.encoders = {}
    for enc in encodings:
      if enc.type in self.encodings:
Exemple #7
0
  FIELDS=[Field("payload", Symbol("payload"), Primitive("binary"), False, False,
                "")]

class FieldCompare(Composite):

  def __eq__(self, o):
    if self.__class__ != o.__class__:
      return False

    for f in self.FIELDS:
      if getattr(self, f.name) != getattr(o, f.name):
        return False

    return True

TRANSPORT = load_xml("transport.xml")
MESSAGING = load_xml("messaging.xml")
SECURITY = load_xml("security.xml")
TRANSACTIONS = load_xml("transactions.xml")

TYPES = reduce(lambda x, y: x + y,
               [d.query["amqp/section/type"]
                for d in [TYPES_DOC, TRANSPORT, MESSAGING, SECURITY,
                          TRANSACTIONS]])
CLASSES = load_composite(TYPES, composite=Composite, restricted=Restricted,
                         frame=Body, sasl_frame=Body,
                         delivery_state=FieldCompare)

PROTOCOL_DECODER = TypeDecoder()
PROTOCOL_ENCODER = TypeEncoder()
def main(input_smil_path, output_smil_path):
    smil = load_xml(input_smil_path)
    smil_dir = os.path.dirname(input_smil_path)
    new_smil = adjust_timing(smil, smil_dir, 0.2, 0.6)
    save_xml(output_smil_path, new_smil)
Exemple #9
0
 def __init__(self, xml_file):
     xml = util.load_xml(xml_file)
     self.xml = xml.getroot()
Exemple #10
0
 def __init__(self, xml_file):
     xml = util.load_xml(xml_file)
     self.xml = xml.getroot()