Exemple #1
0
def maybe_update_hsi():
    """
    If the hsi wrapper script has changed, grab and edit a fresh copy
    """
    l = util.which_all('hsi')
    trg = l[0]
    tc = util.contents(trg).split("\n")
    tv = util.grep('^BINARYVERSION=', tc)

    s = [x for x in l if 'sources/hpss' in x]
    src = s[0]
    sc = util.contents(src).split("\n")
    sv = util.grep('^BINARYVERSION=', sc)

    if tv[0] != sv[0]:
        z = util.grep("${EXECUTABLE}", sc, regex=False, index=True)
        sc[z[0]] = "exec " + sc[z[0]]
        try:
            f = open(trg, 'w')
            f.writelines("\n".join(sc) + "\n")
            f.close()
        except IOError as e:
            CrawlConfig.log(MSG.hsi_wrap_ood)
Exemple #2
0
def test_grep():
    ret = ''
    ret += util.to_json(util.grep('dir2', '2019')) + '\n\n'
    ret += util.to_json(util.grep('dir2', '\d')) + '\n\n'
    ret += util.to_json(util.grep('dir2/file1.txt', 'b')) + '\n\n'
    ret += util.to_json(util.grep('dir2/file1.txt', 'a|b')) + '\n\n'
    ret += util.to_json(util.grep('dir2/file1.txt', 'z')) + '\n\n'
    #ret += util.to_json(util.grep('C:/Program Files', '\d')) + '\n\n'
    ret += util.grep('dir2', '\d', output='text') + '\n\n'

    ret += '\\.log$\n'
    ret += util.grep('dir2', '\d', filename=r'\.log$', output='text') + '\n\n'

    return ret
Exemple #3
0
    def check(self, test):
        """
        """
        success = 1

        [testname, args] = self.rule.split("=")
        if testname[0] == "!":
            self.false = 1
            testname = testname[1:]
        [kind, case] = testname.split("_")
        if "|" in args:
            [key, value] = args.split("|", 1)
        else:
            [key, value] = [args, None]

        if kind == "PACMAN":
            if case == "RETCODE":
                if test.retcode != int(key):
                    success = 0
            elif case == "OUTPUT":
                logfile = os.path.join(test.root, util.LOGFILE)
                if not os.access(logfile, os.F_OK):
                    tap.diag(
                        "LOGFILE not found, cannot validate 'OUTPUT' rule")
                    success = 0
                elif not util.grep(logfile, key):
                    success = 0
            else:
                tap.diag("PACMAN rule '%s' not found" % case)
                success = -1
        elif kind == "PKG":
            localdb = test.db["local"]
            newpkg = localdb.db_read(key)
            if not newpkg:
                success = 0
            else:
                if case == "EXIST":
                    success = 1
                elif case == "VERSION":
                    if value != newpkg.version:
                        success = 0
                elif case == "DESC":
                    if value != newpkg.desc:
                        success = 0
                elif case == "GROUPS":
                    if not value in newpkg.groups:
                        success = 0
                elif case == "PROVIDES":
                    if not value in newpkg.provides:
                        success = 0
                elif case == "DEPENDS":
                    if not value in newpkg.depends:
                        success = 0
                elif case == "OPTDEPENDS":
                    success = 0
                    for optdep in newpkg.optdepends:
                        if value == optdep.split(':', 1)[0]:
                            success = 1
                            break
                elif case == "REASON":
                    if newpkg.reason != int(value):
                        success = 0
                elif case == "FILES":
                    if not value in newpkg.files:
                        success = 0
                elif case == "BACKUP":
                    success = 0
                    for f in newpkg.backup:
                        if f.startswith(value + "\t"):
                            success = 1
                            break
                else:
                    tap.diag("PKG rule '%s' not found" % case)
                    success = -1
        elif kind == "FILE":
            filename = os.path.join(test.root, key)
            if case == "EXIST":
                if not os.path.isfile(filename):
                    success = 0
            elif case == "EMPTY":
                if not (os.path.isfile(filename)
                        and os.path.getsize(filename) == 0):
                    success = 0
            elif case == "CONTENTS":
                try:
                    with open(filename, 'r') as f:
                        success = f.read() == value
                except:
                    success = 0
            elif case == "MODIFIED":
                for f in test.files:
                    if f.name == key:
                        if not f.ismodified():
                            success = 0
                        break
            elif case == "MODE":
                if not os.path.isfile(filename):
                    success = 0
                else:
                    mode = os.lstat(filename)[stat.ST_MODE]
                    if int(value, 8) != stat.S_IMODE(mode):
                        success = 0
            elif case == "TYPE":
                if value == "dir":
                    if not os.path.isdir(filename):
                        success = 0
                elif value == "file":
                    if not os.path.isfile(filename):
                        success = 0
                elif value == "link":
                    if not os.path.islink(filename):
                        success = 0
            elif case == "PACNEW":
                if not os.path.isfile("%s.pacnew" % filename):
                    success = 0
            elif case == "PACSAVE":
                if not os.path.isfile("%s.pacsave" % filename):
                    success = 0
            else:
                tap.diag("FILE rule '%s' not found" % case)
                success = -1
        elif kind == "DIR":
            filename = os.path.join(test.root, key)
            if case == "EXIST":
                if not os.path.isdir(filename):
                    success = 0
            else:
                tap.diag("DIR rule '%s' not found" % case)
                success = -1
        elif kind == "LINK":
            filename = os.path.join(test.root, key)
            if case == "EXIST":
                if not os.path.islink(filename):
                    success = 0
            else:
                tap.diag("LINK rule '%s' not found" % case)
                success = -1
        elif kind == "CACHE":
            cachedir = os.path.join(test.root, util.PM_CACHEDIR)
            if case == "EXISTS":
                pkg = test.findpkg(key, value, allow_local=True)
                if not pkg or not os.path.isfile(
                        os.path.join(cachedir, pkg.filename())):
                    success = 0
        else:
            tap.diag("Rule kind '%s' not found" % kind)
            success = -1

        if self.false and success != -1:
            success = not success
        self.result = success
        return success
