Ejemplo n.º 1
0
def compare_current_oval_to_remote(remote='origin', branch='master'):
    """ Returns a list of OVAL files in current working directory that differ from a remote/branch. """
    repo = get_repo()

    # get a reference the the remote repo
    all_remotes = { available_remote.name for available_remote in repo.remotes }
    if remote not in all_remotes:
        raise RemoteDoesNotExistError(remote)
    remote_repo = repo.remotes[remote].repo

    # get the branch of the remote repo
    all_branches = { available_branch.name for available_branch in remote_repo.heads }
    if branch not in all_branches:
        raise RemoteBranchDoesNotExistError(remote, branch)
    remote_branch = remote_repo.heads[branch]

    # get the head commit of the remote branch
    remote_headcommit = remote_branch.commit
    
    content_rel_path = lib_repo.get_repository_root_path().replace(lib_repo.get_root_path(),'')[1:]
    files = set()

    for diff in remote_headcommit.diff(None, paths=content_rel_path):
      files.add(diff.a_path)

    # check for untracked files 
    for path in repo.untracked_files:
      if path.startswith(content_rel_path):
        files.add(path)

    # get full paths AND remove non-xml files, i.e. readme.md 
    files = { os.path.join(lib_repo.get_root_path(), path) for path in files if path.endswith('.xml') }
    # print('Files list:\n\t{0}'.format('\n\t'.join(files)))

    return files
Ejemplo n.º 2
0
def get_uncommitted_oval():
    """ Returns list of OVAL files in the repository that are not committed. """
    repo = get_repo()

    uncommitted_oval = set()
    content_rel_path = lib_repo.get_repository_root_path().replace(
        lib_repo.get_root_path(), '')[1:]

    # check for changes in content staged for commit
    for diff in repo.index.diff(repo.head.commit, paths=content_rel_path):
        uncommitted_oval.add(diff.a_path)
        # print('staged: {0}'.format(diff.a_path))

    # check for changes in content not staged for commit
    for diff in repo.index.diff(None, paths=content_rel_path):
        uncommitted_oval.add(diff.a_path)
        # print('not staged: {0}'.format(diff.a_path))

    # check for untracked files
    for path in repo.untracked_files:
        if path.startswith(content_rel_path):
            uncommitted_oval.add(path)

    # get full paths AND remove non-xml files, i.e. readme.md
    uncommitted_oval = {
        os.path.join(lib_repo.get_root_path(), path)
        for path in uncommitted_oval if path.endswith('.xml')
    }
    #print('Uncommitted files list:\n\t{0}'.format('\n\t'.join(uncommitted_oval)))

    return uncommitted_oval
Ejemplo n.º 3
0
def get_uncommitted_oval():
    """ Returns list of OVAL files in the repository that are not committed. """
    repo = get_repo()

    uncommitted_oval = set()
    content_rel_path = lib_repo.get_repository_root_path().replace(lib_repo.get_root_path(),'')[1:]

    # check for changes in content staged for commit
    for diff in repo.index.diff(repo.head.commit, paths=content_rel_path):
      uncommitted_oval.add(diff.a_path)
      # print('staged: {0}'.format(diff.a_path))

    # check for changes in content not staged for commit
    for diff in repo.index.diff(None, paths=content_rel_path):
      uncommitted_oval.add(diff.a_path)
      # print('not staged: {0}'.format(diff.a_path))

    # check for untracked files 
    for path in repo.untracked_files:
      if path.startswith(content_rel_path):
        uncommitted_oval.add(path)

    # get full paths AND remove non-xml files, i.e. readme.md 
    uncommitted_oval = { os.path.join(lib_repo.get_root_path(), path) for path in uncommitted_oval if path.endswith('.xml') }
    #print('Uncommitted files list:\n\t{0}'.format('\n\t'.join(uncommitted_oval)))
      
    return uncommitted_oval
