Пример #1
0
 def testnoauthorfail(self):
     """Ensure that accessing feeds with no entry.author doesn't cause failures if the
     feed_author config property isn't set."""
     self.config.plugin_names = ['flashbake.plugins.feed:Feed']
     self.config.extra_props['feed_url'] = "http://twitter.com/statuses/user_timeline/704593.rss"
     from flashbake.context import buildmessagefile
     buildmessagefile(self.config)
Пример #2
0
 def testnoauthorfail(self):
     """Ensure that accessing feeds with no entry.author doesn't cause failures if the
     feed_author config property isn't set."""
     self.config.plugin_names = ['flashbake.plugins.feed:Feed']
     self.config.extra_props[
         'feed_url'] = "http://twitter.com/statuses/user_timeline/704593.rss"
     from flashbake.context import buildmessagefile
     buildmessagefile(self.config)
Пример #3
0
 def testnoaddcontext(self):
     try:
         self.config.plugin_names = ['test.plugins:NoAddContext']
         from flashbake.context import buildmessagefile
         buildmessagefile(self.config)
         self.fail('Should raise a NotImplementedError.')
     except NotImplementedError:
         pass
Пример #4
0
 def testnoaddcontext(self):
     try:
         self.config.plugin_names = ['test.plugins:NoAddContext']
         from flashbake.context import buildmessagefile
         buildmessagefile(self.config)
         self.fail('Should raise a NotImplementedError.')
     except NotImplementedError:
         pass
Пример #5
0
def purge(control_config, hot_files):
    # change to the project directory, necessary to find the .flashbake file and
    # to correctly refer to the project files by relative paths
    os.chdir(hot_files.project_dir)

    git_obj = git.Git(hot_files.project_dir, control_config.git_path)

    # the wrapper object ensures git is on the path
    git_status = git_obj.status().decode('utf-8')

    _handle_fatal(hot_files, git_status)

    logging.debug("Examining git status.")
    for line in git_status.splitlines():
        _capture_deleted(hot_files, line)

    if len(hot_files.deleted) > 0:
        logging.info(
            f'Committing removal of known files, {hot_files.deleted}.')
        message_file = context.buildmessagefile(control_config)
        if not control_config.dry_run:
            # consolidate the commit to be friendly to how git normally works
            commit_output = git_obj.commit(message_file, hot_files.deleted)
            logging.debug(commit_output)
        os.remove(message_file)
        logging.info('Commit for deleted files complete.')
    else:
        logging.info('No deleted files to purge')
Пример #6
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
Пример #7
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
Пример #8
0
def commit(control_config, hot_files, quiet_mins):
    # change to the project directory, necessary to find the .flashbake file and
    # to correctly refer to the project files by relative paths
    os.chdir(hot_files.project_dir)

    git_obj = git.Git(hot_files.project_dir, control_config.git_path)

    # the wrapper object ensures git is on the path
    # get the git status for the project
    git_status = git_obj.status().decode('utf-8')

    _handle_fatal(hot_files, git_status)

    # in particular find the existing entries that need a commit
    # this command is used in `to_commit` on files returned from
    # `def status` in git.py.
    pending_re = re.compile("\s*(renamed|copied|modified|new file):.*")

    now = datetime.datetime.today()
    quiet_period = datetime.timedelta(minutes=quiet_mins)

    to_commit = list()
    # first look in the files git already knows about
    logging.debug("Examining git status.")
    for line in git_status.splitlines():
        if pending_re.match(line):
            pending_file = _trimgit(line)

            # not in the dot-control file, skip it
            if not (hot_files.contains(pending_file)):
                continue

            logging.debug(
                f'Parsing status line {line} to determine commit action')

            # remove files that will be considered for commit
            hot_files.remove(pending_file)

            # check the quiet period against mtime
            last_mod = os.path.getmtime(pending_file)
            pending_mod = datetime.datetime.fromtimestamp(last_mod)
            pending_mod += quiet_period

            # add the file to the list to include in the commit
            if pending_mod < now:
                to_commit.append(pending_file)
                logging.debug(f'Flagging file, {pending_file}, for commit.')
            else:
                logging.debug(
                    f'Change for file, {pending_file}, is too recent.')
        _capture_deleted(hot_files, line)

    logging.debug('Examining unknown or unchanged files.')

    hot_files.warnproblems()

    # figure out what the status of the remaining files is
    for control_file in hot_files.control_files:
        # this shouldn't happen since HotFiles.addfile uses glob.iglob to expand
        # the original file lines which does so based on what is in project_dir
        if not os.path.exists(control_file):
            logging.debug(f'{control_file} does not exist yet.')
            hot_files.putabsent(control_file)
            continue

        status_output = git_obj.status(control_file).decode('utf-8')

        # needed for git >= 1.7.0.4
        if status_output.find('Untracked files') > 0:
            if not control_config.dry_run or control_config.context_only:
                hot_files.putneedsadd(control_file)
                continue
        if status_output.startswith('error'):
            # needed for git < 1.7.0.4
            if status_output.find('did not match') > 0:
                hot_files.putneedsadd(control_file)
                logging.debug(f'{control_file} exists but is unknown by git.')
            else:
                logging.error('Unknown error occurred!')
                logging.error(status_output)
            continue
        # use a regex to match so we can enforce whole word rather than
        # substring matchs, otherwise 'foo.txt~' causes a false report of an
        # error
        control_re = re.compile('\<' + re.escape(control_file) + '\>')
        if control_re.search(status_output) == None:
            logging.debug(f'{control_file} has no uncommitted changes.')
        # if anything hits this block, we need to figure out why
        else:
            logging.error(
                f'{control_file} is in the status message but failed other tests.'
            )
            logging.error(
                f'Try \'git status "{control_file}"\' for more info.')

    hot_files.addorphans(git_obj, control_config)

    for plugin in control_config.file_plugins:
        plugin.post_process(to_commit, hot_files, control_config)

    if len(to_commit) > 0:
        logging.info(f'Committing changes to known files, {to_commit}.')
        message_file = context.buildmessagefile(control_config)
        if not control_config.dry_run:
            # consolidate the commit to be friendly to how git normally works
            commit_output = git_obj.commit(message_file, to_commit)
            logging.debug(commit_output)
        os.remove(message_file)
        _send_commit_notice(control_config, hot_files, to_commit)
        logging.info('Commit for known files complete.')
    else:
        logging.info('No changes to known files found to commit.')

    if hot_files.needs_warning():
        _send_warning(control_config, hot_files)
    else:
        logging.info(
            'No missing or untracked files found, not sending warning notice.')