Example #1
0
def test_run_command():
    print("Testing utils.run_command")
    from sregistry.utils import run_command

    result = run_command(["echo", "hello"])
    assert result["message"] == "hello\n"
    assert result["return_code"] == 0
Example #2
0
def get_environment_tar(self):
    '''return the environment.tar generated with the Singularity software.
       We first try the Linux Filesystem expected location in /usr/libexec
       If not found, we detect the system archicture

       dirname $(singularity selftest 2>&1 | grep 'lib' | awk '{print $4}' | sed -e 's@\(.*/singularity\).*@\1@')
    '''
    from sregistry.utils import ( which, run_command )

    # First attempt - look at File System Hierarchy Standard (FHS)
    res = which('singularity')['message']
    libexec = res.replace('/bin/singularity','')
    envtar = '%s/libexec/singularity/bootstrap-scripts/environment.tar' %libexec

    if os.path.exists(envtar):
        return envtar

    # Second attempt, debian distribution will identify folder
    try:
        res = which('dpkg-architecture')['message']
        if res is not None:
            cmd = ['dpkg-architecture', '-qDEB_HOST_MULTIARCH']
            triplet = run_command(cmd)['message'].strip('\n')
            envtar = '/usr/lib/%s/singularity/bootstrap-scripts/environment.tar' %triplet
            if os.path.exists(envtar):
                return envtar
    except:
        pass

    # Final, return environment.tar provided in package
    return "%s/environment.tar" %os.path.abspath(os.path.dirname(__file__))
Example #3
0
    def run_command(self, cmd, sudo=False, quiet=False):
        '''run_command is a wrapper for the global run_command, checking first
        for sudo and exiting on error if needed
        :param cmd: the command to run
        :param sudo: does the command require sudo?
        On success, returns result. Otherwise, exists on error
        '''
        result = run_command(cmd, sudo=sudo)
        message = result['message']
        return_code = result['return_code']

        if result['return_code'] == 0:
            if isinstance(message, bytes):
                try:
                    message = message.decode('utf-8')
                except UnicodeDecodeError:
                    try:
                        message = unicode(message, errors='replace')
                    except NameError:
                        message = str(message, errors='replace')
            return message
        if quiet is False:
            bot.error("Return Code %s: %s" % (return_code, message))
        sys.exit(1)
Example #4
0
from sregistry.utils import run_command
import json
import pickle

# Read in list of prefixes

words = json.load(open('search-terms.json','r'))

containers = []
count = 0
start = 0
save_index = 0
for w in range(start, len(words)):
    word = words[w]
    res = run_command(['docker', 'search', '--limit', '100', word])

    # If we hit 50K, save to new file
    if count % 50000 == 0:
        pickle.dump(containers, open('containers_%s.pkl' %save_index, 'wb'))
        containers = []
        save_index+=1

    # If a delimiter of 100, save to index
    elif count % 100 == 0:
        pickle.dump(containers, open('containers_%s.pkl' %save_index, 'wb'))
    if res['return_code'] == 0:
        res = res['message']
        lines = res.split('\n')[1:-1]
        for line in lines:
            container = line.split(' ')[0].strip()
Example #5
0
from sregistry.utils import run_command
import json
import pickle

# Read in list of prefixes

words = json.load(open('search-terms.json', 'r'))

containers = []
count = 0
start = 0
save_index = 0
for w in range(start, len(words)):
    word = words[w]
    res = run_command(['docker', 'search', '--limit', '100', word])

    # If we hit 50K, save to new file
    if count % 50000 == 0:
        pickle.dump(containers, open('containers_%s.pkl' % save_index, 'wb'))
        containers = []
        save_index += 1

    # If a delimiter of 100, save to index
    elif count % 100 == 0:
        pickle.dump(containers, open('containers_%s.pkl' % save_index, 'wb'))
    if res['return_code'] == 0:
        res = res['message']
        lines = res.split('\n')[1:-1]
        for line in lines:
            container = line.split(' ')[0].strip()