def reproman_exec(self, command, args): """Run a reproman utility "exec" command in the environment Parameters ---------- command : string The session method name to run. (e.g. mkdir, chown, etc.) args : list of strings Arguments passed in from the command line for the command Raises ------ CommandError Exception if an invalid command argument is passed in. """ if command not in self.INTERNAL_COMMANDS: raise CommandError(cmd=command, msg="Invalid command") pargs = [] # positional args to pass to session command kwargs = {} # key word args to pass to session command for arg in args: if '=' in arg: parts = arg.split('=') if len(parts) != 2: raise CommandError(cmd=command, msg="Invalid command line parameter") kwargs[parts[0]] = parts[1] else: pargs.append(arg) getattr(self, command)(*pargs, **kwargs)
def mkdir(self, path, parents=False): """Create a directory """ command = ["mkdir"] if parents: command.append("-p") command += [path] self.execute_command(command) if not self.isdir(path): raise CommandError(cmd='mkdir', msg="Failed to create directory")
def mkdir(self, path, parents=False): if not os.path.exists(path): if parents: os.makedirs(path) else: try: os.mkdir(path) except OSError: raise CommandError( msg="Failed to make directory {}".format(path))
def chown(self, path, uid=-1, gid=-1, recursive=False, remote=True): """Set the user and gid of a path """ uid = int(uid) # Command line parameters getting passed as type str gid = int(gid) if uid == -1 and gid > -1: command = ['chgrp'] else: command = ['chown'] if recursive: command += ["-R"] if uid > -1 and gid > -1: command += ["{}.{}".format(uid, gid)] elif uid > -1: command += [uid] elif gid > -1: command += [gid] else: raise CommandError(cmd='chown', msg="Invalid command \ parameters.") command += [path] if remote: self.execute_command(command) else: # Run on the local file system Runner().run(command)