def remove(self, removePath=True): from subprocess import call as subcall subcall([os.path.join(self.installpath, "adb.exe"), 'kill-server'], creationflags=0x00000008) rmtree(self.installpath) if removePath: return clearPath(self.installpath, self.installtype == 'system') else: return True
def sysCmd(self, sysCall, stdin=None, stdout=None, cwd=None, shell=False): try: if stdout: return subcall(sysCall, stdin=stdin, stdout=stdout, stderr=stdout, cwd=cwd, shell=shell) else: return subcall(sysCall, stdin=stdin, cwd=cwd, shell=shell) except OSError as ex: errmsg = f'{self.name}.sysCmd failed, args : {str(sysCall)}\nError : {str(ex)}' raise Exception(errmsg)
def downloadMain(self, Cmd, Type): # Start the main download calling youtube-dl Status = subcall(Cmd, shell=True) if Status == 0: Title = ("Download Finished") Message = ("Your " + Type + " has been downloaded successfully.\n" + "The file has been stored in " + getenv("HOME") + "/ .\n" + "Please press on \"Done\" to exit this program.") Image = Gtk.Image.new_from_icon_name("object-select-symbolic", Gtk.IconSize.BUTTON) GydlMessageGui(Title, Message, Image) else: Title = ("Download Unsuccessful") Message = ("Your " + Type + " has not been downloaded.\n" + "Please press on \"Done\" to exit this program.") Image = Gtk.Image.new_from_icon_name("action-unavailable-symbolic", Gtk.IconSize.BUTTON) GydlMessageGui(Title, Message, Image)
def call(cmd): try: response = subcall(cmd,shell=True) print time.sleep(1) if response < 0: sys.exit(response) except OSError, E: sys.exit(E)
def call(cmd, shell=True): try: flag = subcall(cmd, shell=shell) if flag != 0: raise CallException(cmd) return True except CallException, e: print e.value sys.exit(flag)
def call(cmd): if DEBUG: print 'DEBUG: will execute -> %s' % cmd else: try: response = subcall(cmd,shell=True) print time.sleep(1) if response < 0: sys.exit(response) except OSError, E: sys.exit(E)
def call(cmd): print " * ", cmd if debug: return try: response = subcall(cmd,shell=True) print time.sleep(1) if response < 0: sys.exit(response) except OSError, E: sys.exit(E)
def call(cmd): if DEBUG: print 'DEBUG: will execute -> %s' % cmd else: try: response = subcall(cmd, shell=True) print time.sleep(1) if response < 0: sys.exit(response) except OSError, E: sys.exit(E)
def show(): filepath = request.args.get('path') if platform.system() == 'Windows': subcall(['explorer', filepath]) elif platform.system() == 'Linux': subcall(['xdg-open', filepath]) else: subcall(['open', '-R', filepath]) return redirect(request.referrer)
def check_cmd(command_): """ Check whether a command can be run in shell @type command_: str @param command_: the command you want to check, for example, "awk" @rtype: bool @return: whether the command passed the check """ exit_code = subcall(command_, shell=True, stdout=-1, stderr=-1) # Get the exit code without printing standard output print("check command %s" % command_).center(30, "-") if exit_code == 127: # when command not found, exit_code is 127 error("No such command as '%s'" % command_) return False else: return True
def identify_user(): ret = subcall([IDENTIFY_COMMAND,])
PARSER.add_argument('-n', '--name', help="Creates a subdir with this name") ARGS = PARSER.parse_args() if ARGS.name: os.makedirs(ARGS.name) os.chdir(ARGS.name) else: ARGS.name = os.path.basename(str(Path('.').resolve())) TEMPLATE = templates()[ARGS.templatename] with taropen(TEMPLATE, mode='r') as templtar: templtar.extractall() if DIR_TXT.exists(): with open(DIR_TXT) as dtxt: for line in dtxt: os.makedirs(line.rstrip('\n'), exist_ok=True) if FILE_TXT.exists(): with open(FILE_TXT) as ftxt: for line in ftxt: Path(line.rstrip('\n')).touch() if INIT_SH.exists(): subcall([str(INIT_SH.resolve()), ARGS.name]) for fi in [DIR_TXT, FILE_TXT, INIT_SH]: if fi.exists(): fi.unlink()
def sync(source, destination): subcall(['rsync','-WLa', source, destination])
def posix_open(filename): subcall(('xdg-open', filename))
def darwin_open(filename): subcall(('open', filename))