from util import grep

used_functions = list(
    map(
        lambda x: x.replace('getHttpsCallable("', '').replace('"', ''),
        sorted(grep("getHttpsCallable\(\".*?\"", "../client",
                    ('.kt', '.java')))))
functions = list(
    map(
        lambda x: x.replace('exports.', '').replace(' = functions', ''),
        sorted(
            grep("exports.*? = functions", "../functions/functions/src",
                 '.ts'))))

diff = [item for item in used_functions if item not in functions] + [
    item for item in functions
    if item not in used_functions and item != 'onUserDeleted'
    and item != 'onUserSignUp' and item != 'checkIfExpiredSubscriptionsRenewed'
    and item != 'sendNewSongNotification'
]
if len(diff) != 0:
    raise Exception(diff)
Exemple #5
0
    def check(self, test):
        """
        """
        success = 1

        [testname, args] = self.rule.split("=")
        if testname[0] == "!":
            self.false = 1
            testname = testname[1:]
        [kind, case] = testname.split("_")
        if "|" in args:
            [key, value] = args.split("|", 1)
        else:
            [key, value] = [args, None]

        if kind == "PACMAN":
            if case == "RETCODE":
                if test.retcode != int(key):
                    success = 0
            elif case == "OUTPUT":
                logfile = os.path.join(test.root, util.LOGFILE)
                if not os.access(logfile, os.F_OK):
                    tap.diag("LOGFILE not found, cannot validate 'OUTPUT' rule")
                    success = 0
                elif not util.grep(logfile, key):
                    success = 0
            else:
                tap.diag("PACMAN rule '%s' not found" % case)
                success = -1
        elif kind == "PKG":
            localdb = test.db["local"]
            newpkg = localdb.db_read(key)
            if not newpkg:
                success = 0
            else:
                if case == "EXIST":
                    success = 1
                elif case == "VERSION":
                    if value != newpkg.version:
                        success = 0
                elif case == "DESC":
                    if value != newpkg.desc:
                        success = 0
                elif case == "GROUPS":
                    if not value in newpkg.groups:
                        success = 0
                elif case == "PROVIDES":
                    if not value in newpkg.provides:
                        success = 0
                elif case == "DEPENDS":
                    if not value in newpkg.depends:
                        success = 0
                elif case == "OPTDEPENDS":
                    success = 0
                    for optdep in newpkg.optdepends:
                        if value == optdep.split(':', 1)[0]:
                            success = 1
                            break
                elif case == "REASON":
                    if newpkg.reason != int(value):
                        success = 0
                elif case == "FILES":
                    if not value in newpkg.files:
                        success = 0
                elif case == "BACKUP":
                    found = 0
                    for f in newpkg.backup:
                        name, md5sum = f.split("\t")
                        if value == name:
                            found = 1
                    if not found:
                        success = 0
                else:
                    tap.diag("PKG rule '%s' not found" % case)
                    success = -1
        elif kind == "FILE":
            filename = os.path.join(test.root, key)
            if case == "EXIST":
                if not os.path.isfile(filename):
                    success = 0
            elif case == "EMPTY":
                if not (os.path.isfile(filename)
                        and os.path.getsize(filename) == 0):
                    success = 0
            elif case == "MODIFIED":
                for f in test.files:
                    if f.name == key:
                        if not f.ismodified():
                            success = 0
                        break
            elif case == "MODE":
                if not os.path.isfile(filename):
                    success = 0
                else:
                    mode = os.lstat(filename)[stat.ST_MODE]
                    if int(value, 8) != stat.S_IMODE(mode):
                        success = 0
            elif case == "TYPE":
                if value == "dir":
                    if not os.path.isdir(filename):
                        success = 0
                elif value == "file":
                    if not os.path.isfile(filename):
                        success = 0
                elif value == "link":
                    if not os.path.islink(filename):
                        success = 0
            elif case == "PACNEW":
                if not os.path.isfile("%s.pacnew" % filename):
                    success = 0
            elif case == "PACORIG":
                if not os.path.isfile("%s.pacorig" % filename):
                    success = 0
            elif case == "PACSAVE":
                if not os.path.isfile("%s.pacsave" % filename):
                    success = 0
            else:
                tap.diag("FILE rule '%s' not found" % case)
                success = -1
        elif kind == "DIR":
            filename = os.path.join(test.root, key)
            if case == "EXIST":
                if not os.path.isdir(filename):
                    success = 0
            else:
                tap.diag("DIR rule '%s' not found" % case)
                success = -1
        elif kind == "LINK":
            filename = os.path.join(test.root, key)
            if case == "EXIST":
                if not os.path.islink(filename):
                    success = 0
            else:
                tap.diag("LINK rule '%s' not found" % case)
                success = -1
        elif kind == "CACHE":
            cachedir = os.path.join(test.root, util.PM_CACHEDIR)
            if case == "EXISTS":
                pkg = test.findpkg(key, value, allow_local=True)
                if not pkg or not os.path.isfile(
                        os.path.join(cachedir, pkg.filename())):
                    success = 0
        else:
            tap.diag("Rule kind '%s' not found" % kind)
            success = -1

        if self.false and success != -1:
            success = not success
        self.result = success
        return success
