Ejemplo n.º 1
0
def _context_only(options, project_dir, control_file, control_config,
                  hot_files):
    try:
        (hot_files,
         control_config) = control.parse_control(project_dir, control_file,
                                                 control_config, hot_files)
        control_config.context_only = options.context_only
        (hot_files,
         control_config) = control.prepare_control(hot_files, control_config)

        msg_filename = context.buildmessagefile(control_config)
        message_file = open(msg_filename, 'r')

        try:
            for line in message_file:
                print(line.strip())
        finally:
            message_file.close()
            os.remove(msg_filename)
        return 0
    except (flashbake.git.VCError, flashbake.ConfigError) as error:
        logging.error('Error: {}'.format(str(error)))
        return 1
    except PluginError as error:
        _handle_bad_plugin(error)
        return 1
Ejemplo n.º 2
0
def __load_user_control(home_dir, project_dir, options):
    control_file = join(home_dir, '.flashbake', 'config')
    if os.path.exists(control_file):
        (hot_files, control_config) = control.parse_control(project_dir, control_file)
        control_config.context_only = options.context_only
    else:
        hot_files = None
        control_config = None
    return hot_files, control_config
Ejemplo n.º 3
0
def _load_user_control(home_dir, project_dir, options):
    control_file = join(home_dir, '.flashbake', 'config')
    if os.path.exists(control_file):
        (hot_files, control_config) = control.parse_control(project_dir, control_file)
        control_config.context_only = options.context_only
    else:
        hot_files = None
        control_config = None
    return hot_files, control_config
Ejemplo n.º 4
0
def __context_only(options, project_dir, control_file, control_config, hot_files):
    try:
        (hot_files, control_config) = control.parse_control(project_dir, control_file, control_config, hot_files)
        control_config.context_only = options.context_only
        (hot_files, control_config) = control.prepare_control(hot_files, control_config)

        msg_filename = context.buildmessagefile(control_config)
        message_file = open(msg_filename, 'r')

        try:
            for line in message_file:
                print line.strip()
        finally:
            message_file.close()
            os.remove(msg_filename)
        return 0
    except (flashbake.git.VCError, flashbake.ConfigError), error:
        logging.error('Error: %s' % str(error))
        return 1
Ejemplo n.º 5
0
def main():
    ''' Entry point used by the setup.py installation script. '''
    # handle options and arguments
    parser = _build_main_parser()
    global special_message
    special_message = ""

    (options, args) = parser.parse_args()

    if options.quiet and options.verbose:
        parser.error('Cannot specify both verbose and quiet')

    # configure logging
    level = logging.INFO
    if options.verbose:
        level = logging.DEBUG

    if options.quiet:
        level = logging.ERROR

    logging.basicConfig(level=level, format='%(message)s')

    home_dir = os.path.expanduser('~')

    # look for plugin directory
    _load_plugin_dirs(options, home_dir)

    if len(args) < 1:
        parser.error('Must specify project directory.')
        sys.exit(1)

    project_dir = args[0]

    # look for user's default control file
    hot_files, control_config = _load_user_control(home_dir, project_dir,
                                                   options)

    # look for project control file
    control_file = _find_control(parser, project_dir)
    if None == control_file:
        sys.exit(1)

    # emit the context message and exit
    if options.context_only:
        sys.exit(
            _context_only(options, project_dir, control_file, control_config,
                          hot_files))

    quiet_period = 0
    if len(args) == 2:
        if args[1].isdigit():
            try:
                quiet_period = int(args[1])
            except:
                parser.error(
                    f'Quiet minutes, "{args[1]}", must be a valid number.')
                sys.exit(1)
        else:
            try:
                special_message = str(args[1])
            except:
                parser.error(f'Messages, "{args[1]}", must be a string.')
                sys.exit(1)
    try:
        (hot_files,
         control_config) = control.parse_control(project_dir, control_file,
                                                 control_config, hot_files)
        control_config.context_only = options.context_only
        control_config.dry_run = options.dryrun
        if (options.dryrun):
            logging.info('========================================')
            logging.info('!!! Running in dry run mode.         !!!')
            logging.info('!!! No changes will be committed.    !!!')
            logging.info('========================================\n\n')
        (hot_files,
         control_config) = control.prepare_control(hot_files, control_config)
        if options.purge:
            commit.purge(control_config, hot_files)
        else:
            commit.commit(control_config, hot_files, quiet_period)
        if (options.dryrun):
            logging.info('\n\n========================================')
            logging.info('!!! Running in dry run mode.         !!!')
            logging.info('!!! No changes will be committed.    !!!')
            logging.info('========================================')
    except (flashbake.git.VCError, flashbake.ConfigError) as error:
        logging.error(f'Error: {str(error)}')
        sys.exit(1)
    except PluginError as error:
        _handle_bad_plugin(error)
        sys.exit(1)
Ejemplo n.º 6
0
def main():
    # handle options and arguments
    parser = __build_parser()

    (options, args) = parser.parse_args()

    if options.quiet and options.verbose:
        parser.error('Cannot specify both verbose and quiet')

    # configure logging
    level = logging.INFO
    if options.verbose:
        level = logging.DEBUG

    if options.quiet:
        level = logging.ERROR

    logging.basicConfig(level=level,
            format='%(message)s')

    home_dir = os.path.expanduser('~')

    # look for plugin directory
    __load_plugin_dirs(options, home_dir)

    if len(args) < 1:
        parser.error('Must specify project directory.')
        sys.exit(1)

    project_dir = args[0]

    # look for user's default control file
    hot_files, control_config = __load_user_control(home_dir, project_dir,options)

    # look for project control file
    control_file = __find_control(parser, project_dir)
    if None == control_file:
        sys.exit(1)

    # emit the context message and exit
    if options.context_only:
        sys.exit(__context_only(options, project_dir, control_file, control_config, hot_files))

    quiet_period = 0
    if len(args) == 2:
        try:
            quiet_period = int(args[1])
        except:
            parser.error('Quiet minutes, "%s", must be a valid number.' % args[1])
            sys.exit(1)

    try:
        (hot_files, control_config) = control.parse_control(project_dir, control_file, control_config, hot_files)
        control_config.context_only = options.context_only
        (hot_files, control_config) = control.prepare_control(hot_files, control_config)
        if options.purge:
            commit.purge(control_config, hot_files, options.dryrun)
        else:
            commit.commit(control_config, hot_files, quiet_period, options.dryrun)
    except (flashbake.git.VCError, flashbake.ConfigError), error:
        logging.error('Error: %s' % str(error))
        sys.exit(1)