def WriteCacheInfo(p):
    if not os.path.isdir(cache_file_dir):
        if MakeDirs(cache_file_dir) is not None:
            return False
    if len(p.LocalPath) < 1:
        return False
    if apt is not None and os.path.splitext(p.LocalPath)[-1] == '.deb':
        from apt.debfile import DebPackage
        try:
            pkg = DebPackage(p.LocalPath)
        except:
            Print("Exception opening file " + p.LocalPath, file=sys.stderr)
            LG().Log('ERROR', "Exception opening file " + p.LocalPath)
            return False
        p.Name = pkg.pkgname
    elif rpm is not None and os.path.splitext(p.LocalPath)[-1] == '.rpm':
        F, error = opened_w_error(p.LocalPath, 'r')
        if error:
            Print("Exception opening file " + p.LocalPath, file=sys.stderr)
            LG().Log('ERROR', "Exception opening file " + p.LocalPath)
            return False
        ts = rpm.TransactionSet()
        ts.setVSFlags(-1)
        try:
            pkg = ts.hdrFromFdno(F.fileno())
        except rpm.error, e:
            Print(repr(e))
            LG().Log('ERROR', repr(e))
            pkg = None
            F.close()
        if pkg is None:
            return False
        p.Name = pkg.dsOfHeader().N()
示例#2
0
def WriteCacheInfo(p):
    if not os.path.isdir(cache_file_dir):
        if MakeDirs(cache_file_dir) is not None:
            return False
    if len(p.LocalPath) < 1:
        return False
    if apt is not None and os.path.splitext(p.LocalPath)[-1] == '.deb':
        from apt.debfile import DebPackage
        try:
            pkg = DebPackage(p.LocalPath)
        except:
            print("Exception opening file " + p.LocalPath, file=sys.stderr)
            LG().Log('ERROR',  "Exception opening file " + p.LocalPath)
            return False
        p.Name = pkg.pkgname
    elif rpm is not None and os.path.splitext(p.LocalPath)[-1] == '.rpm':
            with opened_w_error(p.LocalPath, 'r') as (F, error):
                if error:
                    print(
                        "Exception opening file " + p.LocalPath, file=sys.stderr)
                    LG().Log('ERROR',  "Exception opening file " + p.LocalPath)
                    return False
                ts = rpm.TransactionSet()
                ts.setVSFlags(-1)
                try:
                    pkg = ts.hdrFromFdno(F.fileno())
                except rpm.error, e:
                    print(repr(e))
                    LG().Log('ERROR',  repr(e))
                    pkg = None
            if pkg is None:
                return False
            p.Name = pkg.dsOfHeader().N()
def IsPackageInstalled(p):
    out = ''
    if p is None:
        return False, out
    if len(
            p.FilePath
    ) > 0 and '://' in p.FilePath:  # its a remote - try to file get name from cache
        if ReadCacheInfo(p) is False:
            return False, out
    elif len(p.FilePath) > 0 and os.path.exists(
            p.FilePath) is True:  # FilePath
        if apt is not None and os.path.splitext(p.FilePath)[-1] == '.deb':
            from apt.debfile import DebPackage
            pkg = DebPackage(p.FilePath)
            p.Name = pkg.pkgname
        elif rpm is not None and os.path.splitext(p.FilePath)[-1] == '.rpm':
            F = open(p.FilePath, 'r')
            ts = rpm.TransactionSet()
            ts.setVSFlags(-1)
            try:
                pkg = ts.hdrFromFdno(F.fileno())
            except rpm.error, e:
                F.close()
                Print(repr(e))
                LG().Log('ERROR', repr(e))
                pkg = None
            F.close()
            if pkg is None:
                return False, out
            p.Name = pkg.dsOfHeader().N()
示例#4
0
def IsPackageInstalled(p):
    out = ''
    if p is None:
        return False, out
    if len(p.FilePath) > 0 and '://' in p.FilePath:  # its a remote - try to file get name from cache
        if ReadCacheInfo(p) is False:
            return False, out
    elif len(p.FilePath) > 0 and os.path.exists(p.FilePath) is True:  # FilePath
        if apt is not None and os.path.splitext(p.FilePath)[-1] == '.deb':
            from apt.debfile import DebPackage
            pkg = DebPackage(p.FilePath)
            p.Name = pkg.pkgname
        elif rpm is not None and os.path.splitext(p.FilePath)[-1] == '.rpm':
            with open(p.FilePath, 'r') as F:
                ts = rpm.TransactionSet()
                ts.setVSFlags(-1)
                try:
                    pkg = ts.hdrFromFdno(F.fileno())
                except rpm.error, e:
                    print(repr(e))
                    LG().Log('ERROR', repr(e))
                    pkg = None
            if pkg is None:
                return False, out
            p.Name = pkg.dsOfHeader().N()
