<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[125593] users/g5pw/pypi2port/pypi2port.py</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://trac.macports.org/changeset/125593">125593</a></dd>
<dt>Author</dt> <dd>g5pw@macports.org</dd>
<dt>Date</dt> <dd>2014-09-22 02:54:17 -0700 (Mon, 22 Sep 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Move docstrings inside functions</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#usersg5pwpypi2portpypi2portpy">users/g5pw/pypi2port/pypi2port.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="usersg5pwpypi2portpypi2portpy"></a>
<div class="modfile"><h4>Modified: users/g5pw/pypi2port/pypi2port.py (125592 => 125593)</h4>
<pre class="diff"><span>
<span class="info">--- users/g5pw/pypi2port/pypi2port.py        2014-09-22 09:54:13 UTC (rev 125592)
+++ users/g5pw/pypi2port/pypi2port.py        2014-09-22 09:54:17 UTC (rev 125593)
</span><span class="lines">@@ -29,31 +29,22 @@
</span><span class="cx"> 
</span><span class="cx"> client = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Lists all packages available in pypi database &quot;&quot;&quot;
-
-
</del><span class="cx"> def list_all():
</span><ins>+    &quot;&quot;&quot; Lists all packages available in pypi database &quot;&quot;&quot;
</ins><span class="cx">     list_packages = client.list_packages()
</span><span class="cx">     for package in list_packages:
</span><span class="cx">         print package
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Searches for a particular package by the name classifier &quot;&quot;&quot;
-
-
</del><span class="cx"> def search(pkg_name):
</span><ins>+    &quot;&quot;&quot; Searches for a particular package by the name classifier &quot;&quot;&quot;
</ins><span class="cx">     values = client.search({'name': pkg_name})
</span><span class="cx">     for value in values:
</span><span class="cx">         for key in value.keys():
</span><span class="cx">             print key, '--&gt;', value[key]
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Fetches the release data for a paticular package based on
-    the package_name and package_version &quot;&quot;&quot;
-
-
</del><span class="cx"> def release_data(pkg_name, pkg_version):
</span><ins>+    &quot;&quot;&quot; Fetches the release data for a paticular package based on
+    the package_name and package_version &quot;&quot;&quot;
</ins><span class="cx">     if pkg_version:
</span><span class="cx">         values = client.release_data(pkg_name, pkg_version)
</span><span class="cx">         if values:
</span><span class="lines">@@ -65,11 +56,8 @@
</span><span class="cx">         return
</span><span class="cx">     return
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Fetches the distfile for a particular package name and release_url &quot;&quot;&quot;
-
-
</del><span class="cx"> def fetch(pkg_name, dict):
</span><ins>+    &quot;&quot;&quot; Fetches the distfile for a particular package name and release_url &quot;&quot;&quot;
</ins><span class="cx">     print &quot;Fetching distfiles...&quot;
</span><span class="cx">     checksum_md5 = dict['md5_digest']
</span><span class="cx">     parent_dir = './sources'
</span><span class="lines">@@ -127,12 +115,9 @@
</span><span class="cx">             print &quot;Error: %s - %s.&quot; % (e.filename, e.strerror)
</span><span class="cx">         return False
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Checks for the checksums and dependecies for a particular python package
-    on the basis of package_name and package_version &quot;&quot;&quot;
-
-
</del><span class="cx"> def fetch_url(pkg_name, pkg_version, checksum=False, deps=False):
</span><ins>+    &quot;&quot;&quot; Checks for the checksums and dependecies for a particular python package
+    on the basis of package_name and package_version &quot;&quot;&quot;
</ins><span class="cx">     values = client.release_urls(pkg_name, pkg_version)
</span><span class="cx">     if checksum:
</span><span class="cx">         # print values
</span><span class="lines">@@ -143,12 +128,9 @@
</span><span class="cx">         for value in values:
</span><span class="cx">             return fetch(pkg_name, value)
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Finds dependencies for a particular package on the basis of
-    package_name and package_version &quot;&quot;&quot;
-
-
</del><span class="cx"> def dependencies(pkg_name, pkg_version, deps=False):
</span><ins>+    &quot;&quot;&quot; Finds dependencies for a particular package on the basis of
+    package_name and package_version &quot;&quot;&quot;
</ins><span class="cx">     flag = False
</span><span class="cx">     if not deps:
</span><span class="cx">         return
</span><span class="lines">@@ -193,11 +175,8 @@
</span><span class="cx">             pass
</span><span class="cx">         return False
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Creates a diff file for an existent port &quot;&quot;&quot;
-
-
</del><span class="cx"> def create_diff(old_file, new_file, diff_file):
</span><ins>+    &quot;&quot;&quot; Creates a diff file for an existent port &quot;&quot;&quot;
</ins><span class="cx">     with open(old_file) as f:
</span><span class="cx">         a = f.readlines()
</span><span class="cx"> #    a = open(old_file).readlines()
</span><span class="lines">@@ -212,11 +191,8 @@
</span><span class="cx">         except:
</span><span class="cx">             pass
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Searches for an existent port by its name &quot;&quot;&quot;
-
-
</del><span class="cx"> def search_port(name):
</span><ins>+    &quot;&quot;&quot; Searches for an existent port by its name &quot;&quot;&quot;
</ins><span class="cx">     try:
</span><span class="cx">         command = &quot;port file name:^py-&quot; + name + &quot;$&quot;
</span><span class="cx">         command = command.split()
</span><span class="lines">@@ -226,12 +202,9 @@
</span><span class="cx">     except Exception:
</span><span class="cx">         return False
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Generates checksums for a package on the basis of the distfile fetched by
-    its package_name and package_version &quot;&quot;&quot;
-
-
</del><span class="cx"> def checksums(pkg_name, pkg_version):
</span><ins>+    &quot;&quot;&quot; Generates checksums for a package on the basis of the distfile fetched by
+    its package_name and package_version &quot;&quot;&quot;
</ins><span class="cx">     flag = False
</span><span class="cx">     print &quot;Attempting to fetch distfiles...&quot;
</span><span class="cx">     file_name = fetch_url(pkg_name, pkg_version, True)
</span><span class="lines">@@ -264,11 +237,8 @@
</span><span class="cx">             print &quot;Error\n&quot;
</span><span class="cx">             return
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Searches if the distfile listed is present or not &quot;&quot;&quot;
-
-
</del><span class="cx"> def search_distfile(name, version):
</span><ins>+    &quot;&quot;&quot; Searches if the distfile listed is present or not &quot;&quot;&quot;
</ins><span class="cx">     try:
</span><span class="cx">         url = client.release_urls(name, version)[0]['url']
</span><span class="cx">         r = requests.get(url, verify=False)
</span><span class="lines">@@ -279,12 +249,9 @@
</span><span class="cx">         print &quot;Please set a DISTFILE env var before generating the portfile&quot;
</span><span class="cx">         sys.exit(0)
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Maps the license passed to the already present list of
-    licences available in Macports &quot;&quot;&quot;
-
-
</del><span class="cx"> def search_license(license):
</span><ins>+    &quot;&quot;&quot; Maps the license passed to the already present list of
+    licences available in Macports &quot;&quot;&quot;
</ins><span class="cx">     license = license.lower()
</span><span class="cx">     patterns = ['.*mit.*', '.*apache.*2', '.*apache.*', '.*bsd.*', '.*agpl.*3',
</span><span class="cx">                 '.*agpl.*2', '.*agpl.*', '.*affero.*3', '.*affero.*2',
</span><span class="lines">@@ -302,11 +269,8 @@
</span><span class="cx">         if match:
</span><span class="cx">             return licenses[i]
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Port Testing function for various phase implementations &quot;&quot;&quot;
-
-
</del><span class="cx"> def port_testing(name, portv='27'):
</span><ins>+    &quot;&quot;&quot; Port Testing function for various phase implementations &quot;&quot;&quot;
</ins><span class="cx">     euid = os.geteuid()
</span><span class="cx">     if euid:
</span><span class="cx">         args = ['sudo', sys.executable] + sys.argv + [os.environ]
</span><span class="lines">@@ -329,11 +293,8 @@
</span><span class="cx">             args = ['sudo', sys.executable] + sys.argv + [os.environ]
</span><span class="cx">             os.execlpe('sudo', *args)
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Fetch phase implementation &quot;&quot;&quot;
-
-
</del><span class="cx"> def port_fetch(name, portv='27'):
</span><ins>+    &quot;&quot;&quot; Fetch phase implementation &quot;&quot;&quot;
</ins><span class="cx">     try:
</span><span class="cx">         command = &quot;sudo port -t fetch dports/python/py-&quot; + \
</span><span class="cx">                   name + &quot; subport=py&quot; + portv + &quot;-&quot; + name
</span><span class="lines">@@ -343,11 +304,8 @@
</span><span class="cx">     except:
</span><span class="cx">         return False
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Checksum phase implementation &quot;&quot;&quot;
-
-
</del><span class="cx"> def port_checksum(name, portv='27'):
</span><ins>+    &quot;&quot;&quot; Checksum phase implementation &quot;&quot;&quot;
</ins><span class="cx">     try:
</span><span class="cx">         command = &quot;sudo port -t checksum dports/python/py-&quot; + \
</span><span class="cx">                   name + &quot; subport=py&quot; + portv + &quot;-&quot; + name
</span><span class="lines">@@ -357,11 +315,8 @@
</span><span class="cx">     except:
</span><span class="cx">         return False
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Checksum phase implementation &quot;&quot;&quot;
-
-
</del><span class="cx"> def port_extract(name, portv='27'):
</span><ins>+    &quot;&quot;&quot; Checksum phase implementation &quot;&quot;&quot;
</ins><span class="cx">     try:
</span><span class="cx">         command = &quot;sudo port -t extract dports/python/py-&quot; + \
</span><span class="cx">                   name + &quot; subport=py&quot; + portv + &quot;-&quot; + name
</span><span class="lines">@@ -371,11 +326,8 @@
</span><span class="cx">     except:
</span><span class="cx">         return False
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Patch phase implementation &quot;&quot;&quot;
-
-
</del><span class="cx"> def port_patch(name, portv='27'):
</span><ins>+    &quot;&quot;&quot; Patch phase implementation &quot;&quot;&quot;
</ins><span class="cx">     try:
</span><span class="cx">         command = &quot;sudo port -t patch dports/python/py-&quot; + \
</span><span class="cx">                   name + &quot; subport=py&quot; + portv + &quot;-&quot; + name
</span><span class="lines">@@ -385,11 +337,8 @@
</span><span class="cx">     except:
</span><span class="cx">         return False
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Configure phase implementation &quot;&quot;&quot;
-
-
</del><span class="cx"> def port_configure(name, portv='27'):
</span><ins>+    &quot;&quot;&quot; Configure phase implementation &quot;&quot;&quot;
</ins><span class="cx">     try:
</span><span class="cx">         command = &quot;sudo port -t configure dports/python/py-&quot; + \
</span><span class="cx">                   name + &quot; subport=py&quot; + portv + &quot;-&quot; + name
</span><span class="lines">@@ -399,11 +348,8 @@
</span><span class="cx">     except:
</span><span class="cx">         return False
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Build phase implementation &quot;&quot;&quot;
-
-
</del><span class="cx"> def port_build(name, portv='27'):
</span><ins>+    &quot;&quot;&quot; Build phase implementation &quot;&quot;&quot;
</ins><span class="cx">     try:
</span><span class="cx">         command = &quot;sudo port -t build dports/python/py-&quot; + \
</span><span class="cx">                   name + &quot; subport=py&quot; + portv + &quot;-&quot; + name
</span><span class="lines">@@ -413,11 +359,8 @@
</span><span class="cx">     except:
</span><span class="cx">         return False
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Destroot phase implementation &quot;&quot;&quot;
-
-
</del><span class="cx"> def port_destroot(name, portv='27'):
</span><ins>+    &quot;&quot;&quot; Destroot phase implementation &quot;&quot;&quot;
</ins><span class="cx">     try:
</span><span class="cx">         command = &quot;sudo port -t destroot dports/python/py-&quot; + \
</span><span class="cx">                   name + &quot; subport=py&quot; + portv + &quot;-&quot; + name
</span><span class="lines">@@ -427,11 +370,8 @@
</span><span class="cx">     except:
</span><span class="cx">         return False
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Clean phase implementation &quot;&quot;&quot;
-
-
</del><span class="cx"> def port_clean(name, portv='27'):
</span><ins>+    &quot;&quot;&quot; Clean phase implementation &quot;&quot;&quot;
</ins><span class="cx">     try:
</span><span class="cx">         command = &quot;sudo port -t clean dports/python/py-&quot; + \
</span><span class="cx">                   name + &quot; subport=py&quot; + portv + &quot;-&quot; + name
</span><span class="lines">@@ -441,12 +381,9 @@
</span><span class="cx">     except:
</span><span class="cx">         return False
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Creates a portfile on the basis of the release_data and release_url fetched
-    on the basis of package_name and package_version &quot;&quot;&quot;
-
-
</del><span class="cx"> def create_portfile(dict, file_name, dict2):
</span><ins>+    &quot;&quot;&quot; Creates a portfile on the basis of the release_data and release_url fetched
+    on the basis of package_name and package_version &quot;&quot;&quot;
</ins><span class="cx">     search_distfile(dict['name'], dict['version'])
</span><span class="cx">     print &quot;Creating Portfile for pypi package &quot; + dict['name'] + &quot;...&quot;
</span><span class="cx">     with open(file_name, 'w') as file:
</span><span class="lines">@@ -654,12 +591,9 @@
</span><span class="cx">     else:
</span><span class="cx">         print &quot;No port found.&quot;
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Creates the directories and other commands necessary
-    for a development environment &quot;&quot;&quot;
-
-
</del><span class="cx"> def print_portfile(pkg_name, pkg_version=None):
</span><ins>+    &quot;&quot;&quot; Creates the directories and other commands necessary
+    for a development environment &quot;&quot;&quot;
</ins><span class="cx">     root_dir = os.path.abspath(&quot;./dports&quot;)
</span><span class="cx">     port_dir = os.path.join(root_dir, 'python')
</span><span class="cx">     home_dir = os.path.join(port_dir, 'py-'+pkg_name)
</span><span class="lines">@@ -693,11 +627,8 @@
</span><span class="cx">     create_portfile(dict, file_name, dict2)
</span><span class="cx">     print &quot;SUCCESS\n&quot;
</span><span class="cx"> 
</span><del>-
-&quot;&quot;&quot; Main function - Argument Parser &quot;&quot;&quot;
-
-
</del><span class="cx"> def main(argv):
</span><ins>+    &quot;&quot;&quot; Main function - Argument Parser &quot;&quot;&quot;
</ins><span class="cx">     parser = argparse.ArgumentParser(description=&quot;Pypi2Port Tester&quot;)
</span><span class="cx"> # Calls list_all() which lists al available python packages
</span><span class="cx">     parser.add_argument('-l', '--list', action='store_true', dest='list',
</span></span></pre>
</div>
</div>

</body>
</html>