Ejemplo n.º 1
0
 def set_simg(self, target, simg):
     # simg will be empty string if not provided by the user
     if simg:
         try:
             self.replace_by_arg(target,
                                 self.params[target].format(simg))
         except KeyError:
             Display.error(
                 what='Singularity Image for Cluster {0} '.format(
                     self.__class__.__name__),
                 info=' [ Not Supported ]',
                 fill='-')
             self.replace_by_arg(target, '')
     else:
         Display.error(what='Singularity Image for Cluster {0} '.format(
             self.__class__.__name__),
                       info=' [ not provided ]',
                       fill='-')
         self.replace_by_arg(target, '')
Ejemplo n.º 2
0
        def __housekeeping(self):
            Display.title(title='Setting Up Working Directory for {0}'.format(
                self.__class__.__name__))
            try:
                workdir = os.path.abspath(self.args.workdir)
            except Exception:
                raise Exception(
                    'No default or user provided Working directory was provided...'
                )
            else:
                if workdir == settings.HOME_DIRECTORY:
                    Display.warning(
                        what="Using tool's directory as working directory ",
                        info=' [ Warning ]')
                    confirmation = input("Type 'y/Y' to proceed? ")
                    if not confirmation in ['y', 'Y']:
                        Display.error(what='You chose not to proceed ',
                                      info=' [ ABORTING ]')
                        os._exit(-1)

                    if workdir != settings.DEFAULT_WORKDIR:
                        os.chdir(workdir)

                else:
                    if workdir != settings.DEFAULT_WORKDIR:
                        os.chdir(workdir)

            Display.info(what='{0} '.format(workdir),
                         info=' [ Set as Working Dirrectory ]',
                         fill='-')

            #  Creating Directory for the benchmark
            print('\n')
            Display.title(title='Creating Benchmark Directory for {0}'.format(
                self.__class__.__name__))

            self.benchmark_directory = os.path.join(
                os.getcwd(),
                os.path.join(
                    self.args.name,
                    os.path.join(str(date.today()), self.__class__.__name__)))

            if os.path.exists(self.benchmark_directory):
                contents_here = os.listdir(self.benchmark_directory)
                if contents_here:
                    Display.info(what='{0} '.format(self.benchmark_directory),
                                 info=' [ Directory Not Empty ]',
                                 fill='-')
                    confirmation = input(
                        "\nType 'o/O' to override, 'b/b' for backup contents and any other key to quit?\n"
                        .format(self.benchmark_directory))

                    if confirmation in ['o', 'O']:
                        # Remove every thing from the directory
                        Display.warning(what='Overriding {0} '.format(
                            self.benchmark_directory),
                                        info=' [ Warning ]',
                                        fill='-')
                        os.system('rm -rf {0}'.format(
                            os.path.join(self.benchmark_directory, '*')))
                    elif confirmation in ['b', 'B']:
                        Display.title(title='BACKING UP CONTENTS')
                        Display.info(what='{0} with suffix '.format(
                            os.path.join(self.benchmark_directory, '*')),
                                     info=' [ "{0}" ]'.format(
                                         settings.DEFAULT_FILE_BACKUP_SUFFIX),
                                     fill='-')
                        # Storing current working directory to get back
                        cwd = os.getcwd()
                        os.chdir(self.benchmark_directory)
                        for content in sorted(contents_here, reverse=True):
                            os.rename(
                                content,
                                content + settings.DEFAULT_FILE_BACKUP_SUFFIX)

                        # going back to the working directory as it was
                        os.chdir(cwd)
                    else:
                        Display.error(what='You chose not to proceed ',
                                      info=' [ ABORTING ]')
                        sys.exit()
            else:
                os.system('mkdir -p {0}'.format(self.benchmark_directory))