mirror of
https://github.com/isjerryxiao/pacroller.git
synced 2024-11-25 17:20:41 +08:00
support pacman -Scc
This commit is contained in:
parent
401ffcfcd3
commit
f95a66c7ea
3 changed files with 15 additions and 2 deletions
|
@ -16,5 +16,6 @@
|
||||||
],
|
],
|
||||||
"need_restart": false,
|
"need_restart": false,
|
||||||
"need_restart_cmd": ["needrestart", "-r", "a", "-m", "a", "-l"],
|
"need_restart_cmd": ["needrestart", "-r", "a", "-m", "a", "-l"],
|
||||||
"systemd-check": true
|
"systemd-check": true,
|
||||||
|
"clear_pkg_cache": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ LIB_DIR = Path('/var/lib/pacroller')
|
||||||
DB_FILE = 'db'
|
DB_FILE = 'db'
|
||||||
PACMAN_CONFIG = '/etc/pacman.conf'
|
PACMAN_CONFIG = '/etc/pacman.conf'
|
||||||
PACMAN_LOG = '/var/log/pacman.log'
|
PACMAN_LOG = '/var/log/pacman.log'
|
||||||
|
PACMAN_PKG_DIR = '/var/cache/pacman/pkg'
|
||||||
assert LIB_DIR.is_dir()
|
assert LIB_DIR.is_dir()
|
||||||
|
|
||||||
if (cfg := (CONFIG_DIR / CONFIG_FILE)).exists():
|
if (cfg := (CONFIG_DIR / CONFIG_FILE)).exists():
|
||||||
|
@ -41,3 +42,4 @@ for i in NEEDRESTART_CMD:
|
||||||
assert isinstance(i, str)
|
assert isinstance(i, str)
|
||||||
|
|
||||||
SYSTEMD = bool(_config.get('systemd-check', True))
|
SYSTEMD = bool(_config.get('systemd-check', True))
|
||||||
|
PACMAN_SCC = bool(_config.get('clear_pkg_cache', False))
|
||||||
|
|
|
@ -14,7 +14,8 @@ from pacroller.utils import execute_with_io, UnknownQuestionError, back_readline
|
||||||
from pacroller.checker import log_checker, sync_err_is_net, upgrade_err_is_net, checkReport
|
from pacroller.checker import log_checker, sync_err_is_net, upgrade_err_is_net, checkReport
|
||||||
from pacroller.config import (CONFIG_DIR, CONFIG_FILE, LIB_DIR, DB_FILE, PACMAN_LOG, PACMAN_CONFIG,
|
from pacroller.config import (CONFIG_DIR, CONFIG_FILE, LIB_DIR, DB_FILE, PACMAN_LOG, PACMAN_CONFIG,
|
||||||
TIMEOUT, UPGRADE_TIMEOUT, NETWORK_RETRY, CUSTOM_SYNC, SYNC_SH,
|
TIMEOUT, UPGRADE_TIMEOUT, NETWORK_RETRY, CUSTOM_SYNC, SYNC_SH,
|
||||||
EXTRA_SAFE, SHELL, HOLD, NEEDRESTART, NEEDRESTART_CMD, SYSTEMD)
|
EXTRA_SAFE, SHELL, HOLD, NEEDRESTART, NEEDRESTART_CMD, SYSTEMD,
|
||||||
|
PACMAN_PKG_DIR, PACMAN_SCC)
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
@ -203,6 +204,11 @@ def main() -> None:
|
||||||
else:
|
else:
|
||||||
logger.debug('using fallback locale C')
|
logger.debug('using fallback locale C')
|
||||||
environ['LANG'] = 'C'
|
environ['LANG'] = 'C'
|
||||||
|
def clear_pkg_cache() -> None:
|
||||||
|
logger.debug('clearing package cache')
|
||||||
|
for i in Path(PACMAN_PKG_DIR).iterdir():
|
||||||
|
if i.is_file():
|
||||||
|
i.unlink()
|
||||||
def run_needrestart(ignore_error=False) -> None:
|
def run_needrestart(ignore_error=False) -> None:
|
||||||
logger.debug('running needrestart')
|
logger.debug('running needrestart')
|
||||||
try:
|
try:
|
||||||
|
@ -260,6 +266,8 @@ def main() -> None:
|
||||||
exit(2)
|
exit(2)
|
||||||
if NEEDRESTART:
|
if NEEDRESTART:
|
||||||
run_needrestart()
|
run_needrestart()
|
||||||
|
if PACMAN_SCC:
|
||||||
|
clear_pkg_cache()
|
||||||
|
|
||||||
elif args.action == 'status':
|
elif args.action == 'status':
|
||||||
count = 0
|
count = 0
|
||||||
|
@ -307,6 +315,8 @@ def main() -> None:
|
||||||
logger.info(f'reset previous error {prev_err}')
|
logger.info(f'reset previous error {prev_err}')
|
||||||
if NEEDRESTART:
|
if NEEDRESTART:
|
||||||
run_needrestart(True)
|
run_needrestart(True)
|
||||||
|
if PACMAN_SCC:
|
||||||
|
clear_pkg_cache()
|
||||||
else:
|
else:
|
||||||
logger.warning('nothing to do')
|
logger.warning('nothing to do')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue