Example #1
0
def check_roles_dir(install_path):
    if not os.path.exists(common.roles_path):
        output.warning(
            "Roles directory %s does not exist. It is possible that osxstrap init was never run."
            % common.roles_path)
        if click.confirm('Do you want to run it now?'):
            galaxy_install(install_path)
Example #2
0
 def looper(input):
     val = validator(input)
     if val!=True:
         output.warning(str(val))
         return True
     else:
         return False
Example #3
0
def input(prompt=None, *, default=None, validator=None):
    if prompt is not None:
        prompt_default = " [{}]".format(default) if default is not None else ""
        prompt = "{}{}: ".format(prompt, prompt_default)

    if validator is None:
        validator = lambda x: x

    while True:
        if prompt is not None:
            output.info(prompt, newline=False)

        try:
            inp = _input().strip()
        except EOFError:
            if prompt:
                output.newline()
            fail()

        if not inp:
            if default is not None:
                return default
            else:
                output.warning("Must enter a value")
                continue

        try:
            inp = validator(inp)
        except ValueError as e:
            output.warning("Invalid input ({})".format(e))
        else:
            return inp
Example #4
0
    def buildChord(self):
        f = open('./patterns/chords.json')
        chords = json.loads(f.read())
        f.close()

        try:
            chords[self.name]
        except KeyError, e:
            output.warning('Can\'t find a chord named ' + self.name + ', will use maj7 instead')
            self.name = 'maj7'
Example #5
0
def p_define(p):
    ''' define : DEFINE ID params defs
    '''
    if ENABLED:
        if p[4]:
            if SPACES.match(p[4][0]):
                p[4][0] = p[4][0][1:]
            else:
                warning(p.lineno(1), "missing whitespace after the macro name")

        ID_TABLE.define(p[2], args = p[3], value = p[4], lineno = p.lineno(2), fname = CURRENT_FILE[-1])

    p[0] = []
Example #6
0
def include_once(filename, lineno):
    ''' Do as above only in file not already included
    '''
    if filename not in INCLUDED.keys(): # If not already included 
        return include_file(filename, lineno) # include it and return

    # Now checks if the file has been included more than once
    if len(INCLUDED[filename]) > 1:
        warning(lineno, "file '%s' already included more than once, in file '%s' at line %i" % 
            (filename, INCLUDED[filename][0][0], INCLUDED[filename][0][1]))

    # Empty file (already included)
    LEXER.next_token = '_ENDFILE_'
    return ''
Example #7
0
    def define(self, _id, lineno, value = '', fname = None, args = None):
        ''' Defines the value of a macro.
        Issues a warning if the macro is already defined.
        '''
        if fname is None:
            if CURRENT_FILE:
                fname = CURRENT_FILE[-1]
            else: # If no files opened yet, use owns program fname
                fname = sys.argv[0]

        if self.defined(_id):
            i = self.table[_id]            
            warning(lineno, '"%s" redefined (previous definition at %s:%i)' % (i.name, i.fname, i.lineno))

        self.set(_id, lineno, value, fname, args)
Example #8
0
    def define(self, _id, lineno, value='', fname=None, args=None):
        ''' Defines the value of a macro.
        Issues a warning if the macro is already defined.
        '''
        if fname is None:
            if CURRENT_FILE:
                fname = CURRENT_FILE[-1]
            else:  # If no files opened yet, use owns program fname
                fname = sys.argv[0]

        if self.defined(_id):
            i = self.table[_id]
            warning(
                lineno, '"%s" redefined (previous definition at %s:%i)' %
                (i.name, i.fname, i.lineno))

        self.set(_id, lineno, value, fname, args)
Example #9
0
def copy_config(source_path):
    if not os.path.isabs(source_path):
        source_path = os.path.join(os.getcwd(), source_path)
    destination_path = os.path.join(config_path, config_filename)
    if source_path and source_path != destination_path:
        if os.path.exists(source_path):
            if not os.path.exists(destination_path):
                common.mkdir(config_path)
                copyfile(source_path, destination_path)
            else:
                output.warning("Destination file %s already exists." % destination_path)
                if click.confirm('Do you want to overwrite it?'):
                    os.remove(destination_path)
                    copyfile(source_path, destination_path)
                else:
                    output.abort("To run osxstrap without copying config, use the osxstrap command.")
        else:
            output.abort("Input file %s does not exist." % source_path)
