示例#1
0
def systemInfo():
    """
    Returns some system information.
    """
    logFull('helpers:systemInfo')
    system = platform.machine() + ' ' + platform.system() + ', ' + ' '.join(
        platform.linux_distribution())
    python = '.'.join([str(v) for v in sys.version_info])
    return '{}\nPython {}'.format(system.strip(), python)
示例#2
0
def encrypt(bdata, encr_key):
    """
    Encrypt some data.
    """
    logFull('helpers:encrypt')
    # Enhance user password with PBKDF2
    pwd = PBKDF2(password=encr_key,
                 salt='^0Twister-Salt9$',
                 dkLen=32,
                 count=100)
    crypt = AES.new(pwd)
    pad_len = 16 - (len(bdata) % 16)
    padding = (chr(pad_len) * pad_len)
    # Encrypt user data + correct padding
    data = crypt.encrypt(bdata + padding)
    return binascii.hexlify(data)
示例#3
0
def getFileTags(fname):
    """
    Returns the title, description and all tags from a test file.
    """
    logFull('helpers:getFileTags')
    try:
        text = open(fname, 'rb').read()
    except:
        return ''

    # Find lines starting with # or beggining of line, followed by optional space,
    # followed by a <tag> ended with the same </tag> containing any character
    # in range 0x20 to 0x7e (all numbers, letters and ASCII symbols)
    # This returns 2 groups : the tag name and the text inside it.
    tags = re.findall('^[ ]*?[#]*?[ ]*?<(?P<tag>\w+)>([ -~\n]+?)</(?P=tag)>',
                      text, re.MULTILINE)

    return '<br>\n'.join([
        '<b>' + title + '</b> : ' + descr.replace('<', '&lt;')
        for title, descr in tags
    ])
示例#4
0
def decrypt(bdata, encr_key):
    """
    Decrypt some data.
    """
    logFull('helpers:decrypt')
    # Enhance user password with PBKDF2
    pwd = PBKDF2(password=encr_key,
                 salt='^0Twister-Salt9$',
                 dkLen=32,
                 count=100)
    crypt = AES.new(pwd)
    try:
        data = binascii.unhexlify(bdata)
    except:
        return ''
    try:
        decrypted = crypt.decrypt(data)
    except:
        return ''
    pad_len = ord(decrypted[-1])
    # Trim the padding
    return decrypted[:-pad_len]
示例#5
0
def dirList(tests_path, path, newdict):
    """
    Create recursive list of folders and files from Tests path.
    The format of a node is: {"data": "name", "attr": {"rel": "folder"}, "children": []}
    """
    logFull('helpers:dirList')
    len_path = len(tests_path) + 1
    if os.path.isdir(path):
        dlist = []  # Folders list
        flist = []  # Files list
        for fname in sorted(os.listdir(path), key=str.lower):
            short_path = (path + os.sep + fname)[len_path:]
            nd = {'data': short_path, 'children': []}
            if os.path.isdir(path + os.sep + fname):
                nd['attr'] = {'rel': 'folder'}
                dlist.append(nd)
            else:
                flist.append(nd)
        # Folders first, files second
        newdict['children'] = dlist + flist
    for nitem in newdict['children']:
        # Recursive !
        dirList(tests_path, tests_path + os.sep + nitem['data'], nitem)
示例#6
0
def execScript(script_path):
    """
    Execute a user script and return the text printed on the screen.
    """
    logFull('helpers:execScript')
    if not os.path.exists(script_path):
        logWarning(
            'Exec script: The path `{}` does not exist!'.format(script_path))
        return False

    try:
        os.system('chmod +x {}'.format(script_path))
    except:
        pass

    logDebug('Executing script `{}`...'.format(script_path))

    try:
        txt = subprocess.check_output(script_path, shell=True)
        return txt.strip()
    except Exception as e:
        logWarning('Exec script `{}`: Exception - `{}`.'.format(
            script_path, e))
        return False