summaryrefslogtreecommitdiffstats
path: root/cnucnu/helper.py
diff options
context:
space:
mode:
authorTill Maas <opensource@till.name>2009-07-19 17:08:24 +0200
committerTill Maas <opensource@till.name>2009-07-19 17:08:24 +0200
commitce1383726feefa1e0f8aa53b4803f36733726611 (patch)
treef1c675b5d3bf6441b136f6dc74e695c36880332c /cnucnu/helper.py
parentc6c86d92cc56628a86d566a838940a7c062252b0 (diff)
downloadcnucnu-ce1383726feefa1e0f8aa53b4803f36733726611.tar.gz
cnucnu-ce1383726feefa1e0f8aa53b4803f36733726611.tar.xz
cnucnu-ce1383726feefa1e0f8aa53b4803f36733726611.zip
remove dir lib for saner imports(?)
Diffstat (limited to 'cnucnu/helper.py')
-rw-r--r--cnucnu/helper.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/cnucnu/helper.py b/cnucnu/helper.py
new file mode 100644
index 0000000..f2d61de
--- /dev/null
+++ b/cnucnu/helper.py
@@ -0,0 +1,72 @@
+#!/usr/bin/python
+# vim: fileencoding=utf8 foldmethod=marker
+#{{{ License header: GPLv2+
+# This file is part of cnucnu.
+#
+# Cnucnu is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# Cnucnu is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cnucnu. If not, see <http://www.gnu.org/licenses/>.
+#}}}
+
+import pprint as pprint_module
+pp = pprint_module.PrettyPrinter(indent=4)
+pprint = pp.pprint
+
+def get_html(url):
+ import urllib
+ res = urllib.urlopen(url)
+ return res.read()
+
+def rpm_cmp(v1, v2):
+ import rpm
+ return rpm.labelCompare((None, v1, None), (None, v2, None))
+
+def rpm_max(list):
+ list.sort(cmp=rpm_cmp)
+ return list[-1]
+
+""" return a dict that only contains keys that are in key_list
+"""
+def filter_dict(d, key_list):
+ return dict([v for v in d.items() if v[0] in key_list])
+
+def secure_download(url, cainfo=""):
+ import pycurl
+ import StringIO
+
+ c = pycurl.Curl()
+ c.setopt(pycurl.URL, url.encode("ascii"))
+
+ # -k / --insecure
+ # c.setopt(pycurl.SSL_VERIFYPEER, 0)
+
+ # Verify certificate
+ c.setopt(pycurl.SSL_VERIFYPEER, 1)
+
+ # Verify CommonName or Subject Alternate Name
+ c.setopt(pycurl.SSL_VERIFYHOST, 2)
+
+ # --cacert
+ if cainfo:
+ c.setopt(pycurl.CAINFO, cainfo)
+
+ res = StringIO.StringIO()
+
+ c.setopt(pycurl.WRITEFUNCTION, res.write)
+
+ c.perform()
+ c.close()
+ data = res.getvalue()
+ res.close()
+
+ return data
+