def import_files(self, event): dialog = wx.DirDialog(self, 'Select directory', style=wx.DD_DIR_MUST_EXIST) if dialog.ShowModal() == wx.ID_OK: path = dialog.GetPath() dialog = wx.TextEntryDialog(self, 'Enter name for imported mod', 'Import mod', '') if dialog.ShowModal() == wx.ID_OK: name = dialog.GetValue() fname = encode_filename(name) dialog1 = ProgressDialog(self, 'Importing mod') dialog2 = ProgressDialog(self, 'Saving .dfmod') def process(): try: mod_dataset = decode_directory(path, callback=dialog1) mod = Mod(name, os.path.join('mods', fname), self.core_dataset, self.core_dataset.difference(mod_dataset)) encode_mod(mod, callback=dialog2) except: self.show_current_exception() dialog1.Close() dialog2.Close() self.reload_mods() thread_wrapper(process)()
def reload_mods(self, initial=False, progress=True): ''' This method clears the currently loaded mod list and reloads every mod in the mods directory. Should be used as rarely as possible due to long execution time''' dialog = ProgressDialog(self, 'Loading mods', show=progress) self.mods = [] notified = False mod_headers = {} # First, let's read the headers of all the mods for mod in get_mod_list(): path = os.path.join('mods', mod) mod_headers[path] = decode_mod_headers(path) dialog.set_task_number(len(mod_headers)) # Now, let's verify the checksums of all the mods and update if needed core_checksum = str(self.core_dataset.checksum()) for mod, headers in mod_headers.items(): if 'meta' in headers: continue # Verify only core files for now if headers['checksum'] != core_checksum: if not notified: notified = True print 'Updating mods...' self.info_dialog( 'DFMM has detected a change in your core files. The patches defined in your mods will be re-rolled. Depending on the number and size of your mods, this may take several minutes. Watch the console window for possible notifications about changes that cannot be applied to the new files.', 'Core files changed') print 'Processing mod "%s"...' % mod mod = decode_mod(mod, self.core_dataset) encode_mod(mod, overwrite=True) if notified: print 'Done updating mods.' # First, process the normal mods. This makes them available for the # metamods to reference for path, headers in mod_headers.items(): if 'meta' not in headers: dialog.task_started(label=headers['name']) self.load_normal_mod(path) # Then, the metamods for path, headers in mod_headers.items(): if 'meta' in headers: dialog.task_started(label=headers['name']) self.load_metamod(path, headers) dialog.done() self.update_mod_list() self.update_title()
def resort_all(self, event): dialog = ProgressDialog(self, 'Resorting objects') dialog.set_task_number(len(self.panels)) for panel in self.panels: dialog.task_started(panel.type) panel.resort_objects() dialog.done()
def install(self, event): print 'Installing mods' print '-' * 20 dataset = self.merge_selected_mods( callback=ProgressDialog(self, 'Merging mods')) path = os.path.join('..', 'raw', 'objects') current_files = os.listdir(path) for f in current_files: if os.path.isfile(os.path.join(path, f)): os.remove(os.path.join(path, f)) encode_objects(dataset.objects, path, callback=ProgressDialog(self, 'Installing data')) self.last_checksum = self.mods_checksum() print 'Install complete'
def reload_mods(self, initial=False, progress=True): ''' This method clears the currently loaded mod list and reloads every mod in the mods directory. Should be used as rarely as possible due to long execution time''' dialog = ProgressDialog(self, 'Loading mods', show=progress) self.mods = [] notified = False mod_headers = {} # First, let's read the headers of all the mods for mod in get_mod_list(): path = os.path.join('mods', mod) mod_headers[path] = decode_mod_headers(path) dialog.set_task_number(len(mod_headers)) # Now, let's verify the checksums of all the mods and update if needed core_checksum = str(self.core_dataset.checksum()) for mod, headers in mod_headers.items(): if 'meta' in headers: continue # Verify only core files for now if headers['checksum'] != core_checksum: if not notified: notified = True print 'Updating mods...' self.info_dialog('DFMM has detected a change in your core files. The patches defined in your mods will be re-rolled. Depending on the number and size of your mods, this may take several minutes. Watch the console window for possible notifications about changes that cannot be applied to the new files.', 'Core files changed') print 'Processing mod "%s"...' % mod mod = decode_mod(mod, self.core_dataset) encode_mod(mod, overwrite=True) if notified: print 'Done updating mods.' # First, process the normal mods. This makes them available for the # metamods to reference for path, headers in mod_headers.items(): if 'meta' not in headers: dialog.task_started(label=headers['name']) self.load_normal_mod(path) # Then, the metamods for path, headers in mod_headers.items(): if 'meta' in headers: dialog.task_started(label=headers['name']) self.load_metamod(path, headers) dialog.done() self.update_mod_list() self.update_title()
def __init__(self): self.wTree = gtk.glade.XML('interface2.glade','mainUI') self.window = self.wTree.get_widget('mainUI') self.__dialog = ProgressDialog() self.__dialog.button.connect("clicked",self.cancel_connection,self.__dialog) self.operators = range(3) self.avalaible_devices = range(2) self.mon = monitor() self.device_active = None self.build_list_operators() self.build_combo_operators() self.window.connect("destroy", self.quit_cb) self.wTree.get_widget("connect").connect("pressed",self.connect) self.wTree.get_widget("menu_item_about").connect("activate",self.show_about) self.__build_avalaible_devices() self.__hardware_detection() self.window.show_all()
def save(self, event, exit=False): if self.mod: self.mod.objects = self.objects dialog = ProgressDialog(self, 'Saving mod') # All this must be in the other thread so it doesn't get out of order def process(): if self.mod: # Working from a .dfmod file encode_mod(self.mod, overwrite=True, callback=dialog) else: # Working in standalone mode if os.path.isdir(self.path): encode_objects(self.objects, self.path, callback=dialog) else: dir, fname = os.path.split(self.path) encode_objects(self.objects, dir, callback=dialog) self.unsaved_changes = False if self.parent: self.parent.reload_mods(progress=False) if exit: self.Close(True) thread_wrapper(process)()
class MainInterface: def __init__(self): self.wTree = gtk.glade.XML('interface2.glade','mainUI') self.window = self.wTree.get_widget('mainUI') self.__dialog = ProgressDialog() self.__dialog.button.connect("clicked",self.cancel_connection,self.__dialog) self.operators = range(3) self.avalaible_devices = range(2) self.mon = monitor() self.device_active = None self.build_list_operators() self.build_combo_operators() self.window.connect("destroy", self.quit_cb) self.wTree.get_widget("connect").connect("pressed",self.connect) self.wTree.get_widget("menu_item_about").connect("activate",self.show_about) self.__build_avalaible_devices() self.__hardware_detection() self.window.show_all() def build_list_operators(self): file = open("operators","r") i=0 for line in file: line = line.strip() if(line=="<operator>"): self.operators[i]=operator() for line in file: line = line.strip() if(line=="</operator>"): break else: split=line.split("=") self.operators[i].add(split[0],split[1]) i=i+1 file.close() def connect(self,widget, data = None): if (self.mon.status() == PPP_STATUS_DISCONNECTED): combo = self.wTree.get_widget('combobox') active = combo.get_active() self.window.set_sensitive(False) self.__dialog.show() self.mon.start(self.operators[active],self.device_active.get_attrib("nodo")) gobject.timeout_add_seconds(1,self.checking_connection) else: widget.set_label("Conectar") self.mon.stop() def checking_connection(self): if(self.mon.status() == PPP_STATUS_CONNECTING): self.__dialog.label.set_markup(self.mon.get_state()) return True elif (self.mon.status() == PPP_STATUS_CONNECTED): self.__dialog.hide() self.wTree.get_widget("connect").set_label("Desconectar") self.wTree.get_widget("connect").set_active(True) self.window.set_sensitive(True) return False else: self.__dialog.should_change = False self.__dialog.image.set_from_file('network-error.png') self.__dialog.label.set_markup("Error") return False def cancel_connection(self,widget,dialog,data = None): if(self.mon.status() == PPP_STATUS_CONNECTING): self.mon.stop() dialog.hide() self.window.set_sensitive(True) def show_about(self,widget): self.about = gtk.glade.XML('interface2.glade','about-dialog') self.about.get_widget('about-dialog').show_all() def build_combo_operators(self): box_operators=self.wTree.get_widget('combobox') liststore = gtk.ListStore(gtk.gdk.Pixbuf,str) px = gtk.CellRendererPixbuf() cell = gtk.CellRendererText() box_operators.pack_start(px) box_operators.pack_start(cell) box_operators.add_attribute(px, 'pixbuf', 0) box_operators.add_attribute(cell, 'text', 1) for i in self.operators: iter = liststore.append() liststore.set_value(iter, 1, i.get_attrib('name')) logo_path =i.get_attrib('logo')+ '.png' if os.path.exists(logo_path): liststore.set_value(iter, 0, gtk.gdk.pixbuf_new_from_file(logo_path)) box_operators.set_model(liststore) box_operators.set_active(-1) def __hardware_detection(self): cmd = "lsusb" pm = Popen(cmd, shell=True, stdout=PIPE, close_fds=True) for line in pm.stdout: line = line.split(" ")[5] vendor, product = line.split(":") if(vendor!="1d6b"): for iter in self.avalaible_devices: if(vendor == iter.get_attrib("idVendor") and product == iter.get_attrib("idProduct")): self.device_active=iter break if(self.device_active!=None): break def __build_avalaible_devices(self): file = open("modems.xml","r") i=0 for line in file: line = line.strip() line = line.split(" ") if(len(line) > 1): if(line[0]=="<product"): sp = line[1].split("=") vendor, product = sp[1].split(":") self.avalaible_devices[i] = modem(vendor,product) iter = 2 while(iter<len(line)-1): split = line[iter].split("=") self.avalaible_devices[i].add(split[0],split[1]) iter = iter + 1 i = i+1 def quit_cb(self,widget, data=None): gtk.main_quit()
def parse_ftrace(filename, callback): fid = ftrace_open(filename) progress = ProgressDialog(title="ftrace", message="loading %s..." % (os.path.basename(filename)), max=100, show_time=True, can_cancel=True) progress.open() try: fid.seek(0, 2) except ValueError: # gzip do not support seek end # do we uncompress everything. :-/ # parsing is already far slower than uncompressing. while fid.read(1024): pass totsize = fid.tell() fid.seek(0, 0) last_percent = 0 # the base regular expressions event_re = re.compile( r'\s*(.+)-([0-9]+)\s+\[([0-9]+)\][^:]*\s+([0-9.]+): ([^:]*): (.*)') function_re = re.compile( r'\s*(.+)-([0-9]+)\s+\[([0-9]+)\][^:]*\s+([0-9.]+): (.*) <-(.*)') last_timestamp = 0 linenumber = 0 for line in fid: ### print("DEBUG LINE: ",linenumber, line) percent = int(fid.tell() * 100. / totsize) if percent != last_percent: last_percent = percent (cont, skip) = progress.update(percent) if not cont or skip: break linenumber += 1 line = line.rstrip() res = event_re.match(line.decode('utf-8')) if res: groups = res.groups() event_name = groups[4] event = { 'linenumber': linenumber, 'common_comm': groups[0], 'common_pid': int(groups[1]), 'common_cpu': int(groups[2]), 'timestamp': int(float(groups[3]) * 1000000), 'event': event_name, 'event_arg': groups[5] } last_timestamp = event['timestamp'] to_match = event['event_arg'] try: for name, regex, func in events_re[event_name]: res = regex.search(to_match) if res: func(event, res.groups()) except KeyError: pass callback(Event(event)) continue res = event_re.match(line.decode('utf-8')) if res: event = { 'linenumber': linenumber, 'common_comm': res.group(1), 'common_pid': int(res.group(2)), 'common_cpu': int(res.group(3)), 'timestamp': int(float(res.group(4)) * 1000000), 'event': 'function', 'callee': res.group(5), 'caller': res.group(6) } callback(Event(event)) continue fid.close()
def finish_parsing(self): #put generated data in unresizable numpy format c_states = [] i=0 for tc in self.tmp_c_states: t = tcIdleState(name='cpu%d'%(i)) while len(tc['start_ts'])>len(tc['end_ts']): tc['end_ts'].append(tc['start_ts'][-1]) t.start_ts = numpy.array(tc['start_ts']) t.end_ts = numpy.array(tc['end_ts']) t.types = numpy.array(tc['types']) c_states.append(t) i+=1 self.c_states=c_states i=0 p_states = [] for tc in self.tmp_p_states: t = tcFrequencyState(name='cpu%d'%(i)) t.start_ts = numpy.array(tc['start_ts']) t.end_ts = numpy.array(tc['end_ts']) t.types = numpy.array(tc['types']) i+=1 p_states.append(t) self.wake_events = numpy.array(self.wake_events,dtype=[('waker',tuple),('wakee',tuple),('time','uint64')]) self.p_states=p_states processes = [] last_ts = 0 for pid,comm in self.tmp_process: tc = self.tmp_process[pid,comm] if len(tc['end_ts'])>0 and last_ts < tc['end_ts'][-1]: last_ts = tc['end_ts'][-1] if len(self.tmp_process) >0: progress = ProgressDialog(title="precomputing data", message="precomputing overview data...", max=len(self.tmp_process), show_time=False, can_cancel=False) progress.open() i = 0 for pid,comm in self.tmp_process: tc = self.tmp_process[pid,comm] if tc['type'] in self.process_types: klass, order = self.process_types[tc['type']] t = klass(pid=pid,comm=tc['comm'],project=self) else: t = tcProcess(pid=pid,comm=comm,project=self) while len(tc['start_ts'])>len(tc['end_ts']): tc['end_ts'].append(last_ts) t.start_ts = numpy.array(tc['start_ts']) t.end_ts = numpy.array(tc['end_ts']) t.types = numpy.array(tc['types']) t.cpus = numpy.array(tc['cpus']) t.comments = tc['comments'] #numpy.array(tc['comments']) t.process_type = tc["type"] # precompute 16 levels of overview cache t.get_overview_ts(1<<16) processes.append(t) progress.update(i) i += 1 if len(self.tmp_process) > 0: progress.close() self.tmp_process = [] def cmp_process(x,y): # sort process by type, pid, comm def type_index(t): try: return self.process_types[t][1] except ValueError: return len(order)+1 c = cmp(type_index(x.process_type),type_index(y.process_type)) if c != 0: return c c = cmp(x.pid,y.pid) if c != 0: return c c = cmp(x.comm,y.comm) return c ### ??? processes.sort(cmp_process) self.processes = processes self.p_states=p_states self.tmp_c_states = [] self.tmp_p_states = [] self.tmp_process = {}