Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
parallel downloads while doing zypper distribution upgrade
#!/usr/bin/env python2
"""
This script will print package urls which need to be downloaded for 'distrubution upgrade'
Printed urls can be used for downloading packages in parallel.
For eg: we can use GNU parallel commanline tool along with wget/curl for parallel downloading
python2 zypper_dup_print_urls.py | parallel --tmuxpane -j4 --colsep ' ' mkdir -p '{1}/{2}' \; cd '{1}/{2}' \; wget -c {3}
will download packages with 4 simultaneous downloads
"""
import os
import zypp
def initRepos():
repoManager = zypp.RepoManager()
repos = repoManager.knownRepositories()
for repo in repos:
if not repo.enabled():
continue
if not repoManager.isCached( repo ):
repoManager.buildCache( repo )
repoManager.loadFromCache( repo );
def initZypp():
Z = zypp.ZYppFactory_instance().getZYpp()
Z.initializeTarget( zypp.Pathname("/") )
Z.target().load();
initRepos()
return Z
def tryDUP( res ):
hasProblems = res.doUpgrade()
if( hasProblems ):
return;
prs = res.problems()
probSols = zypp.ProblemSolutionList()
for i in prs:
# Just choose first solution
probSols.push_back( i.solutions()[0] )
res.applySolutions( probSols )
tryDUP( res )
Z = initZypp()
tryDUP( Z.resolver() )
todo = zypp.GetResolvablesToInsDel( Z.pool() )
urlList = []
for item in todo._toInstall:
repoUrl = item.repoInfo().baseUrls()[0].asCompleteString()
if( 'CHECK_BUG' in os.environ ):
itemUrl = str( item.lookupLocation().filename() )
else:
r=item.lookupLocation(); itemUrl = str( r.filename() )
url = repoUrl + itemUrl
urlList.append( url )
arch = '---'
if zypp.Arch.x86_64() == item.arch():
arch = 'x86_64'
elif zypp.Arch.noarch() == item.arch():
arch = 'noarch'
elif zypp.Arch.i386() == item.arch():
arch = 'i386'
print item.repoInfo().alias(), arch, url
@jpluimers

This comment has been minimized.

Copy link

jpluimers commented Oct 17, 2018

Two questions:

  • what do I need to have installed to be able to do import zypp?
  • where should I download this to so that zypper can use it in the next run?
@harish2704

This comment has been minimized.

Copy link
Owner Author

harish2704 commented Mar 7, 2019

@jpluimers

  • what do I need to have installed to be able to do import zypp?

Python ( and many other language bindings ) for zypper comes under this project. https://github.com/openSUSE/libzypp-bindings. You need to

  • build that project yourself
  • set PYTHONPATH properly so that import zypp will work.
  • where should I download this to so that zypper can use it in the next run?

Zypper can not use this script. This script is using zypper ( to be exact, the libzypp library. not the zypper cli tool )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.