Ejemplo n.º 4
0
def main():
    """ parse command line options and generate file """

    # parse command line options
    parser = argparse.ArgumentParser(
        description='Searches the index for duplicate oval ids')

    # get index
    elements_index = lib_search.ElementsIndex(message)

    all_oval_ids = dict()
    duplicate_oval_ids = dict()
    for document in elements_index.query():
        oval_id = document['oval_id']
        root_path = document['path'].replace(lib_repo.get_root_path(), '')

        if oval_id in all_oval_ids:
            if oval_id not in duplicate_oval_ids:
                duplicate_oval_ids[oval_id] = set()
                duplicate_oval_ids[oval_id].add(all_oval_ids[oval_id])
            duplicate_oval_ids[oval_id].add(root_path)

        all_oval_ids[oval_id] = root_path

    print('Found {0} duplicate OVAL IDs'.format(len(duplicate_oval_ids)))
    pprint.pprint(duplicate_oval_ids)
Ejemplo n.º 5
0
def main():
    """ parse command line options and generate file """

    # parse command line options
    parser = argparse.ArgumentParser(description='Searches the index for duplicate oval ids')

    # get index
    elements_index = lib_search.ElementsIndex(message)


    all_oval_ids = dict()
    duplicate_oval_ids = dict()
    for document in elements_index.query():
        oval_id = document['oval_id']
        root_path = document['path'].replace(lib_repo.get_root_path(), '')
        
        if oval_id in all_oval_ids:
            if oval_id not in duplicate_oval_ids:
                duplicate_oval_ids[oval_id] = set()
                duplicate_oval_ids[oval_id].add(all_oval_ids[oval_id])
            duplicate_oval_ids[oval_id].add(root_path)

        all_oval_ids[oval_id] = root_path

    print('Found {0} duplicate OVAL IDs'.format(len(duplicate_oval_ids)))
    pprint.pprint(duplicate_oval_ids)
Ejemplo n.º 6
0
def compare_current_oval_to_remote(remote='origin', branch='master'):
    """ Returns a list of OVAL files in current working directory that differ from a remote/branch. """
    repo = get_repo()

    # get a reference the the remote repo
    all_remotes = {available_remote.name for available_remote in repo.remotes}
    if remote not in all_remotes:
        raise RemoteDoesNotExistError(remote)
    remote_repo = repo.remotes[remote].repo

    # get the branch of the remote repo
    all_branches = {
        available_branch.name
        for available_branch in remote_repo.heads
    }
    if branch not in all_branches:
        raise RemoteBranchDoesNotExistError(remote, branch)
    remote_branch = remote_repo.heads[branch]

    # get the head commit of the remote branch
    remote_headcommit = remote_branch.commit

    content_rel_path = lib_repo.get_repository_root_path().replace(
        lib_repo.get_root_path(), '')[1:]
    files = set()

    for diff in remote_headcommit.diff(None, paths=content_rel_path):
        files.add(diff.a_path)

    # check for untracked files
    for path in repo.untracked_files:
        if path.startswith(content_rel_path):
            files.add(path)

    # get full paths AND remove non-xml files, i.e. readme.md
    files = {
        os.path.join(lib_repo.get_root_path(), path)
        for path in files if path.endswith('.xml')
    }
    # print('Files list:\n\t{0}'.format('\n\t'.join(files)))

    return files
Ejemplo n.º 7
0
def get_repo():
    return git.Repo(lib_repo.get_root_path())
Ejemplo n.º 8
0
def child(schema_version):

   schema_path="{0}/oval_schemas/{1}/all-oval-definitions.xsd".format(lib_repo.get_root_path(), schema_version)
   lib_xml.get_schematron_xsl_from_schema(schema_path)
   os._exit(0)
Ejemplo n.º 9
0
def get_repo():
    return git.Repo(lib_repo.get_root_path())
Ejemplo n.º 10
0
def child(schema_version):

    schema_path = "{0}/oval_schemas/{1}/all-oval-definitions.xsd".format(
        lib_repo.get_root_path(), schema_version)
    lib_xml.get_schematron_xsl_from_schema(schema_path)
    os._exit(0)