Skip to content

Instantly share code, notes, and snippets.

@harish2704
Created October 1, 2018 18:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save harish2704/54d5f68fa606419ec4777847fba9f511 to your computer and use it in GitHub Desktop.
Save harish2704/54d5f68fa606419ec4777847fba9f511 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link
Author

@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