def IsPackageInstalled(p):
    out = ''
    if p is None:
        return False, out
    if len(
            p.FilePath
    ) > 0 and '://' in p.FilePath:  # its a remote - try to file get name from cache
        if ReadCacheInfo(p) is False:
            return False, out
    elif len(p.FilePath) > 0 and os.path.exists(
            p.FilePath) is True:  # FilePath
        if apt is not None and os.path.splitext(p.FilePath)[-1] == '.deb':
            from apt.debfile import DebPackage
            pkg = DebPackage(p.FilePath)
            p.Name = pkg.pkgname
        elif rpm is not None and os.path.splitext(p.FilePath)[-1] == '.rpm':
            with open(p.FilePath, 'r') as F:
                ts = rpm.TransactionSet()
                ts.setVSFlags(-1)
                try:
                    pkg = ts.hdrFromFdno(F.fileno())
                except rpm.error as e:
                    print(repr(e))
                    LG().Log('ERROR', repr(e))
                    pkg = None
            if pkg is None:
                return False, out
            p.Name = pkg.dsOfHeader().N()
    if len(p.Name) < 1:
        return False, out

    if p.PackageGroup is True:
        if p.cmds[p.PackageManager]['stat_group'] is not None:
            cmd = p.cmds[p.PackageManager]['stat_group'] + '"' + p.Name + '"'
        else:
            print('ERROR.  PackageGroup is not valid for ' + p.PackageManager,
                  file=sys.stdout)
            LG().Log(
                'ERROR',
                'ERROR.  PackageGroup is not valid for ' + p.PackageManager)
            return False, out
    else:
        cmd = 'LANG=en_US.UTF8 ' + p.cmds[p.PackageManager]['stat'] + p.Name
    code, out = RunGetOutput(cmd, False)
    if p.PackageGroup is True:  # implemented for YUM only.
        if 'Installed' in out:
            return True, out
        else:
            return False, out
    # regular packages
    print('check installed:' + out)
    LG().Log('INFO', 'check installed:' + out)
    if code is 0:
        if 'deinstall' in out or 'not-installed' in out:
            code = 1
    if code is not int(p.ReturnCode):
        return False, out
    return True, out
def IsPackageInstalled(p):
    out = ''
    if p is None:
        return False, out
    if len(p.FilePath) > 0 and '://' in p.FilePath:  # its a remote - try to file get name from cache
        if ReadCacheInfo(p) is False:
            return False, out
    elif len(p.FilePath) > 0 and os.path.exists(p.FilePath) is True:  # FilePath
        if apt is not None and os.path.splitext(p.FilePath)[-1] == '.deb':
            from apt.debfile import DebPackage
            pkg = DebPackage(p.FilePath)
            p.Name = pkg.pkgname
        elif rpm is not None and os.path.splitext(p.FilePath)[-1] == '.rpm':
            with open(p.FilePath, 'r') as F:
                ts = rpm.TransactionSet()
                ts.setVSFlags(-1)
                try:
                    pkg = ts.hdrFromFdno(F.fileno())
                except rpm.error as e:
                    print(repr(e))
                    LG().Log('ERROR', repr(e))
                    pkg = None
            if pkg is None:
                return False, out
            p.Name = pkg.dsOfHeader().N()
    if len(p.Name) < 1:
        return False, out

    if p.PackageGroup is True:
        if p.cmds[p.PackageManager]['stat_group'] is not None:
            cmd = p.cmds[p.PackageManager]['stat_group'] + '"' + p.Name + '"'
        else:
            print('ERROR.  PackageGroup is not valid for ' +
                  p.PackageManager, file=sys.stdout)
            LG().Log(
                'ERROR', 'ERROR.  PackageGroup is not valid for ' + p.PackageManager)
            return False, out
    else:
        cmd = 'LANG=en_US.UTF8 ' + p.cmds[p.PackageManager]['stat'] + p.Name
    code, out = RunGetOutput(cmd, False)
    if p.PackageGroup is True:  # implemented for YUM only.
        if 'Installed' in out:
            return True, out
        else:
            return False, out
    # regular packages
    print('check installed:' + out)
    LG().Log('INFO',  'check installed:' + out)
    if code is 0:
        if 'deinstall' in out or 'not-installed' in out:
            code = 1
    if code is not int(p.ReturnCode):
        return False, out
    return True, out
