コード例 #1
0
ファイル: app_utils.py プロジェクト: punisherVX/panhandler
def _get_current_build_time() -> (datetime, None):
    build_date_string = cnc_utils.get_long_term_cached_value(
        'panhandler', 'current_build_time')

    if not build_date_string:
        print('Getting updated build_date_string')
        panhandler_config = cnc_utils.get_app_config('panhandler')
        if 'app_dir' not in panhandler_config:
            return None

        build_file = os.path.join(panhandler_config['app_dir'], 'build_date')

        if not os.path.exists(build_file) or not os.path.isfile(build_file):
            return None

        try:
            with open(build_file, 'r') as bf:
                build_date_string = str(bf.readline()).strip()
                cnc_utils.set_long_term_cached_value('panhandler',
                                                     'current_build_time',
                                                     build_date_string, 14400,
                                                     'app_update')
        except OSError as ose:
            print('Could not read build date data file')
            print(ose)
            return None

    print(build_date_string)
    return datetime.strptime(build_date_string, '%Y-%m-%dT%H:%M:%S')
コード例 #2
0
ファイル: app_utils.py プロジェクト: punisherVX/panhandler
def _get_current_tag() -> (str, None):
    tag_string = cnc_utils.get_long_term_cached_value('panhandler',
                                                      'current_tag')

    if not tag_string:
        print('Getting updated tag')
        panhandler_config = cnc_utils.get_app_config('panhandler')
        if 'app_dir' not in panhandler_config:
            return None

        tag_file = os.path.join(panhandler_config['app_dir'], 'tag')

        if not os.path.exists(tag_file) or not os.path.isfile(tag_file):
            return None

        try:
            with open(tag_file, 'r') as bf:
                tag_string = bf.read()
                cnc_utils.set_long_term_cached_value('panhandler',
                                                     'current_tag', tag_string,
                                                     14400, 'app_update')

        except OSError as ose:
            print('Could not read tag date data file')
            print(ose)
            return None

    return str(tag_string.strip())
コード例 #3
0
ファイル: db_utils.py プロジェクト: andrewmallory/pan-cnc
def initialize_default_repositories(app_name) -> None:
    """
    Find any configured repositories in the application configuration
    and build db records for their respective skillets.

    Called from the WelcomeView to ensure all default skillets are found and indexed

    :return: None
    """
    app_config = cnc_utils.get_app_config(app_name)
    if 'repositories' not in app_config:
        return

    for r in app_config['repositories']:
        repo_details = dict()
        repo_details.update(r)

        initialize_repo(repo_details)
コード例 #4
0
ファイル: app_utils.py プロジェクト: punisherVX/panhandler
def get_recommended_links() -> list:
    app_name = 'panhandler'
    app_config = cnc_utils.get_app_config('panhandler')
    recommended_links = list()

    # do not make external calls if we are testing
    if cnc_utils.is_testing():
        print('Returning blank recommended links due to testing env')
        return recommended_links

    if 'application_data' not in app_config:
        print('Could not find application_data in .pan-cnc.yaml')
        return recommended_links

    if type(app_config['application_data']) is not dict:
        print('malformed application_data in .pan-cnc.yaml')
        return recommended_links

    if 'recommended_repos_link' not in app_config['application_data']:
        print(
            'Could not find value recommended_repos_link key in application_data'
        )
        return recommended_links

    recommend_url = app_config['application_data']['recommended_repos_link']

    if not str(recommend_url).startswith('http'):
        print('recommended_repos_link does not appear to be a valid link')
        return recommended_links

    try:
        # try to pull from cache is possible
        recommends_from_cache = cnc_utils.get_long_term_cached_value(
            app_name, 'recommended_links')
        if recommends_from_cache is not None:
            print('Returning recommended_links from the cache')
            return recommends_from_cache

        resp = requests.get(recommend_url, verify=False, timeout=5)
        if resp.status_code != 200:
            print('Could not fetch recommended_repos_link')
            print(resp.text)
            print(resp.status_code)
            return recommended_links

        data_object = oyaml.safe_load(resp.text)
        if _validate_recommended_data(data_object):
            # save for later
            cnc_utils.set_long_term_cached_value(app_name, 'recommended_links',
                                                 data_object['links'], 7200,
                                                 'recommended_links')
            return data_object['links']
        else:
            # FIXME - return a default list here
            return recommended_links
    except ValueError as ve:
        print('Could not load response')
        print(ve)
        return recommended_links

    except ConnectionError as ce:
        print('Could not fetch recommended links url')
        print(ce)
        return recommended_links
    except Timeout as te:
        print('Timed out waiting for recommended links to load')
        print(te)
        return recommended_links