コード例 #1
0
ファイル: utils.py プロジェクト: michaelmoore10/sregistry-cli
def get_endpoint_path(self, endpoint_id):
    '''return the first fullpath to a folder in the endpoint based on
       expanding the user's home from the globus config file. This
       function is fragile but I don't see any other way to do it.
    
       Parameters
       ==========
       endpoint_id: the endpoint id to look up the path for

    '''
    config = os.path.expanduser("~/.globusonline/lta/config-paths")
    if not os.path.exists(config):
        bot.error('%s not found for a local Globus endpoint.')
        sys.exit(1)

    path = None

    # Read in the config and get the root path

    config = [x.split(',')[0] for x in read_file(config)]
    for path in config:
        if os.path.exists(path):
            break

    # If we don't have an existing path, exit

    if path is None:
        bot.error('No path was found for a local Globus endpoint.')
        sys.exit(1)

    return path
コード例 #2
0
ファイル: test_utils.py プロジェクト: ogawa/sregistry-cli
def test_write_read_files(tmp_path):
    '''test_write_read_files will test the functions write_file and read_file
    '''
    print("Testing utils.write_file...")
    from sregistry.utils import write_file
    tmpfile = str(tmp_path / 'written_file.txt')
    assert not os.path.exists(tmpfile)
    write_file(tmpfile, "hello!")
    assert os.path.exists(tmpfile)

    print("Testing utils.read_file...")
    from sregistry.utils import read_file
    content = read_file(tmpfile)[0]
    assert content == "hello!"
コード例 #3
0
def logs(content=''):
    '''return a plain text log to parse into any view for the user
    '''

    logfile = '/tmp/tunel-server-%s.log' % app.config.get('ROBOTNAME')
    if os.path.exists(logfile):
        content = read_file(logfile)

    if not isinstance(content, list):
        content = [content]

    # Add the name of the log as the first line
    content = [logfile + '\n'] + content

    return Response(content, status=200, mimetype='text/plain')
コード例 #4
0
ファイル: utils.py プロジェクト: singularityhub/sregistry-cli
def get_build_template(name=None, manager="apt"):
    """get a particular build template, by default we return templates
       that are based on package managers.

       Parameters
       ==========
       name: the full path of the template file to use.
       manager: the package manager to use in the template (yum or apt)

    """
    base = get_installdir()
    if name is None:
        name = "%s/main/templates/build/singularity-builder-%s.sh" % (base, manager)

    if os.path.exists(name):
        bot.debug("Found template %s" % name)
        return "".join(read_file(name))

    bot.warning("Template %s not found." % name)