Example #10
0
def copy_config(source_path):
    if not os.path.isabs(source_path):
        source_path = os.path.join(os.getcwd(), source_path)
    destination_path = os.path.join(config_path, config_filename)
    if source_path and source_path != destination_path:
        if os.path.exists(source_path):
            if not os.path.exists(destination_path):
                common.mkdir(config_path)
                copyfile(source_path, destination_path)
            else:
                output.warning("Destination file %s already exists." %
                               destination_path)
                if click.confirm('Do you want to overwrite it?'):
                    os.remove(destination_path)
                    copyfile(source_path, destination_path)
                else:
                    output.abort(
                        "To run osxstrap without copying config, use the osxstrap command."
                    )
        else:
            output.abort("Input file %s does not exist." % source_path)
Example #11
0
    def __init__(self, name = 'C', accidental = False):
        self.name = name
        self.accidental = accidental

        if accidental != '#' and accidental != 'b' and accidental != 'x' and accidental != 'bb' and accidental != False:
            print 'error: ' + str(accidental) + ' is not a valid accidental'
            self.accidental = False

        self.note_values = {
            'C': 0.5,
            'D': 1.0,
            'E': 1.0,
            'F': 0.5,
            'G': 1.0,
            'A': 1.0,
            'B': 1.0
        }
        self.note_order = ['C', 'D', 'E', 'F', 'G', 'A', 'B']

        try:
            self.note_values[self.name]
        except KeyError, e:
            output.warning(self.name + ' is not a valid note, will use C instead')
            self.name = 'C'
Example #12
0
def _zip_file_integrity_check(file_path):
    """
    Determines whether the zip file contents are structured correctly to be uploaded.
    That includes the zip being properly zipped and the correct files being placed
    :param file_path:
    :return:
    """
    try:
        zip = zipfile.ZipFile(file_path)
    except zipfile.BadZipFile:
        raise TypeError("The file provided is not a proper zip file")
    except FileNotFoundError:
        raise FileNotFoundError("Could not find the zip file provided")
    if not any((item.startswith(_BOT_FILE_NAME_PREPEND)
                or item.lower() in _LANGUGAGE_PROJECT_FILE_IDENTIFIERS)
               for item in zip.namelist()):
        raise ValueError(
            "MyBot.* file must be present in the zip's top directory (or cargo.toml in case of Rust)."
        )
    if not any(item.lower().startswith(_HALITE_LIBRARY_FOLDER)
               for item in zip.namelist()):
        output.warning(
            "WARNING: Could not find an hlt/ library folder. Proceeding with upload. {}"
            .format(os.linesep))
Example #13
0
    try:
        analysis_type = click.prompt('\nWhat would you like to analyse? (' +
                                     ', '.join(analysis_options.keys()) + ')',
                                     default='everything')
    except click.Abort:
        output.error('\n\nAborted, closing program...')
        exit()

    if analysis_type == 'nothing':
        break
    else:
        analysis_function = analysis_options.get(analysis_type, None)

        if analysis_function is None:
            output.warning(
                '\nYour selected analysis "' + analysis_type +
                '" was not understood. If you want to exit, type "nothing".')
        else:
            if STATIC_ANALYSIS:
                output.important('\n-- STATIC ANALYIS --')
                analysis_function()

            if TEMPORAL_ANALYSIS:
                output.important('\n-- TEMPORAL ANALYIS --')

                time_start = filter.time_min(graph)
                time_end = filter.time_max(graph)
                time_diff = time_end - time_start

                output.normal('First edge time: ' + str(time_start))
                output.normal('Last edge time: ' + str(time_end))
Example #14
0
 def warning(self, msg):
     ''' Emmits a warning and continue execution.
     '''
     warning(self.lex.lineno, msg)
Example #15
0
def check_roles_dir(install_path):
	if not os.path.exists(common.roles_path):
		output.warning("Roles directory %s does not exist. It is possible that osxstrap init was never run." % common.roles_path)
		if click.confirm('Do you want to run it now?'):
			galaxy_install(install_path)
Example #16
0
 def warning(self, msg):
     ''' Emmits a warning and continue execution.
     '''
     warning(self.lex.lineno, msg)
Example #17
0
 def log_warning(self, stage, row_number, col_number, message):
     output.warning(stage, message)
     output.raw_info("\n".join(self.get_traceback(row_number, col_number)))