def __init__(self, node, command=None, commands=None, # set to False if not set explicitly here forever = None, # set to True if not set explicitly here critical = None, # an optional list of local files # to install remotely in the dir where the script is run includes = None, *args, **kwds): self.node = node if command is None and commands is None: print("WARNING: SshJobScript requires either command or commands") self.commands = [ "echo", "misformed", "SshJobScript"] elif command and commands: print("WARNING: SshJobScript created with command and commands - keeping the latter") self.commands = commands elif command: self.commands = [ command ] else: # allow to pass empty subcommands so one can use if-expressions there self.commands = [ x for x in commands if x] self.includes = [] if includes is None else includes # set defaults to pass to upper level forever = forever if forever is not None else False critical = critical if critical is not None else True AbstractJob.__init__(self, forever=forever, critical=critical, *args, **kwds)
def __init__(self, node, localpaths, remotepath, # set to False if not set explicitly here forever = None, # set to True if not set explicitly here critical = None, # asyncssh's SFTP client get option preserve = False, recurse = False, follow_symlinks = False, # this goes to AbstractJob *args, **kwds): self.node = node self.localpaths = localpaths self.remotepath = remotepath # set defaults to pass to upper level forever = forever if forever is not None else False critical = critical if critical is not None else True self.preserve = preserve self.recurse = recurse self.follow_symlinks = follow_symlinks AbstractJob.__init__(self, forever=forever, critical=critical, *args, **kwds)
def __init__(self, node, command=None, commands=None, # set to False if not set explicitly here forever = None, # set to True if not set explicitly here critical = None, *args, **kwds): self.node = node if command is None and commands is None: print("WARNING: SshJob requires either command or commands") self.commands = [ "echo", "misformed", "SshJob"] elif command and commands: print("WARNING: SshJob created with command and commands - keeping the latter") self.commands = commands elif command: self.commands = [ command ] else: # allow to pass empty subcommands so one can use if-expressions there self.commands = [ x for x in commands if x] # set defaults to pass to upper level forever = forever if forever is not None else False critical = critical if critical is not None else True AbstractJob.__init__(self, forever=forever, critical=critical, *args, **kwds)
def __init__( self, node, *, # pylint: disable=r0912 command=None, commands=None, keep_connection=False, # if set, propagate to all commands verbose=None, # set to False if not set explicitly here forever=None, # set to True if not set explicitly here critical=None, **kwds): check_arg_type(node, (SshProxy, LocalNode), "SshJob.node") self.node = node self.keep_connection = keep_connection # use command or commands if command is None and commands is None: print("WARNING: SshJob requires either command or commands") commands = [ Run("echo misformed SshJob - no commands nor commands") ] elif command and commands: print("WARNING: SshJob created with command and commands" " - keeping the latter only") commands = commands elif command: commands = command else: pass # find out what really is meant here if not commands: # cannot tell which case in (1) (2) (3) (4) print("WARNING: SshJob requires a meaningful commands") self.commands = [Run("echo misformed SshJob - empty commands")] elif isinstance(commands, (str, Deferred)): # print("case (4)") self.commands = [Run(commands)] elif isinstance(commands, AbstractCommand): # print("case (2)") self.commands = [commands] elif isinstance(commands, (list, tuple)): # allows to insert None as a command commands = [c for c in commands if c] if not commands: commands = [ Run("echo misformed SshJob" " - need at least one non-void command") ] elif isinstance(commands[0], AbstractCommand): # print("case (1)") # check the list is homogeneous if not all(isinstance(c, AbstractCommand) for c in commands): print("WARNING: commands must be" " a list of AbstractCommand objects") self.commands = commands else: # print("case (3)") tokens = commands command_args = (str(t) for t in tokens) self.commands = [Run(*command_args)] else: print("WARNING: SshJob could not make sense of commands") self.commands = [ Run("echo misformed SshJob" " - could not make sense of commands") ] assert len(self.commands) >= 1 assert all(isinstance(c, AbstractCommand) for c in self.commands) # xxx assign a back-reference from commands to node # for the capture mechanism for command in self.commands: command.node = self.node # used in repr_result() to show which command has failed self._errors = [] # propagate the verbose flag on all commands if set if verbose is not None: for propagate in self.commands: propagate.verbose = verbose # set defaults to pass to mother class forever = forever if forever is not None else False critical = critical if critical is not None else True AbstractJob.__init__(self, forever=forever, critical=critical, **kwds)