def importFile(self, eetFile, decompArg="-d"): """This method decompiles a binary EET file using the eet system command""" self.eetFilePath = eetFile self.cfgName = eetFile.split("/")[-1] self.tmpFile = eetFile.split("/")[-1] nextInt = 0 #ensure we aren't overwriting other CFGs that are open for writing while os.path.isfile("%s/%s%s.txt" % (TMPDIR, self.tmpFile, nextInt)): nextInt += 1 self.tmpFile = "%s%s.txt" % (self.tmpFile, nextInt) #print eetFile #print "%s/%s"%(TMPDIR, self.tmpFile) cmd = ecore.Exe("eet %s %s config %s/%s" % (decompArg, eetFile, TMPDIR, self.tmpFile)) #Wait while the file is extracted while not os.path.isfile("%s/%s" % (TMPDIR, self.tmpFile)): time.sleep(0.5) extractFile = "%s/%s" % (TMPDIR, self.tmpFile) #Prints the output of the file if we want to see that for debugging #print "%s/%s"%(TMPDIR, self.tmpFile) #for l in tmpFile.readlines(): # print l if decompArg == "-d": self.readExtract(extractFile) else: with open(extractFile) as f: self.ecfgParse = f.read()
def run_command(self, command, password): self.cmd_exe = cmd = ecore.Exe( command, ecore.ECORE_EXE_PIPE_READ | ecore.ECORE_EXE_PIPE_ERROR | ecore.ECORE_EXE_PIPE_WRITE) cmd.on_add_event_add(self.command_started) cmd.on_data_event_add(self.received_data) cmd.on_error_event_add(self.received_error, password) cmd.on_del_event_add(self.command_done)
def list_content(self, archive_file, done_cb): self._contents = list() cmd = '%s "%s"' % (LIST_MAP.get(self.mime_type), archive_file) exe = ecore.Exe( cmd, ecore.ECORE_EXE_PIPE_READ | ecore.ECORE_EXE_PIPE_READ_LINE_BUFFERED) exe.on_data_event_add(self._list_stdout) exe.on_del_event_add(self._list_done, done_cb)
def extract(self, archive_file, destination, progress_cb, done_cb): os.chdir(destination) cmd = 'pv -n "%s" | %s ' % (archive_file, EXTRACT_MAP.get(self.mime_type)) exe = ecore.Exe( cmd, ecore.ECORE_EXE_PIPE_ERROR | ecore.ECORE_EXE_PIPE_ERROR_LINE_BUFFERED) exe.on_error_event_add(self._extract_stderr, progress_cb) exe.on_del_event_add(self._extract_done, done_cb)
def runCommand(self, command, done_cb=None): self.cmd_exe = cmd = ecore.Exe( command, ecore.ECORE_EXE_PIPE_READ | ecore.ECORE_EXE_PIPE_ERROR | ecore.ECORE_EXE_PIPE_WRITE) cmd.on_add_event_add(self.command_started) cmd.on_data_event_add(self.received_data) cmd.on_error_event_add(self.received_error) cmd.on_del_event_add(self.command_done) self.done_cb = done_cb
def item_activated_cb(self, gl, item): file_entry, progress, n, h = item.data if progress != file_entry.size: return path = os.path.join(h.save_path(), file_entry.path) if sys.platform == 'linux2': ecore.Exe("xdg-open '{0}'".format(path)) else: os.startfile(path)
def run_cmd(self, command, done_cb=None): '''Run command capture ouput''' command = markup_to_utf8(command) # pylint: disable=c-extension-no-member self.cmd_exe = cmd = ecore.Exe( command, ecore.ECORE_EXE_PIPE_READ | ecore.ECORE_EXE_PIPE_ERROR | ecore.ECORE_EXE_PIPE_WRITE) cmd.on_add_event_add(self.cb_started) cmd.on_data_event_add(self.cb_data) cmd.on_error_event_add(self.cb_error) cmd.on_del_event_add(self.cb_done) self.done_cb = done_cb
def fileSelected(self, fs, ourPath): self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS) #move the file to temp dir / rename it so we can work around a issue with spaces in file names tmpCount = 1 while os.path.isfile("/tmp/swamiwall_%s" % tmpCount): tmpCount += 1 shutil.copy2(ourPath, '/tmp/swamiwall_%s' % tmpCount) time.sleep(1) ourFile = os.path.splitext(os.path.basename(ourPath))[0].replace( " ", "") ecore.Exe('convertimage.sh %s %s' % ('/tmp/swamiwall_%s' % tmpCount, ourFile)) time.sleep(1) self.addWall("%s.edj" % ourFile, "%s/.e/e/backgrounds/" % UserHome)
def saveData(self, saveAs=False): """Writes the data back into an eet file""" if saveAs: saveLocation = saveAs self.eetFilePath = saveAs else: saveLocation = self.eetFilePath # save the new config with open("%s/%s" % (TMPDIR, self.tmpFile), 'w') as f: if isinstance(self.ecfgParse, basestring): f.write(self.ecfgParse) compArg = "-i" else: f.write(self.ecfgParse.text()) compArg = "-e" #if save location exists create a backup before writing over it if os.path.isfile(saveLocation): if os.path.isfile("%s.old" % saveLocation): os.remove("%s.old" % saveLocation) while os.path.isfile("%s.old" % saveLocation): time.sleep(0.5) os.rename(saveLocation, "%s.old" % saveLocation) while os.path.isfile(saveLocation): time.sleep(0.5) #print "writing %s from %s/%s"%(saveLocation, TMPDIR, self.tmpFile) cmd = ecore.Exe("eet %s %s config %s/%s 1" % (compArg, saveLocation, TMPDIR, self.tmpFile)) while not os.path.isfile(saveLocation): time.sleep(0.5) os.remove("%s/%s" % (TMPDIR, self.tmpFile))
def testInit(self): # basic read flags with line support flags = ecore.ECORE_EXE_PIPE_READ | ecore.ECORE_EXE_PIPE_READ_LINE_BUFFERED # simple ls -la output, monitor for add, del and data (stdout) def on_add(x, event, a, b, c): print("ecore.Exe added:") print(" exe : %s" % x) print(" event: %s" % event) print(" extra: arguments: a=%s, b=%s, c=%s" % (a, b, c)) print("") self.assertEqual(x, exe) self.assertIsInstance(event, ecore.EventExeAdd) self.assertEqual(a, 1) self.assertEqual(b, 2) self.assertEqual(c, 3) def on_del(x, event): print("ecore.Exe deleted:") print(" exe : %s" % x) ecore.timer_add(1.0, ecore.main_loop_quit) def on_data(x, event): self.assertEqual(x, exe) self.assertIsInstance(event, ecore.EventExeData) print("ecore.Exe data on stdout:") print(" Exe : %s" % repr(exe)) print(" Event : %s" % repr(event)) for l in event.lines: print(" %s" % repr(l)) print exe = ecore.Exe("ls -la", flags) exe.on_add_event_add(on_add, 1, c=3, b=2) exe.on_del_event_add(on_del) exe.on_data_event_add(on_data) # use C-api like event handler, will catch all 3 Exe() instances def catch_all_exe_add(event): print("") print(">>> EXE ADDED: %s" % event) print("") return 1 ecore.on_exe_add_event_add(catch_all_exe_add) ecore.Exe("ls -l /", flags) # start cat, send data to it, then read, then send again, then kill it def on_cat_pipe_add(x, event): x.send(b"123\nabc\nxyz\n") def on_cat_pipe_data(x, event): self.assertEqual(event.lines, ["123", "abc", "xyz"]) x.on_data_event_del(on_cat_pipe_data) def on_cat_pipe_data2(x, event): print("cat pipe output:") print("\n".join(event.lines)) print("") x.send("some\nmore\nlines!\n") if event.lines and event.lines[-1] == "lines!": x.on_data_event_del(on_cat_pipe_data2) x.kill( ) # otherwise it will stay there forever (will be detached) cat_pipe = ecore.Exe("cat", flags | ecore.ECORE_EXE_PIPE_WRITE) cat_pipe.on_add_event_add(on_cat_pipe_add) cat_pipe.on_data_event_add(on_cat_pipe_data) cat_pipe.on_data_event_add(on_cat_pipe_data2) ecore.main_loop_begin()
def applyPressed(self, btn): #Accessing global data #print edje.file_data_get(themeFile, "gtk-theme") #The current selected theme path - self.selectedTheme #Dbus call to stop Moksha from fighting with our changes bus = dbus.SessionBus() obj = bus.get_object('org.enlightenment.wm.service', '/org/enlightenment/wm/RemoteObject') iface = dbus.Interface(obj, dbus_interface='org.enlightenment.wm.Config') iface.SaveBlock() #Update Moksha Theme #Get existing profile eProfileFile = neet.EETFile() eProfileFile.importFile("%s/.e/e/config/profile.cfg" % UserHome, "-x") eProfile = eProfileFile.readValue() #change to a tmp profile so we aren't writing to the one in memory #ecore.Exe("cp -a %s/.e/e/config/%s %s/.e/e/config/__tmpprofile"%(UserHome, eProfile, UserHome)) #time.sleep(1) #ecore.Exe("enlightenment_remote -default-profile-set __tmpprofile") eCFG = neet.EETFile() eCFG.importFile("%s/.e/e/config/%s/e.cfg" % (UserHome, eProfile)) ethemeData = eCFG.readValue( (("list", "themes"), ("item", "E_Config_Theme", "category", "theme"), ("value", "file"))) ethemeData.data = self.selectedTheme #print ethemeData.data eCFG.saveData() #Update elm theme order #elmProfile = "standard" #same as eProfile - shouldn't just assume elmProfileFile = neet.EETFile() elmProfileFile.importFile( "%s/.elementary/config/profile.cfg" % UserHome, "-x") elmProfile = elmProfileFile.readValue() elmCFG = neet.EETFile() elmCFG.importFile("%s/.elementary/config/%s/base.cfg" % (UserHome, elmProfile)) themeData = elmCFG.readValue((("value", "theme"), )) themeName = edje.file_data_get(self.selectedTheme, "elm-theme") themeData.data = "%s:MokshaRadiance:default" % themeName elmCFG.saveData() #Swap back to our updated profile #ecore.Exe("enlightenment_remote -default-profile-set %s"%eProfile) #Remove the __tmpprofile #shutil.rmtree("%s/.e/e/config/__tmpprofile"%(UserHome)) #Give Moksha control of the config data again iface.Load() iface.SaveRelease() #Restart to apply the new theme ecore.Exe("enlightenment_remote -restart") #Flush Elm settings elementary.Configuration.all_flush