예제 #1
0
def test_git_cache(cache_dir):
    '''
    Test GitHub cache using a git client
    '''
    mgr = layouts.Layouts(force_refresh=True,
                          force_git=True,
                          cache_dir=cache_dir)
    assert mgr.list_layouts()
예제 #2
0
def layout_mgr():
    '''
    Layout manager setup

    Uses the default cache location, but the retrieval is cached so tests can run faster and not
    have to re-initialize Layouts()
    '''
    return layouts.Layouts()
예제 #3
0
def common_cache_dir():
    '''
    Returns a pre-populated cache directory
    Used to speed-up tests so the cache does not have to be re-downloaded each time
    '''
    # Get unique cache directory
    unique_dir = cache_dir()

    # Force cache to generate
    layouts.Layouts(cache_dir=unique_dir)

    return unique_dir
예제 #4
0
def test_local_cache(cache_dir):
    '''
    Test local cache check

    Downloads .tar.gz from GitHub, extracts and uses
    '''
    # Prepare layout cache
    github_path = 'hid-io/layouts'
    tmp_dir = cache_dir
    version = 'master'

    # Check for environment variable Github token
    token = os.environ.get('GITHUB_APIKEY', None)

    # Retrieve repo information
    gh = Github(token)
    repo = gh.get_repo(github_path)
    commit = repo.get_commit(version)
    tar_url = repo.get_archive_link('tarball')

    # GitHub only uses the first 7 characters of the sha in the download
    dirname = "{}-{}".format(github_path.replace('/', '-'), commit.sha[:7])
    dirpath = os.path.join(tmp_dir, dirname)
    filename = "{}.tar.gz".format(dirname)
    filepath = os.path.join(tmp_dir, filename)

    # If directory doesn't exist, check if tarball does
    if not os.path.isdir(dirpath):
        # If tarball doesn't exist, download it
        if not os.path.isfile(filepath):
            # Retrieve tar file
            chunk_size = 2000
            req = requests.get(tar_url, stream=True)
            with open(filepath, 'wb') as infile:
                for chunk in req.iter_content(chunk_size):
                    infile.write(chunk)

        # Extract tarfile
        tar = tarfile.open(filepath)
        tar.extractall(tmp_dir)

    # Run actual test
    mgr = layouts.Layouts(layout_path=dirpath)
    assert mgr.list_layouts()
예제 #5
0
파일: __init__.py 프로젝트: leetmeister/kll
def command_line_args(control, input_args):
    '''
    Initialize argparse and process all command line arguments

    @param control: ControlStage object which has access to all the group argument parsers
    '''
    # Setup argument processor
    parser = argparse.ArgumentParser(
        usage="{} [options..] [<generic>..]".format(kll_name),
        description="KLL Compiler - Generates specified output from KLL .kll files.",
        epilog="Example: {0} scan_map.kll".format(kll_name),
        formatter_class=argparse.RawTextHelpFormatter,
        add_help=False,
    )

    # Install path
    install_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))

    # Get git information
    control.git_rev, control.git_changes, control.git_date, long_version = git_revision(
        os.path.join(install_path, '..')
    )
    control.version = "{0}{1}".format(__version__, long_version)

    # Optional Arguments
    parser.add_argument(
        '-h', '--help',
        action="help",
        help="This message."
    )
    parser.add_argument(
        '-v', '--version',
        action="version",
        version="{0} {1}".format(kll_name, control.version),
        help="Show program's version number and exit"
    )
    parser.add_argument(
        '--path',
        action="store_true",
        help="Shows the absolute path to the kll compiler installation directory. Then exits.",
    )
    parser.add_argument(
        '--layout-cache-path',
        action="store_true",
        help="Shows the absolute path to the kll layouts cache director. Then exits.",
    )
    parser.add_argument(
        '--layout-cache-refresh',
        action="store_true",
        help="Does a refresh on the kll layouts cache. Then exits. Don't do this too often or you'll get GitHub RateLimit Errors.",
    )

    # Add stage arguments
    control.command_line_flags(parser)

    # Process Arguments
    args = parser.parse_args(input_args)

    # If --path defined, lookup installation path, then exit
    if args.path:
        print(install_path)
        sys.exit(0)

    # If --layout-cache-path defined, lookup cache directory for layouts cache, then exit
    if args.layout_cache_path:
        import layouts
        mgr = layouts.Layouts()
        layout_path = mgr.layout_path
        print(layout_path)
        sys.exit(0)

    # If --layout-cache-refresh defined, show the refreshed layout path
    if args.layout_cache_refresh:
        import layouts
        mgr = layouts.Layouts(force_refresh=True)
        layout_path = mgr.layout_path
        print(layout_path)
        sys.exit(0)

    # Utilize parsed arguments in each of the stages
    control.command_line_args(args)
예제 #6
0
def test_github_cache(cache_dir):
    '''
    Test GitHub cache
    '''
    mgr = layouts.Layouts(force_refresh=True, cache_dir=cache_dir)
    assert mgr.list_layouts()
예제 #7
0
#!/usr/bin/env python3
'''
Basic tests for layouts repo

Used to validate whether the JSON files can be read and processed.
'''

## Imports

import os

import layouts

## Test

# Determine this scripts directory
script_dir = os.path.dirname(os.path.realpath(__file__))

# Load layouts of this repository
mgr = layouts.Layouts(layout_path=os.path.join(script_dir, ".."))

# Print out a list of layouts
# Doing this requires loading all of the JSON files, and reading the name field
for layout, path in sorted(mgr.layout_names.items()):
    print(layout, path)