本文整理汇总了Python中apt.Cache方法的典型用法代码示例。如果您正苦于以下问题:Python apt.Cache方法的具体用法?Python apt.Cache怎么用?Python apt.Cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apt
的用法示例。
在下文中一共展示了apt.Cache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IsFFMPEG
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def IsFFMPEG():
''' Chech if FFMPEG is present '''
if windows:
if not os.path.isdir(ffmpegConf):
return False
if not os.path.isfile(os.path.join(ffmpegConf, 'ffmpeg.exe')):
return False
else:
cache = apt.Cache()
cache.open()
try:
return cache["ffmpeg"].is_installed
except Exception:
# does not exist
return False
return True
示例2: detect_installation
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def detect_installation():
if is_debian(): # For apt-based distros.
import apt
cache = apt.Cache()
if 'wott-agent' in cache and __file__ in cache['wott-agent'].installed_files:
return Installation.DEB
elif is_amazon_linux2(): # For Amazon Linux 2.
import rpm
ts = rpm.ts()
package_iterator = ts.dbMatch('name', 'python3-wott-agent')
if package_iterator.count() > 0:
package_header = next(package_iterator)
if __file__.encode() in package_header[rpm.RPMTAG_FILENAMES]:
return Installation.RPM
# Other.
from agent import __version__
if isinstance(__version__, pkg_resources.Distribution):
return Installation.PYTHON_PACKAGE
return Installation.NONE
示例3: IsLavFilters
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def IsLavFilters():
''' Check if LavFilters is present '''
if windows:
software_list = WinSoftwareInstalled(winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_32KEY) + WinSoftwareInstalled(winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_64KEY) + WinSoftwareInstalled(winreg.HKEY_CURRENT_USER, 0)
if not any('LAV Filters' in software['name'] for software in software_list):
# does not exist
return False
else:
cache = apt.Cache()
cache.open()
try:
#print("lav filters")
return cache["gst123"].is_installed
except Exception:
# does not exist
return False
return True
示例4: identify_screensaver
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def identify_screensaver():
cache = apt.Cache()
logging.debug('Getting apt cache.')
logging.debug('Checking if supported screensaver packages are installed.')
if cache['xscreensaver'].is_installed and cache['gnome-screensaver'].is_installed:
logging.debug('xscreensaver and gnome-screensaver installed. User must specify which package to monitor.')
print("XScreenSaver and gnome-screensaver detected. Please select active screensaver in the settings file "
"before proceeding.")
sys.exit(403)
if cache['xscreensaver'].is_installed:
logging.debug('\txscreensaver installed.')
return 'xscreensaver'
elif cache['gnome-screensaver'].is_installed:
logging.debug('\tgnome-screensaver installed.')
return 'gnome-screensaver'
else:
print('Unable to run application, screensaver supported?')
logging.critical('Aborting... Unable to run application, screensaver not supported.')
sys.exit(402)
示例5: get_latest_same_kernel_deb
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def get_latest_same_kernel_deb(name_part0, name_part2):
"""
Return the latest version of a deb package for given name parts.
"""
import apt
search_pattern = re.compile(name_part0 + r'(\d+)' + name_part2)
class KernelFilter(apt.cache.Filter):
"""Filter class for checking for matching with a RE search pattern."""
def apply(self, pkg):
return pkg.is_installed and search_pattern.match(pkg.name)
cache = apt.cache.FilteredCache(apt.Cache())
cache.set_filter(KernelFilter())
return sorted([(int(search_pattern.match(deb.name).group(1)), deb) for deb in cache],
reverse=True)[0][1]
示例6: get_updates
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def get_updates():
cache = apt.Cache()
cache.open(None)
cache.upgrade()
return str(cache.get_changes().__len__())
示例7: show_autoremovable_pkgs
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def show_autoremovable_pkgs():
"""List all the kernel related packages available for autoremoval.
"""
packages = {}
ver_max_len = 0
try:
apt_cache = apt.Cache()
except SystemError:
logger.error("Unable to obtain the cache!")
sys.exit(1)
for pkg_name in apt_cache.keys():
pkg = apt_cache[pkg_name]
if (pkg.is_installed and pkg.is_auto_removable) and re.match(
r"^linux-(image|(\w+-)?headers)-.*$", pkg_name
):
packages[pkg_name] = pkg.installed.version
if ver_max_len < len(pkg.installed.version):
ver_max_len = len(pkg.installed.version)
if packages:
logger.info("List of kernel packages available for autoremoval:")
logger.info(
"{0:>{width}} {1:<{width}}".format(
"Version", "Package", width=ver_max_len + 2
)
)
for package in sorted(packages.keys()):
logger.info(
"{0:>{width}} {1:<{width}}".format(
packages[package], package, width=ver_max_len + 2
)
)
logger.log(
42,
"kernel packages available for autoremoval: {0}".format(
sorted(packages.keys())
),
)
else:
logger.log(42, "No kernel packages available for autoremoval.")
示例8: __init__
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def __init__(self, file_in, install):
QtCore.QThread.__init__(self)
self.cache = apt.Cache(None)
self.cache.open()
self.file_in = file_in
self.install = install
self.isDone = False
self.logger = logging.getLogger(__name__)
self.logger.setLevel(logging.DEBUG)
handler = logging.FileHandler('/var/log/resetter/resetter.log')
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
self.logger.addHandler(handler)
self.resolver = apt.cache.ProblemResolver(self.cache)
self.aprogress = UIAcquireProgress(False)
self.thread1 = QtCore.QThread()
self.aprogress.moveToThread(self.thread1)
self.thread1.started.connect(lambda: self.aprogress.play(0.0, False, ""))
self.aprogress.finished.connect(self.thread1.quit)
self.thread2 = QtCore.QThread()
self.iprogress = UIInstallProgress()
self.iprogress.moveToThread(self.thread2)
self.thread2.started.connect(lambda: self.iprogress.play(0.0, ""))
self.iprogress.finished.connect(self.thread2.quit)
self.broken_list = []
示例9: __init__
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def __init__(self, file_in, install):
QtCore.QThread.__init__(self)
self.op_progress = None
self.cache = apt.Cache(self.op_progress)
self.cache.open()
self.file_in = file_in
self.isDone = False
self.logger = logging.getLogger(__name__)
self.logger.setLevel(logging.DEBUG)
handler = logging.FileHandler('/var/log/resetter/resetter.log')
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
self.logger.addHandler(handler)
self.install = install
self.aprogress = UIAcquireProgress(False)
self.thread1 = QtCore.QThread()
self.aprogress.moveToThread(self.thread1)
self.thread1.started.connect(lambda: self.aprogress.play(0.0, False, ''))
self.aprogress.finished.connect(self.thread1.quit)
self.iprogress = UIInstallProgress()
self.thread2 = QtCore.QThread()
self.iprogress.moveToThread(self.thread2)
self.thread2.started.connect(lambda: self.iprogress.play(0.0, ''))
self.iprogress.finished.connect(self.thread2.quit)
self.broken_list = []
示例10: __init__
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def __init__(self, file_in, install):
QtCore.QThread.__init__(self)
self.cache = apt.Cache(None)
self.cache.open()
self.file_in = file_in
self.isDone = False
self.error_msg = QMessageBox()
self.error_msg.setIcon(QMessageBox.Critical)
self.error_msg.setWindowTitle("Error")
self.logger = logging.getLogger(__name__)
self.logger.setLevel(logging.DEBUG)
handler = logging.FileHandler('/var/log/resetter/resetter.log')
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
self.logger.addHandler(handler)
self.install = install
self.aprogress = UIAcquireProgress(False)
self.thread1 = QtCore.QThread()
self.aprogress.moveToThread(self.thread1)
self.thread1.started.connect(lambda: self.aprogress.play(0.0, False, ""))
self.aprogress.finished.connect(self.thread1.quit)
self.iprogress = UIInstallProgress()
self.thread2 = QtCore.QThread()
self.iprogress.moveToThread(self.thread2)
self.thread2.started.connect(lambda: self.iprogress.play(0.0, ""))
self.iprogress.finished.connect(self.thread2.quit)
self.broken_list = []
示例11: update_apt_cache
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def update_apt_cache(self, init=False):
'''if init is true, force to update, or it will update only once'''
if init or not getattr(self, 'cache'):
apt_pkg.init()
self.cache = apt.Cache()
示例12: get_kernel_deb_package
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def get_kernel_deb_package(boot_image_path):
"""
Return a deb package instance for the currently running kernel.
"""
import apt
class FileFilter(apt.cache.Filter):
def apply(self, pkg):
return pkg.is_installed and boot_image_path in pkg.installed_files
cache = apt.cache.FilteredCache(apt.Cache())
cache.set_filter(FileFilter())
kernel_debs = list(cache)
if kernel_debs:
return kernel_debs[0]
示例13: upgrade_packages
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def upgrade_packages(pkg_names):
"""
Update all passed (as a list) OS packages.
"""
unique_names = set(pkg_names)
message = "The following packages will be upgraded:\n\t{}\nConfirm:"
packages = []
if is_debian(): # For apt-based distros.
import apt
cache = apt.cache.Cache()
cache.update(apt.progress.text.AcquireProgress())
cache.open()
for pkg_name in unique_names:
# Older versions of python3-apt don't provide full dict interface, namely .get().
# The result of this expression will either be False or a apt.package.Package instance.
pkg = pkg_name in cache and cache[pkg_name]
if pkg and pkg.is_installed and pkg.is_upgradable:
packages.append(pkg_name)
pkg.mark_upgrade()
if confirmation(message.format(', '.join(packages))):
cache.commit()
elif is_amazon_linux2(): # For Amazon Linux 2.
import rpm
from sh import yum # pylint: disable=E0401
ts = rpm.ts()
# This will be a list like:
# package.arch version repo
list_updates = yum(['list', 'updates', '-q', '--color=no']).stdout
# This will get a list of "package.arch"
updates = [line.split(maxsplit=1)[0] for line in list_updates.splitlines()[1:]]
for pkg_name in unique_names:
package_iterator = ts.dbMatch('name', pkg_name)
for package in package_iterator:
# Package may be installed for multiple architectures. Get them all.
fullname = b'.'.join((package[rpm.RPMTAG_NAME], package[rpm.RPMTAG_ARCH]))
if fullname in updates:
packages.append(fullname.decode())
if confirmation(message.format(', '.join(packages))):
yum(['update', '-y'] + packages)
示例14: updated_cache
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def updated_cache(backup_ext, sources):
with locked_sources_list():
with sources_list_only(backup_ext, sources):
cache = apt.Cache()
cache.update()
cache.open(None)
yield cache
示例15: __init__
# 需要导入模块: import apt [as 别名]
# 或者: from apt import Cache [as 别名]
def __init__(self, parent=None):
super(EasyInstaller, self).__init__(parent)
self.setWindowTitle("Easy install")
self.list_view = QListView(self)
self.list_view.setFixedWidth(380)
self.EditText = QLineEdit()
self.EditText.setPlaceholderText("Search for applications")
self.model = QtGui.QStandardItemModel(self.list_view)
self.setFixedSize(600, 350)
self.font = QtGui.QFont()
self.font.setBold(True)
self.font2 = QtGui.QFont()
self.font2.setBold(False)
self.EditText = QLineEdit()
self.EditText.setPlaceholderText("Add apps to install")
self.btnRemove = QPushButton()
self.btnInstall = QPushButton()
self.btnBrowse = QPushButton()
self.btnBrowse.setFixedWidth(100)
self.btnBrowse.clicked.connect(self.openBackup)
self.btnBrowse.setText("Open Backup")
self.btnRemove.setText("Remove From List")
self.btnRemove.clicked.connect(self.removeItems)
self.btnInstall.setText("Install Apps")
self.btnInstall.clicked.connect(self.installPackages)
self.btnadd = QPushButton(self)
self.btnadd.setText("Add App")
self.btnClose = QPushButton()
self.btnClose.setText("Close")
self.btnClose.clicked.connect(self.closeview)
self.btnadd.clicked.connect(self.addItems)
self.btnselect = QPushButton()
self.btnselect.setText("Select All")
self.btnselect.clicked.connect(self.selectAll)
self.comboBox = QComboBox()
self.comboBox.setVisible(False)
self.comboBox.currentIndexChanged.connect(self.setText)
miniLayout = QVBoxLayout()
miniLayout.addWidget(self.EditText)
miniLayout.addWidget(self.comboBox)
horizontalLayout = QHBoxLayout()
horizontalLayout.addLayout(miniLayout)
horizontalLayout.addWidget(self.btnadd)
horizontalLayout.addWidget(self.btnBrowse)
horizontalLayout.setAlignment(QtCore.Qt.AlignRight)
horizontalLayout2 = QHBoxLayout()
horizontalLayout2.addWidget(self.btnRemove)
horizontalLayout2.addWidget(self.btnselect)
horizontalLayout2.addWidget(self.btnInstall)
horizontalLayout2.addWidget(self.btnClose)
verticalLayout = QVBoxLayout(self)
verticalLayout.addLayout(horizontalLayout)
verticalLayout.addWidget(self.list_view)
verticalLayout.addLayout(horizontalLayout2)
self.cache = apt.Cache()
self.isWritten = False