Skip to content

Commit cc99c88

Browse files
committed
Improve handling of package conflicts
1 parent 7a0c3cf commit cc99c88

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

zypperoni

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ from shlex import quote
2828
import xml.etree.ElementTree as ET
2929

3030
# Constants
31-
ZYPPERONI_VERSION = "0.3.2"
31+
ZYPPERONI_VERSION = "0.3.3"
3232
ZYPPER_PID_FILE = "/run/zypp.pid"
3333
VALID_CMD = ["ref", "force-ref", "in", "in-download", "dup", "dup-download", "inr", "inr-download"]
3434
VALID_OPT = ["--debug", "--help", "--version", "--no-confirm", "--max-jobs"]
@@ -336,15 +336,15 @@ async def main_task(num_jobs, task_type, task_items, no_confirm=None):
336336
msg = "Zypperoni has finished its tasks. Handing you over to zypper..."
337337
if task_type == "dup":
338338
logging.info(msg)
339-
command = f"env ZYPP_SINGLE_RPMTRANS=1 zypper {'--non-interactive' if no_confirm else ''} dist-upgrade"
339+
command = f"env ZYPP_SINGLE_RPMTRANS=1 zypper {'--non-interactive' if no_confirm else ''} --no-cd dist-upgrade"
340340
os.system(command)
341341
elif task_type == "in":
342342
logging.info(msg)
343-
command = f"env ZYPP_SINGLE_RPMTRANS=1 zypper {'--non-interactive' if no_confirm else ''} install {' '.join(install_pkgs)}"
343+
command = f"env ZYPP_SINGLE_RPMTRANS=1 zypper {'--non-interactive' if no_confirm else ''} --no-cd install {' '.join(install_pkgs)}"
344344
os.system(command)
345345
elif task_type == "inr":
346346
logging.info(msg)
347-
command = f"env ZYPP_SINGLE_RPMTRANS=1 zypper {'--non-interactive' if no_confirm else ''} install-new-recommends"
347+
command = f"env ZYPP_SINGLE_RPMTRANS=1 zypper {'--non-interactive' if no_confirm else ''} --no-cd install-new-recommends"
348348
os.system(command)
349349