def WriteCacheInfo(p):
    if not os.path.isdir(cache_file_dir):
        if MakeDirs(cache_file_dir) is not None:
            return False
    if len(p.LocalPath) < 1:
        return False
    if apt is not None and os.path.splitext(p.LocalPath)[-1] == '.deb':
        from apt.debfile import DebPackage
        try:
            pkg = DebPackage(p.LocalPath)
        except:
            print("Exception opening file " + p.LocalPath, file=sys.stderr)
            LG().Log('ERROR', "Exception opening file " + p.LocalPath)
            return False
        p.Name = pkg.pkgname
    elif rpm is not None and os.path.splitext(p.LocalPath)[-1] == '.rpm':
        with opened_w_error(p.LocalPath, 'r') as (F, error):
            if error:
                print("Exception opening file " + p.LocalPath, file=sys.stderr)
                LG().Log('ERROR', "Exception opening file " + p.LocalPath)
                return False
            ts = rpm.TransactionSet()
            ts.setVSFlags(-1)
            try:
                pkg = ts.hdrFromFdno(F.fileno())
            except rpm.error as e:
                print(repr(e))
                LG().Log('ERROR', repr(e))
                pkg = None
        if pkg is None:
            return False
        p.Name = pkg.dsOfHeader().N()
    if len(p.Name) < 1:
        return False
    cache_file_path = cache_file_dir + '/' + os.path.basename(p.LocalPath)
    with opened_w_error(cache_file_path, 'w+') as (F, error):
        if error:
            print("Exception creating cache file " + cache_file_path +
                  " Error Code: " + str(error.errno) + " Error: " +
                  error.strerror,
                  file=sys.stderr)
            LG().Log(
                'ERROR', "Exception creating cache file " + cache_file_path +
                " Error Code: " + str(error.errno) + " Error: " +
                error.strerror)
            return False
        F.write(p.Name + '\n')
        F.close()
    return True
def WriteCacheInfo(p):
    if not os.path.isdir(cache_file_dir):
        if MakeDirs(cache_file_dir) is not None:
            return False
    if len(p.LocalPath) < 1:
        return False
    if apt is not None and os.path.splitext(p.LocalPath)[-1] == '.deb':
        from apt.debfile import DebPackage
        try:
            pkg = DebPackage(p.LocalPath)
        except:
            print("Exception opening file " + p.LocalPath, file=sys.stderr)
            LG().Log('ERROR',  "Exception opening file " + p.LocalPath)
            return False
        p.Name = pkg.pkgname
    elif rpm is not None and os.path.splitext(p.LocalPath)[-1] == '.rpm':
        with opened_w_error(p.LocalPath, 'r') as (F, error):
            if error:
                print("Exception opening file " + p.LocalPath, file=sys.stderr)
                LG().Log('ERROR',  "Exception opening file " + p.LocalPath)
                return False
            ts = rpm.TransactionSet()
            ts.setVSFlags(-1)
            try:
                pkg = ts.hdrFromFdno(F.fileno())
            except rpm.error as e:
                print(repr(e))
                LG().Log('ERROR',  repr(e))
                pkg = None
        if pkg is None:
            return False
        p.Name = pkg.dsOfHeader().N()
    if len(p.Name) < 1:
        return False
    cache_file_path = cache_file_dir + '/' + os.path.basename(p.LocalPath)
    with opened_w_error(cache_file_path, 'w+') as (F, error):
        if error:
            print("Exception creating cache file " + cache_file_path + " Error Code: " +
                  str(error.errno) + " Error: " + error.strerror, file=sys.stderr)
            LG().Log('ERROR',  "Exception creating cache file " + cache_file_path +
                     " Error Code: " + str(error.errno) + " Error: " + error.strerror)
            return False
        F.write(p.Name + '\n')
        F.close()
    return True