Exemple #6
0
import os

from util import grep

used_textures = list(
    map(lambda x: x.replace('\'', '').replace('.png', ''),
        sorted(grep("img_.*\'", "../lib", '.dart'))))
texture_files = list(
    map(lambda x: x.replace('.svg', ''), sorted(os.listdir('images'))))
diff = [item for item in texture_files if item not in used_textures
        ] + [item for item in used_textures if item not in texture_files]
if len(diff) != 0:
    raise Exception(diff)
from util import grep

used_strings = list(map(lambda x: x.replace('.', '').replace(')', '').replace(',', '').replace(';', '').split('(', 1)[0],
                        sorted(grep('\.txt_.*?\,', "../lib", '.dart')) + sorted(grep('\.txt_.*?\;', "../lib", '.dart'))+ sorted(grep('\.txt_.*?\)', "../lib", '.dart'))))
strings = list(map(lambda x: x.replace('"', ''), sorted(grep("\"txt_.*?\"", "../lib/l10n", '.arb'))))
diff = [item for item in used_strings if item not in strings] + [item for item in strings if item not in used_strings]
if len(diff) != 0:
    raise Exception(diff)
Exemple #8
0
from util import grep

used_strings = list(
    map(
        lambda x: x.replace('.', '').replace(')', '').replace(',', '').replace(
            ';', '').split('(', 1)[0],
        sorted(grep('\.txt_.*?\,', "../lib", '.dart')) +
        sorted(grep('\.txt_.*?\;', "../lib", '.dart')) +
        sorted(grep('\.txt_.*?\)', "../lib", '.dart'))))
strings = list(
    map(lambda x: x.replace('"', ''),
        sorted(grep("\"txt_.*?\"", "../lib/l10n", '.arb'))))
diff = [item for item in used_strings if item not in strings
        ] + [item for item in strings if item not in used_strings]
if len(diff) != 0:
    raise Exception(diff)