350350
################################
@@ -464,7 +464,8 @@ if COMMAND in ["ref", "force-ref"]:
464464
# get all enabled repos
465465
logging.info("Getting all enabled repos")
466466
REPO_ALIAS = []
467-
xml_output = shell_exec("env -i zypper --non-interactive --xmlout repos")
467+
xml_output = shell_exec("env -i zypper --non-interactive --no-cd --xmlout repos")
468+
logging.debug(xml_output)
468469
get_zypp_lock()
469470
docroot = ET.fromstring(xml_output)
470471
for item in docroot.iter("repo"):
@@ -486,7 +487,8 @@ if COMMAND in ["ref", "force-ref"]:
486487
elif COMMAND in ["dup", "dup-download"]:
487488
# get info about dup packages
488489
logging.info("Getting all packages to be downloaded for distribution upgrade")
489-
xml_output = shell_exec("env -i zypper --non-interactive --xmlout dist-upgrade --dry-run")
490+
xml_output = shell_exec("env -i zypper --non-interactive --no-cd --xmlout dist-upgrade --dry-run")
491+
logging.debug(xml_output)
490492
get_zypp_lock()
491493
docroot = ET.fromstring(xml_output)
492494
for item in docroot.iter('install-summary'):
@@ -497,6 +499,10 @@ elif COMMAND in ["dup", "dup-download"]:
497499
logging.info(f"Total download size: {download_size_bytes/1000**2:.2f} MB")
498500
if COMMAND == "dup":
499501
logging.info(f"Space usage difference after operation: {diff_bytes/1000**2:+.2f} MB")
502+
if not num_pkgs:
503+
if xml_output.find("conflicts") != -1 or xml_output.find("nothing provides") != -1:
504+
logging.warning("There are package conflicts that must be manually resolved. See output of:\n" \
505+
"zypper --non-interactive --no-cd dist-upgrade --dry-run")
500506
# parse all packages from xml output
501507
DUP_PKG = []
502508
for item in docroot.iter("solvable"):
@@ -523,7 +529,7 @@ elif COMMAND in ["dup", "dup-download"]:
523529
if COMMAND == "dup" and download_size_bytes == 0:
524530
zypperoni_cleanup()
525531
logging.info("Zypperoni has finished its tasks. Handing you over to zypper...")
526-
command = f"env ZYPP_SINGLE_RPMTRANS=1 zypper {'--non-interactive' if NO_CONFIRM else ''} dist-upgrade"
532+
command = f"env ZYPP_SINGLE_RPMTRANS=1 zypper {'--non-interactive' if NO_CONFIRM else ''} --no-cd dist-upgrade"
527533
os.system(command)
528534
sys.exit()
529535
logging.info(f"Packages to download: {' '.join(DUP_PKG)}")
@@ -541,7 +547,8 @@ elif COMMAND in ["dup", "dup-download"]:
541547
elif COMMAND in ["in", "in-download"]:
542548
# get info about install packages
543549
logging.info("Getting packages and its dependecies to be downloaded for installation")
544-
xml_output = shell_exec(f"env -i zypper --non-interactive --xmlout install --dry-run {' '.join(ARG)}")
550+
xml_output = shell_exec(f"env -i zypper --non-interactive --no-cd --xmlout install --dry-run {' '.join(ARG)}")
551+
logging.debug(xml_output)
545552
get_zypp_lock()
546553
docroot = ET.fromstring(xml_output)
547554
NO_ERR = False
@@ -553,6 +560,10 @@ elif COMMAND in ["in", "in-download"]:
553560
logging.info(f"Total download size: {download_size_bytes/1000**2:.2f} MB")
554561
logging.info(f"Space usage difference after operation: {diff_bytes/1000**2:+.2f} MB")
555562
NO_ERR = True
563+
if not num_pkgs:
564+
if xml_output.find("conflicts") != -1 or xml_output.find("nothing provides") != -1:
565+
logging.warning("There are package conflicts that must be manually resolved. See output of:\n" \
566+
"zypper --non-interactive --no-cd dist-upgrade --dry-run")
556567
if not NO_ERR:
557568
friendly_output = ""
558569
for item in docroot.iter("message"):
@@ -586,7 +597,7 @@ elif COMMAND in ["in", "in-download"]:
586597
if COMMAND == "in" and download_size_bytes == 0:
587598
zypperoni_cleanup()
588599
logging.info("Zypperoni has finished its tasks. Handing you over to zypper...")
589-
command = f"env ZYPP_SINGLE_RPMTRANS=1 zypper {'--non-interactive' if NO_CONFIRM else ''} install {' '.join(ARG)}"
600+
command = f"env ZYPP_SINGLE_RPMTRANS=1 zypper {'--non-interactive' if NO_CONFIRM else ''} --no-cd install {' '.join(ARG)}"
590601
os.system(command)
591602
sys.exit()
592603
logging.info(f"Packages to download: {' '.join(IN_PKG)}")
@@ -604,7 +615,8 @@ elif COMMAND in ["in", "in-download"]:
604615
elif COMMAND in ["inr", "inr-download"]:
605616
# get info about recommended install packages
606617
logging.info("Getting new packages and its dependecies to be downloaded for recommended installation")
607-
xml_output = shell_exec(f"env -i zypper --non-interactive --xmlout install-new-recommends --dry-run")
618+
xml_output = shell_exec(f"env -i zypper --non-interactive --no-cd --xmlout install-new-recommends --dry-run")
619+
logging.debug(xml_output)
608620
get_zypp_lock()
609621
docroot = ET.fromstring(xml_output)
610622
for item in docroot.iter('install-summary'):
@@ -614,6 +626,10 @@ elif COMMAND in ["inr", "inr-download"]:
614626
logging.info(f"Number of packages to download: {num_pkgs}")
615627
logging.info(f"Total download size: {download_size_bytes/1000**2:.2f} MB")
616628
logging.info(f"Space usage difference after operation: {diff_bytes/1000**2:+.2f} MB")
629+
if not num_pkgs:
630+
if xml_output.find("conflicts") != -1 or xml_output.find("nothing provides") != -1:
631+
logging.warning("There are package conflicts that must be manually resolved. See output of:\n" \
632+
"zypper --non-interactive --no-cd dist-upgrade --dry-run")
617633
# parse all packages from xml output
618634
INR_PKG = []
619635
for item in docroot.iter("solvable"):
@@ -640,7 +656,7 @@ elif COMMAND in ["inr", "inr-download"]:
640656
if COMMAND == "inr" and download_size_bytes == 0:
641657
zypperoni_cleanup()
642658
logging.info("Zypperoni has finished its tasks. Handing you over to zypper...")
643-
command = f"env ZYPP_SINGLE_RPMTRANS=1 zypper {'--non-interactive' if NO_CONFIRM else ''} install-new-recommends"
659+
command = f"env ZYPP_SINGLE_RPMTRANS=1 zypper {'--non-interactive' if NO_CONFIRM else ''} --no-cd install-new-recommends"
644660
os.system(command)
645661
sys.exit()
646662
logging.info(f"Packages to download: {' '.join(INR_PKG)}")

0 commit comments

Comments
 (0)