<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>api &#8211; VeriTeknik</title>
	<atom:link href="https://www.veriteknik.net.tr/en/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.veriteknik.net.tr/en/</link>
	<description>VeriTeknik Bilişim &#124; VeriTeknik Bilişim</description>
	<lastBuildDate>Sun, 04 Mar 2012 11:12:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Using the Python API for Yum</title>
		<link>https://www.veriteknik.net.tr/en/using-the-python-api-for-yum/</link>
					<comments>https://www.veriteknik.net.tr/en/using-the-python-api-for-yum/#respond</comments>
		
		<dc:creator><![CDATA[Mustafa Emre Aydın]]></dc:creator>
		<pubDate>Sun, 04 Mar 2012 11:12:32 +0000</pubDate>
				<category><![CDATA[LINUX]]></category>
		<category><![CDATA[Programmin]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[yum]]></category>
		<guid isPermaLink="false">http://www.plugged.in/?p=220</guid>

					<description><![CDATA[<p>Here&#8217;s something very basic yet poorly documented. That&#8217;s why it looks like almost everybody&#8217;s trying to hack their way into this module, the yum module for Python. First of all don&#8217;t forget that this module is only available if you&#8217;re using a Red Hat branch of distribution (fedora, centos etc.) For other distributions, such as [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.veriteknik.net.tr/en/using-the-python-api-for-yum/">Using the Python API for Yum</a> appeared first on <a rel="nofollow" href="https://www.veriteknik.net.tr/en/">VeriTeknik</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Here&#8217;s something very basic yet poorly documented. That&#8217;s why it looks like almost everybody&#8217;s trying to hack their way into this module, the yum module for Python.</p>
<p>First of all don&#8217;t forget that this module is only available if you&#8217;re using a Red Hat branch of distribution (fedora, centos etc.) For other distributions, such as Debian, there are other api&#8217;s, such as apt itself.</p>
<p>Below you&#8217;ll find some basic ways of getting configuration settings of the current yum.</p>
<pre class="brush: python; gutter: true; first-line: 1">import yum
yb = yum.YumBase()
print yb.conf.logfile # this will obviously printout the logfile's path
for i in yb.conf.reposdir : print i # and this will printout the directories and files for the repositories
print yb.conf.skip_broken # usually false. when set to true, your yum commands will take action of is the --skip-broken parameters was given to the yum itself.
print yb.conf.errorlevel # this is the level of errors you'd like to get as an output. it's between 0-10 and 0 is only critical ones, while 10 is more like a debug feature. Usually it is set to default 2, but since you'll be running in a script, after your script gets stable, its a good idea to set this to 0 and then distribute it.
print yb.conf.config_file_path # obvious again, the file path for your yum's config file.</pre>
<p>&nbsp;</p>
<p>for more configuration options, you can always see like this;</p>
<pre class="brush: python; gutter: true; first-line: 1">dir(yb.conf)</pre>
<p>and don&#8217;t forget this perfect module, to reverse engineer some function if you don&#8217;t know what arguments it gets and if it&#8217;s poorly documented (ex: it doesn&#8217;t have a valid __doc__ attribute) :</p>
<pre class="brush: python; gutter: true; first-line: 1">import inspect
inspect.getargspec(somefunction)</pre>
<p>And about the arch method. What yum knows about our architecture.</p>
<pre class="brush: python; gutter: true; first-line: 1">import yum
yb = yum.YumBase()
print yb.arch.compatarches # these are the compatible architectures with our system.
# below are the arch types that yum thinks we are usig (hopefully true!)
print yb.arch.canonarch
print yb.arch.basearch
# With the function below, you can get a list of architectures which are compatible with each other.
# Let's say you're using an x86_64 arch, then u can use packages from these ones,
yb.arch.get_arch_list('x86_64')
['x86_64', 'athlon', 'i686', 'i586', 'i486', 'i386', 'noarch']</pre>
<p>If you&#8217;d like to get the currently installed packages on your system, rpm is the module you&#8217;d like to load.</p>
<pre class="brush: python; gutter: true; first-line: 1">import rpm
bold = "\033[1m"
reset = "\033[0;0m"
trans = rpm.TransactionSet()
for header in trans.dbMatch() : print "%s%s%s-%s:%s-%s.%s%s%s" % (bold,header['name'],reset,header['epochnum'],header['version'],header['release'],bold,header['arch'],reset)</pre>
<p>Note that this script outputs various parts in bold. You can use this in any script you&#8217;d like.</p>
<p>Yet here&#8217;s a nice method to install new packages.</p>
<pre class="brush: python; gutter: true; first-line: 1">import yum
yb=yum.YumBase()
searchlist=['name']
arg=['gedit']
matches = yb.searchGenerator(searchlist,arg)
for (package, matched_value) in matches :
    if package.name == 'gedit' : yb.install(package)
    yb.buildTransaction()
    yb.processTransaction()</pre>
<p>&nbsp;</p>
<p>Experiment, enjoy!</p>
<p>The post <a rel="nofollow" href="https://www.veriteknik.net.tr/en/using-the-python-api-for-yum/">Using the Python API for Yum</a> appeared first on <a rel="nofollow" href="https://www.veriteknik.net.tr/en/">VeriTeknik</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.veriteknik.net.tr/en/using-the-python-api-for-yum/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">220</post-id>	</item>
	</channel>
</rss>
