def setFile(self, fileName): """The method setFile removes the old file and puts the new file in place with the preferred name of a file. :param fileName: The name of the new file :type fileName: Str. -- path to the new file """ self.fileName = self.getPreferredFileName() Program.Program().execute("mv " + fileName + " " + self.fileName, "mv", self)
def from_xml_(self, xml_string): recording = parseString(xml_string.encode(XMLDOC_CODEPAGE)) try: self.id_ = str(recording.getElementsByTagName(RECORDING_ID_NODE)[0].firstChild.data) self.schedule_id_ = str(recording.getElementsByTagName(RECORDING_SCHEDULE_ID_NODE)[0].firstChild.data) self.channel_id_ = str(recording.getElementsByTagName(RECORDING_CHANNEL_ID_NODE)[0].firstChild.data) except: return False try: self.is_active_ = string_to_bool(recording.getElementsByTagName(RECORDING_IS_ACTIVE_NODE)[0].firstChild.data) except: self.is_active_ = False try: self.is_conflicting_ = string_to_bool(recording.getElementsByTagName(RECORDING_IS_CONFLICT_NODE)[0].firstChild.data) except: self.is_conflicting_ = False try: self.program_ = Program(recording.toxml()) except: self.program_ = None return True
def from_xml_(self, xml_string): schedule = parseString(xml_string.encode(XMLDOC_CODEPAGE)) try: self.channel_id_ = str( schedule.getElementsByTagName(SCHEDULE_CHANNEL_ID_NODE) [0].firstChild.data) self.program_id_ = str( schedule.getElementsByTagName(SCHEDULE_PROGRAM_ID_NODE) [0].firstChild.data) self.program_ = Program( schedule.getElementsByTagName(EPG_PROGRAM)[0].toxml()) except: return False try: self.is_repeat_ = string_to_bool( schedule.getElementsByTagName(SCHEDULE_REPEATE_NODE) [0].firstChild.data) except: self.is_repeat_ = False try: self.is_new_only_ = string_to_bool( schedule.getElementsByTagName(SCHEDULE_NEW_ONLY_NODE) [0].firstChild.data) except: self.is_new_only_ = False try: self.is_record_series_anytime_ = string_to_bool( schedule.getElementsByTagName(SCHEDULE_SERIES_ANYTIME_NODE) [0].firstChild.data) except: self.is_record_series_anytime_ = False try: self.recordings_to_keep_ = int( schedule.getElementsByTagName(SCHEDULE_REC_TO_KEEP_NODE) [0].firstChild.data) except: self.recordings_to_keep_ = 0
""" Testing """ from programs import ComputerController, Computer, Program if __name__ == "__main__": computer = Computer() computer.add_program(ComputerController(keyword='computer.umdl')) #computer.add_program(Program(keyword='computer_music.pmdl',callback=lambda x: print("MUSIC"))) # computer.add_program(Program(keyword='computer_email.pmdl',callback=lambda x: print("EMAIL"))) # computer.add_program(Program(keyword='youtube.pmdl',callback=lambda x: print("YT"))) computer.add_program( Program('hey_fucker.pmdl', lambda x: print("Eres un deus"))) computer.start_programs()
# TODO(izzy): I misunderstood the rule when I glanced at the problem. # We don't have th primitives for this one yet 'b548a754.json': (ColorGridWithMask, PassGrid, (MaskFromColor, PassGrid, Color_p(8)), Color_p(0)), # this one is a good exapmle of the value of for-loops, variables, and also # of recognizing the boarders of the grid. Notice all the repeated structure. 'bc1d5164.json': (MaskedOverlay, (MaskedOverlay, (MaskedOverlay, (ExtractPatch, PassGrid, Int_p(0), Int_p(0), Int_p(3), Int_p(3)), (ExtractPatch, PassGrid, Int_p(0), Int_p(2), Int_p(3), Int_p(3)), (InvertMask, (MaskFromColor, (ExtractPatch, PassGrid, Int_p(0), Int_p(2), Int_p(3), Int_p(3)), Color_p(0)))), (ExtractPatch, PassGrid, Int_p(4), Int_p(0), Int_p(3), Int_p(3)), (InvertMask, (MaskFromColor, (ExtractPatch, PassGrid, Int_p(4), Int_p(0), Int_p(3), Int_p(3)), Color_p(0)))), (ExtractPatch, PassGrid, Int_p(4), Int_p(2), Int_p(3), Int_p(3)), (InvertMask, (MaskFromColor, (ExtractPatch, PassGrid, Int_p(4), Int_p(2), Int_p(3), Int_p(3)), Color_p(0)))) } if __name__ == '__main__': for task_name in demo_programs: spec = demo_programs[task_name] P = Program(spec) if not P.type_check(): print(f'The program for {task_name} failed type_check') print(f'{task_name}:\t{run_program_on_task_train(P, task_name)}')