本文整理汇总了Python中apt.debfile.DebPackage.dsOfHeader方法的典型用法代码示例。如果您正苦于以下问题:Python DebPackage.dsOfHeader方法的具体用法?Python DebPackage.dsOfHeader怎么用?Python DebPackage.dsOfHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apt.debfile.DebPackage
的用法示例。
在下文中一共展示了DebPackage.dsOfHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WriteCacheInfo
# 需要导入模块: from apt.debfile import DebPackage [as 别名]
# 或者: from apt.debfile.DebPackage import dsOfHeader [as 别名]
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()
示例2: IsPackageInstalled
# 需要导入模块: from apt.debfile import DebPackage [as 别名]
# 或者: from apt.debfile.DebPackage import dsOfHeader [as 别名]
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()
示例3: IsPackageInstalled
# 需要导入模块: from apt.debfile import DebPackage [as 别名]
# 或者: from apt.debfile.DebPackage import dsOfHeader [as 别名]
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
示例4: WriteCacheInfo
# 需要导入模块: from apt.debfile import DebPackage [as 别名]
# 或者: from apt.debfile.DebPackage import dsOfHeader [as 别名]
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