Example #1
0
def createDirectories(baseDir, directories, server=None):
    """
    This function create the directories listed in the directories array.
    @param baseDir: the parent directory.
    @param directories: the list of directory to create.
    @param server: the server on which the directory will be created.
    """
    for (directory) in directories:
        dir = os.path.join(baseDir, directory)
        if server is not None:
            command = 'ssh %s "ls -d1 %s"' % (server, dir)
            stream, process = utils_commands.get_output_stream_from_command(
                command, logger_name=None)
            line = None
            for line in stream:
                line = line.strip()
                if line == dir:
                    break
            if line != dir:
                logging.info('%s does not exists on %s: create it' %
                             (dir, server))
                command = 'ssh %s "mkdir %s"' % (server, dir)
                utils_commands.launchCommandLocally(command)
        elif not os.path.exists(dir):
            logging.info('%s does not exists: create it' % dir)
            os.mkdir(dir, 0775)
Example #2
0
def createDirectories(baseDir,directories, server=None):
    """
    This function create the directories listed in the directories array.
    @param baseDir: the parent directory.
    @param directories: the list of directory to create.
    @param server: the server on which the directory will be created.
    """
    for (directory) in directories:
        dir=os.path.join(baseDir,directory)
        if server is not None:
            command = 'ssh %s "ls -d1 %s"'%(server, dir)
            stream, process = utils_commands.get_output_stream_from_command(command, logger_name=None)
            line=None
            for line in stream:
                line=line.strip()
                if line == dir:
                    break
            if line != dir:
                logging.info('%s does not exists on %s: create it'%(dir, server))
                command = 'ssh %s "mkdir %s"'%(server, dir)
                utils_commands.launchCommandLocally(command)
        elif not os.path.exists(dir):
            logging.info('%s does not exists: create it'%dir)
            os.mkdir(dir,0775)
Example #3
0
 def run_command(self,command, **kwargs):
     """Run the command and return the code that this command returned"""
     if command.__class__==''.__class__:
         pass
     elif command.__class__==[].__class__:
         pass
     return_code=0
     if self.type_r==TYPE_PRINT:
         print command
     elif self.type_r==TYPE_RUN_LOCAL:
         logging.info(command)
         return_code=utils_commands.launchCommandLocally(command, nice=False, **kwargs)
     else:
         logging.error('The type %s is not handle by the Command_runner class'%self.type_r)
         return_code=1
     return return_code