<!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>[130752] users/gaurav/pypi2port/pypi2port</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/130752">130752</a></dd>
<dt>Author</dt> <dd>gaurav@macports.org</dd>
<dt>Date</dt> <dd>2015-01-02 04:06:59 -0800 (Fri, 02 Jan 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Updated executable</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#usersgauravpypi2portpypi2port">users/gaurav/pypi2port/pypi2port</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="usersgauravpypi2portpypi2port"></a>
<div class="modfile"><h4>Modified: users/gaurav/pypi2port/pypi2port (130751 => 130752)</h4>
<pre class="diff"><span>
<span class="info">--- users/gaurav/pypi2port/pypi2port        2015-01-02 12:03:33 UTC (rev 130751)
+++ users/gaurav/pypi2port/pypi2port        2015-01-02 12:06:59 UTC (rev 130752)
</span><span class="lines">@@ -7,728 +7,748 @@
</span><span class="cx"> import hashlib
</span><span class="cx"> import zipfile
</span><span class="cx"> import progressbar as pb
</span><ins>+# progressbar3000 for python3
+import requests
</ins><span class="cx"> try:
</span><del>- import xmlrpclib
- from urllib2 import urlopen
</del><ins>+        import xmlrpclib
</ins><span class="cx"> except ImportError:
</span><del>- import xmlrpc.client as xmlrpclib
- from urllib.request import urlopen
</del><ins>+        import xmlrpc.client as xmlrpclib
</ins><span class="cx"> import textwrap
</span><span class="cx"> import string
</span><span class="cx"> import shutil
</span><span class="cx"> import re
</span><span class="cx"> import difflib
</span><span class="cx"> import subprocess
</span><del>-import requests
</del><span class="cx">
</span><ins>+
</ins><span class="cx"> client = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def list_all():
</span><del>- """ Lists all packages available in pypi database """
- list_packages = client.list_packages()
- for package in list_packages:
- print(package)
</del><ins>+        """ Lists all packages available in pypi database """
+        list_packages = client.list_packages()
+        for package in list_packages:
+                print(package)
</ins><span class="cx">
</span><span class="cx">
</span><ins>+class Package_Search:
+        def __init__(self, name, summary, version):
+                self.name = name
+                self.version = version
+                self.summary = ""
+                for i in range(0, len(summary), 62):
+                        self.summary += summary[i:62+i] + '\n\t\t'
+
+        def __str__(self):
+                return "Name\t\t" + self.name + "\nVersion\t\t" + self.version + "\nSummary\t\t" + self.summary + "\n"
+                
+
</ins><span class="cx"> def search(pkg_name):
</span><del>- """ Searches for a particular package by the name classifier """
- values = client.search({'name': pkg_name})
- for value in values:
- for key in value.keys():
- print key, '-->', value[key]
</del><ins>+        """ Searches for a particular package by the name classifier """
+        values = client.search({'name': pkg_name})
+        for value in values:
+                package = Package_Search(value['name'], value['summary'], value['version'])
+                print(package)
</ins><span class="cx">
</span><ins>+class Package_release_data:
+        def __init__(self, attributes):
+                # self.name = name
+                # self.version = version
+                # self.home_page = attributes['home_page']
+                # self.license = attributes['license']
+                # self.summary = attributes['summary']
+                # self.maintainer = attributes['maintainer']
+                # self.docs_url = attributes['docs_url']
+                # self.requires_python = attributes['requires_python']
+                # self.maintainer_email = attributes['maintainer_email']
+                # self.cheesecake_code_kwalitee_id = attributes['cheesecake_code_kwalitee_id']
+                # self.keywords = attributes['keywords']
+                # self.package_url = attributes['package_url']
+                # self.author = attributes['author']
+                # self.author_email = attributes['author_email']
+                # self.download_url = attributes['download_url']
+                # self.platform = attributes['platform']
+                # self.cheesecake_documentation_id = attributes['cheesecake_documentation_id']
+                # self._pypi_hidden = attributes['_pypi_hidden']
+                # self.description = attributes['description']
+                # self.release_url = attributes['release_url']
+                # self.downloads = attributes['downloads']
+                # self._pypi_ordering = attributes['_pypi_ordering']
+                # self.classifiers = attributes['classifiers']
+                # self.bugtrack_url = attributes['bugtrack_url']
+                # self.stable_version = attributes['stable_version']
+                # self.cheesecake_installability_id = attributes['cheesecake_installability_id']
</ins><span class="cx">
</span><ins>+                variables = attributes.keys()
+                for v in variables:
+                        setattr(self, v, attributes[v])
+
+        def __str__(self):
+                output = "Name\t\t" + self.name + "\nVersion\t\t" + self.version
+                if self.maintainer and self.maintainer != 'UNKNOWN':
+                        output += "\nMaintainter\t" + self.maintainer
+                output += "\nHome_page\t" + self.home_page
+                output += "\nPackage_url\t" + self.package_url
+                if self.download_url and self.download_url != 'UNKNOWN':
+                        output += "\nDownload_url\t" + self.download_url
+                output += "\nRelease_url\t" + self.release_url
+                if self.docs_url and self.docs_url != 'UNKNOWN':
+                        output += "\nDocs_url\t" + self.docs_url
+                output += "\nDescription\t" + self.description
+                return output
+
</ins><span class="cx"> def release_data(pkg_name, pkg_version):
</span><del>- """ Fetches the release data for a paticular package based on
- the package_name and package_version """
- if pkg_version:
- values = client.release_data(pkg_name, pkg_version)
- if values:
- for key in values.keys():
- print key, '-->', values[key]
- else:
- print("No such package found.")
- print("Please specify the exact package name.")
- return
- return
</del><ins>+        """ Fetches the release data for a paticular package based on
+        the package_name and package_version """
+        # if pkg_version:
+        values = client.release_data(pkg_name, pkg_version)
+        if values:
+                package = Package_release_data(values)
+                print(package)
+        else:
+                print("No such package found.")
+                print("Please specify the exact package name.")
+        return
+        # return
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def fetch(pkg_name, dict):
</span><del>- """ Fetches the distfile for a particular package name and release_url """
- print("Fetching distfiles...")
- checksum_md5 = dict['md5_digest']
- parent_dir = './sources'
- home_dir = parent_dir + '/' + 'python'
- src_dir = home_dir + '/py-' + pkg_name
- if not os.path.exists(parent_dir):
- os.makedirs(parent_dir)
- if not os.path.exists(home_dir):
- os.makedirs(home_dir)
- if not os.path.exists(src_dir):
- os.makedirs(src_dir)
</del><ins>+        """ Fetches the distfile for a particular package name and release_url """
+        print("Fetching distfiles...")
+        checksum_md5 = dict['md5_digest']
+        parent_dir = './sources'
+        home_dir = parent_dir + '/' + 'python'
+        src_dir = home_dir + '/py-' + pkg_name
+        if not os.path.exists(parent_dir):
+                os.makedirs(parent_dir)
+        if not os.path.exists(home_dir):
+                os.makedirs(home_dir)
+        if not os.path.exists(src_dir):
+                os.makedirs(src_dir)
</ins><span class="cx">
</span><del>- url = dict['url']
- file_name = src_dir + '/' + dict['filename']
</del><ins>+        url = dict['url']
+        file_name = src_dir + '/' + dict['filename']
</ins><span class="cx">
</span><del>- u = urlopen(url)
- with open(file_name, 'wb') as f:
- meta = u.info()
- file_size = int(meta.getheaders("Content-Length")[0])
</del><ins>+        r = requests.get(url)
+        if r.status_code == 200        :
+                with open(file_name, 'wb') as f:
+                        meta = r.headers['content-length']
+                        file_size = int(meta)
</ins><span class="cx">
</span><del>- widgets = ['Fetching: ', pb.Percentage(), ' ',
- pb.Bar(marker=pb.RotatingMarker(), left='[', right=']'),
- ' ', pb.ETA(), ' ', pb.FileTransferSpeed()]
- pbar = pb.ProgressBar(widgets=widgets, maxval=int(file_size))
- pbar.start()
</del><ins>+                        widgets = ['Fetching: ', pb.Percentage(), ' ',
+                                         pb.Bar(marker=pb.RotatingMarker(), left='[', right=']'),
+                                         ' ', pb.ETA(), ' ', pb.FileTransferSpeed()]
+                        pbar = pb.ProgressBar(widgets=widgets, maxval=int(file_size))
+                        pbar.start()
</ins><span class="cx">
</span><del>- file_size_dl = 0
- block_sz = 1024
- while True:
- buffer = u.read(block_sz)
- if not buffer:
- break
</del><ins>+                        file_size_dl = 0
+                        block_sz = 1024
</ins><span class="cx">
</span><del>- file_size_dl += len(buffer)
- f.write(buffer)
- pbar.update(file_size_dl)
</del><ins>+                        for chunk in r.iter_content(block_sz):
+                                if file_size_dl+block_sz > file_size:
+                                        file_size_dl = file_size
+                                else:
+                                        file_size_dl += block_sz
+                                f.write(chunk)
+                                pbar.update(file_size_dl)
</ins><span class="cx">
</span><del>- pbar.finish()
</del><ins>+                        pbar.finish()
</ins><span class="cx">
</span><del>- checksum_md5_calc = hashlib.md5(open(file_name).read()).hexdigest()
- if str(checksum_md5) == str(checksum_md5_calc):
- print('Successfully fetched')
- ext = file_name.split('.')[-1]
- if ext == 'egg':
- zip = zipfile.ZipFile(file_name)
- for name in zip.namelist():
- if name.split("/")[0] == "EGG-INFO":
- zip.extract(name, src_dir)
- return file_name
- else:
- print('Aborting due to inconsistency on checksums\n')
- try:
- os.remove(file_name)
- except OSError as e:
- print("Error: %s - %s." % (e.filename, e.strerror))
- return False
</del><ins>+        checksum_md5_calc = hashlib.md5(open(file_name).read()).hexdigest()
+        if str(checksum_md5) == str(checksum_md5_calc):
+                print('Successfully fetched')
+                ext = file_name.split('.')[-1]
+                if ext == 'egg':
+                        zip = zipfile.ZipFile(file_name)
+                        for name in zip.namelist():
+                                if name.split("/")[0] == "EGG-INFO":
+                                        zip.extract(name, src_dir)
+                return file_name
+        else:
+                print('Aborting due to inconsistency on checksums\n')
+                try:
+                        os.remove(file_name)
+                except OSError as e:
+                        print("Error: %s - %s." % (e.filename, e.strerror))
+                return False
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def fetch_url(pkg_name, pkg_version, checksum=False, deps=False):
</span><del>- """ Checks for the checksums and dependecies for a particular python package
- on the basis of package_name and package_version """
- values = client.release_urls(pkg_name, pkg_version)
- if checksum:
- # print values
- for value in values:
- if value['filename'].split('.')[-1] in ('gz', 'zip'):
- return fetch(pkg_name, value)
- else:
- for value in values:
- return fetch(pkg_name, value)
</del><ins>+        """ Checks for the checksums and dependecies for a particular python package
+        on the basis of package_name and package_version """
+        values = client.release_urls(pkg_name, pkg_version)
+        if checksum:
+                for value in values:
+                        if value['filename'].split('.')[-1] in ('gz', 'zip'):
+                                return fetch(pkg_name, value)
+        else:
+                for value in values:
+                        return fetch(pkg_name, value)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def dependencies(pkg_name, pkg_version, deps=False):
</span><del>- """ Finds dependencies for a particular package on the basis of
- package_name and package_version """
- flag = False
- if not deps:
- return
- values = client.release_urls(pkg_name, pkg_version)
- for value in values:
- if value['filename'].split('.')[-1] in ('gz', 'zip'):
- fetch(pkg_name, value)
- try:
- with open('./sources/python/py-'
- + pkg_name + '/EGG-INFO/requires.txt') as f:
- list = f.readlines()
- list = [x.strip('\n') for x in list]
- f.close()
- try:
- if flag:
- shutil.rmtree('./sources/python/py-' + pkg_name + '/EGG-INFO',
- ignore_errors=True)
- items = os.listdir('./sources/python/py-' + pkg_name)
- for item in items[:]:
- if item.split('.')[-1] not in ('gz', 'zip'):
- os.remove('./sources/python/py-'
- + pkg_name + '/' + item)
- items.remove(item)
- if not items:
- os.rmdir('./sources/python/py-' + pkg_name)
- except:
- pass
- return list
- except:
- try:
- if flag:
- shutil.rmtree('./sources/python/py-'+pkg_name+'/EGG-INFO',
- ignore_errors=True)
- items = os.listdir('./sources/python/py-'+pkg_name)
- for item in items[:]:
- if item.split('.')[-1] not in ('gz', 'zip'):
- os.remove('./sources/python/py-'+pkg_name+'/'+item)
- items.remove(item)
- if not items:
- os.rmdir('./sources/python/py-'+pkg_name)
- except:
- pass
- return False
</del><ins>+        """ Finds dependencies for a particular package on the basis of
+        package_name and package_version """
+        flag = False
+        if not deps:
+                return
+        values = client.release_urls(pkg_name, pkg_version)
+        for value in values:
+                if value['filename'].split('.')[-1] in ('gz', 'zip'):
+                        fetch(pkg_name, value)
+        try:
+                with open('./sources/python/py-'
+                                 + pkg_name + '/EGG-INFO/requires.txt') as f:
+                        list = f.readlines()
+                        list = [x.strip('\n') for x in list]
+                f.close()
+                try:
+                        if flag:
+                                shutil.rmtree('./sources/python/py-' + pkg_name + '/EGG-INFO',
+                                                         ignore_errors=True)
+                                items = os.listdir('./sources/python/py-' + pkg_name)
+                                for item in items[:]:
+                                        if item.split('.')[-1] not in ('gz', 'zip'):
+                                                os.remove('./sources/python/py-'
+                                                                 + pkg_name + '/' + item)
+                                                items.remove(item)
+                                if not items:
+                                        os.rmdir('./sources/python/py-' + pkg_name)
+                except:
+                        pass
+                return list
+        except:
+                try:
+                        if flag:
+                                shutil.rmtree('./sources/python/py-'+pkg_name+'/EGG-INFO',
+                                                         ignore_errors=True)
+                                items = os.listdir('./sources/python/py-'+pkg_name)
+                                for item in items[:]:
+                                        if item.split('.')[-1] not in ('gz', 'zip'):
+                                                os.remove('./sources/python/py-'+pkg_name+'/'+item)
+                                                items.remove(item)
+                                if not items:
+                                        os.rmdir('./sources/python/py-'+pkg_name)
+                except:
+                        pass
+                return False
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def create_diff(old_file, new_file, diff_file):
</span><del>- """ Creates a diff file for an existent port """
- with open(old_file) as f:
- a = f.readlines()
</del><ins>+        """ Creates a diff file for an existent port """
+        with open(old_file) as f:
+                a = f.readlines()
</ins><span class="cx"> # a = open(old_file).readlines()
</span><del>- with open(new_file) as f:
- b = f.readlines()
</del><ins>+        with open(new_file) as f:
+                b = f.readlines()
</ins><span class="cx"> # b = open(new_file).readlines()
</span><del>- diff_string = difflib.unified_diff(a, b, "Portfile.orig", "Portfile")
- with open(diff_file, 'w') as d:
- d.writelines(diff_string)
</del><ins>+        diff_string = difflib.unified_diff(a, b, "Portfile.orig", "Portfile")
+        with open(diff_file, 'w') as d:
+                d.writelines(diff_string)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def search_port(name):
</span><del>- """ Searches for an existent port by its name """
- try:
- command = "port file name:^py-" + name + "$"
- command = command.split()
- existing_portfile = \
- subprocess.check_output(command, stderr=subprocess.STDOUT).strip()
- return existing_portfile
- except Exception:
- return False
</del><ins>+        """ Searches for an existent port by its name """
+        try:
+                command = "port file name:^py-" + name + "$"
+                command = command.split()
+                existing_portfile = \
+                        subprocess.check_output(command, stderr=subprocess.STDOUT).strip()
+                return existing_portfile
+        except Exception:
+                return False
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def checksums(pkg_name, pkg_version):
</span><del>- """ Generates checksums for a package on the basis of the distfile fetched by
- its package_name and package_version """
- flag = False
- print("Attempting to fetch distfiles...")
- file_name = fetch_url(pkg_name, pkg_version, True)
- if file_name:
- checksums = []
- try:
- print("Generating checksums...")
- command = "openssl rmd160 "+file_name
- command = command.split()
- rmd160 = subprocess.check_output(command, stderr=subprocess.STDOUT)
- rmd160 = rmd160.split('=')[1].strip()
- checksums.insert(0, rmd160)
</del><ins>+        """ Generates checksums for a package on the basis of the distfile fetched by
+        its package_name and package_version """
+        flag = False
+        print("Attempting to fetch distfiles...")
+        file_name = fetch_url(pkg_name, pkg_version, True)
+        if file_name:
+                checksums = []
+                try:
+                        print("Generating checksums...")
+                        command = "openssl rmd160 "+file_name
+                        command = command.split()
+                        rmd160 = subprocess.check_output(command, stderr=subprocess.STDOUT)
+                        rmd160 = rmd160.split('=')[1].strip()
+                        checksums.insert(0, rmd160)
</ins><span class="cx">
</span><del>- command = "openssl sha256 "+file_name
- command = command.split()
- sha256 = subprocess.check_output(command, stderr=subprocess.STDOUT)
- sha256 = sha256.split('=')[1].strip()
- checksums.insert(1, sha256)
</del><ins>+                        command = "openssl sha256 "+file_name
+                        command = command.split()
+                        sha256 = subprocess.check_output(command, stderr=subprocess.STDOUT)
+                        sha256 = sha256.split('=')[1].strip()
+                        checksums.insert(1, sha256)
</ins><span class="cx">
</span><del>- dir = '/'.join(file_name.split('/')[0:-1])
- if flag:
- os.remove(file_name)
- try:
- if flag:
- os.rmdir(dir)
- except OSError:
- pass
- return checksums
- except:
- print("Error\n")
- return
</del><ins>+                        dir = '/'.join(file_name.split('/')[0:-1])
+                        if flag:
+                                os.remove(file_name)
+                        try:
+                                if flag:
+                                        os.rmdir(dir)
+                        except OSError:
+                                pass
+                        return checksums
+                except:
+                        print("Error\n")
+                        return
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def search_distfile(name, version):
</span><del>- """ Searches if the distfile listed is present or not """
- try:
- url = client.release_urls(name, version)[0]['url']
- r = requests.get(url, verify=False)
- if not r.status_code == 200:
- raise Exception('No distfile')
- except:
- print("No distfile found")
- print("Please set a DISTFILE env var before generating the portfile")
- sys.exit(0)
</del><ins>+        """ Searches if the distfile listed is present or not """
+        try:
+                url = client.release_urls(name, version)[0]['url']
+                r = requests.get(url, verify=False)
+                if not r.status_code == 200:
+                        raise Exception('No distfile')
+        except:
+                print("No distfile found")
+                print("Please set a DISTFILE env var before generating the portfile")
+                sys.exit(0)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def search_license(license):
</span><del>- """ Maps the license passed to the already present list of
- licences available in Macports """
- license = license.lower()
- patterns = ['.*mit.*', '.*apache.*2', '.*apache.*', '.*bsd.*', '.*agpl.*3',
- '.*agpl.*2', '.*agpl.*', '.*affero.*3', '.*affero.*2',
- '.*affero.*', '.*lgpl.*3', '.*lgpl.*2', '.*lgpl.*', '.*gpl.*3',
- '.*gpl.*2', '.*gpl.*', '.*general.*public.*license.*3',
- '.*general.*public.*license.*2',
- '.*general.*public.*license.*', '.*mpl.*3', '.*mpl.*2',
- '.*mpl.*', '.*python.*license.*', '^python$', '.*']
- licenses = ['MIT', 'Apache-2', 'Apache', 'BSD', 'AGPL-3', 'AGPL-2', 'AGPL',
- 'AGPL-3', 'AGPL-2', 'AGPL', 'LGPL-3', 'LGPL-2', 'LGPL',
- 'GPL-3', 'GPL-2', 'GPL', 'GPL-3', 'GPL-2', 'GPL', 'MPL-3',
- 'MPL-2', 'MPL', 'Python', 'Python', 'NULL']
- for i in range(len(patterns)):
- match = re.search(patterns[i], license)
- if match:
- return licenses[i]
</del><ins>+        """ Maps the license passed to the already present list of
+        licences available in Macports """
+        license = license.lower()
+        patterns = ['.*mit.*', '.*apache.*2', '.*apache.*', '.*bsd.*', '.*agpl.*3',
+                                '.*agpl.*2', '.*agpl.*', '.*affero.*3', '.*affero.*2',
+                                '.*affero.*', '.*lgpl.*3', '.*lgpl.*2', '.*lgpl.*', '.*gpl.*3',
+                                '.*gpl.*2', '.*gpl.*', '.*general.*public.*license.*3',
+                                '.*general.*public.*license.*2',
+                                '.*general.*public.*license.*', '.*mpl.*3', '.*mpl.*2',
+                                '.*mpl.*', '.*python.*license.*', '^python$', '.*']
+        licenses = ['MIT', 'Apache-2', 'Apache', 'BSD', 'AGPL-3', 'AGPL-2', 'AGPL',
+                                'AGPL-3', 'AGPL-2', 'AGPL', 'LGPL-3', 'LGPL-2', 'LGPL',
+                                'GPL-3', 'GPL-2', 'GPL', 'GPL-3', 'GPL-2', 'GPL', 'MPL-3',
+                                'MPL-2', 'MPL', 'Python', 'Python', 'NULL']
+        for i in range(len(patterns)):
+                match = re.search(patterns[i], license)
+                if match:
+                        return licenses[i]
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def port_testing(name, portv='27'):
</span><del>- """ Port Testing function for various phase implementations """
- euid = os.geteuid()
- if euid:
- args = ['sudo', sys.executable] + sys.argv + [os.environ]
- os.execlpe('sudo', *args)
</del><ins>+        """ Port Testing function for various phase implementations """
+        euid = os.geteuid()
+        if euid:
+                args = ['sudo', sys.executable] + sys.argv + [os.environ]
+                os.execlpe('sudo', *args)
</ins><span class="cx">
</span><del>- for phase in [port_fetch, port_checksum, port_extract, port_configure,
- port_build, port_destroot, port_clean]:
- print(phase.__name__)
- phase_output = phase(name, portv)
- if phase_output:
- print(phase.__name__ + " - SUCCESS")
- else:
- print(phase.__name__ + " FAILED")
- port_clean(name, portv)
- print("Exiting")
- sys.exit(1)
</del><ins>+        for phase in [port_fetch, port_checksum, port_extract, port_configure,
+                                 port_build, port_destroot, port_clean]:
+                print(phase.__name__)
+                phase_output = phase(name, portv)
+                if phase_output:
+                        print(phase.__name__ + " - SUCCESS")
+                else:
+                        print(phase.__name__ + " FAILED")
+                        port_clean(name, portv)
+                        print("Exiting")
+                        sys.exit(1)
</ins><span class="cx">
</span><del>- euid = os.geteuid()
- if euid:
- args = ['sudo', sys.executable] + sys.argv + [os.environ]
- os.execlpe('sudo', *args)
</del><ins>+                euid = os.geteuid()
+                if euid:
+                        args = ['sudo', sys.executable] + sys.argv + [os.environ]
+                        os.execlpe('sudo', *args)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def port_fetch(name, portv='27'):
</span><del>- """ Fetch phase implementation """
- try:
- command = "sudo port -t fetch dports/python/py-" + \
- name + " subport=py" + portv + "-" + name
- command = command.split()
- subprocess.check_call(command, stderr=subprocess.STDOUT)
- return True
- except:
- return False
</del><ins>+        """ Fetch phase implementation """
+        try:
+                command = "sudo port -t fetch dports/python/py-" + \
+                                 name + " subport=py" + portv + "-" + name
+                command = command.split()
+                subprocess.check_call(command, stderr=subprocess.STDOUT)
+                return True
+        except:
+                return False
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def port_checksum(name, portv='27'):
</span><del>- """ Checksum phase implementation """
- try:
- command = "sudo port -t checksum dports/python/py-" + \
- name + " subport=py" + portv + "-" + name
- command = command.split()
- subprocess.check_call(command, stderr=subprocess.STDOUT)
- return True
- except:
- return False
</del><ins>+        """ Checksum phase implementation """
+        try:
+                command = "sudo port -t checksum dports/python/py-" + \
+                                 name + " subport=py" + portv + "-" + name
+                command = command.split()
+                subprocess.check_call(command, stderr=subprocess.STDOUT)
+                return True
+        except:
+                return False
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def port_extract(name, portv='27'):
</span><del>- """ Checksum phase implementation """
- try:
- command = "sudo port -t extract dports/python/py-" + \
- name + " subport=py" + portv + "-" + name
- command = command.split()
- subprocess.check_call(command, stderr=subprocess.STDOUT)
- return True
- except:
- return False
</del><ins>+        """ Checksum phase implementation """
+        try:
+                command = "sudo port -t extract dports/python/py-" + \
+                                 name + " subport=py" + portv + "-" + name
+                command = command.split()
+                subprocess.check_call(command, stderr=subprocess.STDOUT)
+                return True
+        except:
+                return False
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def port_patch(name, portv='27'):
</span><del>- """ Patch phase implementation """
- try:
- command = "sudo port -t patch dports/python/py-" + \
- name + " subport=py" + portv + "-" + name
- command = command.split()
- subprocess.check_call(command, stderr=subprocess.STDOUT)
- return True
- except:
- return False
</del><ins>+        """ Patch phase implementation """
+        try:
+                command = "sudo port -t patch dports/python/py-" + \
+                                 name + " subport=py" + portv + "-" + name
+                command = command.split()
+                subprocess.check_call(command, stderr=subprocess.STDOUT)
+                return True
+        except:
+                return False
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def port_configure(name, portv='27'):
</span><del>- """ Configure phase implementation """
- try:
- command = "sudo port -t configure dports/python/py-" + \
- name + " subport=py" + portv + "-" + name
- command = command.split()
- subprocess.check_call(command, stderr=subprocess.STDOUT)
- return True
- except:
- return False
</del><ins>+        """ Configure phase implementation """
+        try:
+                command = "sudo port -t configure dports/python/py-" + \
+                                 name + " subport=py" + portv + "-" + name
+                command = command.split()
+                subprocess.check_call(command, stderr=subprocess.STDOUT)
+                return True
+        except:
+                return False
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def port_build(name, portv='27'):
</span><del>- """ Build phase implementation """
- try:
- command = "sudo port -t build dports/python/py-" + \
- name + " subport=py" + portv + "-" + name
- command = command.split()
- subprocess.check_call(command, stderr=subprocess.STDOUT)
- return True
- except:
- return False
</del><ins>+        """ Build phase implementation """
+        try:
+                command = "sudo port -t build dports/python/py-" + \
+                                 name + " subport=py" + portv + "-" + name
+                command = command.split()
+                subprocess.check_call(command, stderr=subprocess.STDOUT)
+                return True
+        except:
+                return False
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def port_destroot(name, portv='27'):
</span><del>- """ Destroot phase implementation """
- try:
- command = "sudo port -t destroot dports/python/py-" + \
- name + " subport=py" + portv + "-" + name
- command = command.split()
- subprocess.check_call(command, stderr=subprocess.STDOUT)
- return True
- except:
- return False
</del><ins>+        """ Destroot phase implementation """
+        try:
+                command = "sudo port -t destroot dports/python/py-" + \
+                                 name + " subport=py" + portv + "-" + name
+                command = command.split()
+                subprocess.check_call(command, stderr=subprocess.STDOUT)
+                return True
+        except:
+                return False
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def port_clean(name, portv='27'):
</span><del>- """ Clean phase implementation """
- try:
- command = "sudo port -t clean dports/python/py-" + \
- name + " subport=py" + portv + "-" + name
- command = command.split()
- subprocess.check_call(command, stderr=subprocess.STDOUT)
- return True
- except:
- return False
</del><ins>+        """ Clean phase implementation """
+        try:
+                command = "sudo port -t clean dports/python/py-" + \
+                                 name + " subport=py" + portv + "-" + name
+                command = command.split()
+                subprocess.check_call(command, stderr=subprocess.STDOUT)
+                return True
+        except:
+                return False
</ins><span class="cx">
</span><ins>+# class Package_portfile:
+#         def __init__(self, dict, filename, dict2):
</ins><span class="cx">
</span><ins>+
</ins><span class="cx"> def create_portfile(dict, file_name, dict2):
</span><del>- """ Creates a portfile on the basis of the release_data and release_url fetched
- on the basis of package_name and package_version """
- search_distfile(dict['name'], dict['version'])
- print("Creating Portfile for pypi package " + dict['name'] + "...")
- with open(file_name, 'w') as file:
- file.write('# -*- coding: utf-8; mode: tcl; tab-width: 4; ')
- file.write('indent-tabs-mode: nil; c-basic-offset: 4 ')
- file.write('-*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4\n')
- file.write('# $Id$\n\n')
- file.write('PortSystem 1.0\n')
- file.write('PortGroup python 1.0\n\n')
</del><ins>+        """ Creates a portfile on the basis of the release_data and release_url fetched
+        on the basis of package_name and package_version """
+        search_distfile(dict['name'], dict['version'])
+        print("Creating Portfile for pypi package " + dict['name'] + "...")
+        with open(file_name, 'w') as file:
+                file.write('# -*- coding: utf-8; mode: tcl; tab-width: 4; ')
+                file.write('indent-tabs-mode: nil; c-basic-offset: 4 ')
+                file.write('-*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4\n')
+                file.write('# $Id$\n\n')
+                file.write('PortSystem 1.0\n')
+                file.write('PortGroup python 1.0\n\n')
</ins><span class="cx">
</span><del>- file.write('name py-{0}\n'.format(dict['name']))
- file.write('version {0}\n'.format(dict['version']))
</del><ins>+                file.write('name py-{0}\n'.format(dict['name']))
+                file.write('version {0}\n'.format(dict['version']))
</ins><span class="cx">
</span><del>- file.write('platforms darwin\n')
- license = dict['license']
- license = search_license(license)
- file.write('license {0}\n'.format(license))
</del><ins>+                file.write('platforms darwin\n')
+                license = dict['license']
+                license = search_license(license)
+                file.write('license {0}\n'.format(license))
</ins><span class="cx">
</span><del>- if dict['maintainer']:
- maintainers = ' '.join(dict['maintainer'])
- if not maintainers == "UNKNOWN":
- file.write('maintainers {0}\n\n'.format(maintainers))
- else:
- file.write('maintainers {0}\n\n'.format(
- os.getenv('maintainer', 'nomaintainer')))
- else:
- print("No maintainers found...")
- print("Looking for maintainers in environment variables...")
- file.write('maintainers {0}\n\n'.format(
- os.getenv('maintainer', 'nomaintainer')))
</del><ins>+                if dict['maintainer']:
+                        maintainers = ' '.join(dict['maintainer'])
+                        if not maintainers == "UNKNOWN":
+                                file.write('maintainers {0}\n\n'.format(maintainers))
+                        else:
+                                file.write('maintainers {0}\n\n'.format(
+                                                 os.getenv('maintainer', 'nomaintainer')))
+                else:
+                        print("No maintainers found...")
+                        print("Looking for maintainers in environment variables...")
+                        file.write('maintainers {0}\n\n'.format(
+                                         os.getenv('maintainer', 'nomaintainer')))
</ins><span class="cx">
</span><del>- summary = dict['summary']
- if summary:
- summary = re.sub(r'[\[\]\{\}\;\:\$\t\"\'\`\=(--)]+',
- ' ', summary)
- summary = re.sub(r'\s(\s)+', ' ', summary)
- summary = summary.encode('utf-8')
- summary = filter(lambda x: x in string.printable, summary)
- sum_lines = textwrap.wrap(summary)
- file.write('description ')
- for sum_line in sum_lines:
- if sum_line:
- if not sum_lines.index(sum_line) == 0:
- file.write(' ')
- if sum_line == sum_lines[-1]:
- file.write("{0}\n".format(sum_line))
- else:
- file.write("{0} \\\n".format(sum_line))
- else:
- file.write('description None\n\n')
-# description = dict['description']
-# if description:
-# description = description.encode('utf-8')
-# description = filter(lambda x: x in string.printable, description)
-# description = re.sub(r'[\[\]\{\}\;\:\$\t\"\'\`\=(--)]+',
-# ' ', description)
-# description = re.sub(r'\s(\s)+', ' ', description)
-# lines = textwrap.wrap(description, width=70)
-# file.write('long_description ')
-# for line in lines:
-# if line and lines.index(line) < 4:
-# if not lines.index(line) == 0:
-# file.write(' ')
-# if lines.index(line) >= 3:
-# file.write("{0}...\n".format(line))
-# elif line == lines[-1]:
-# file.write("{0}\n".format(line))
-# else:
-# file.write("{0} \\\n".format(line))
-# else:
-# file.write('long_description ${description}\n\n')
- file.write('long_description ${description}\n\n')
- home_page = dict['home_page']
</del><ins>+                summary = dict['summary']
+                if summary:
+                        summary = re.sub(r'[\[\]\{\}\;\:\$\t\"\'\`\=(--)]+',
+                                                         ' ', summary)
+                        summary = re.sub(r'\s(\s)+', ' ', summary)
+                        summary = summary.encode('utf-8')
+                        summary = filter(lambda x: x in string.printable, summary)
+                        sum_lines = textwrap.wrap(summary)
+                        file.write('description ')
+                        for sum_line in sum_lines:
+                                if sum_line:
+                                        if not sum_lines.index(sum_line) == 0:
+                                                file.write(' ')
+                                        if sum_line == sum_lines[-1]:
+                                                file.write("{0}\n".format(sum_line))
+                                        else:
+                                                file.write("{0} \\\n".format(sum_line))
+                else:
+                        file.write('description None\n\n')
</ins><span class="cx">
</span><del>- if home_page and not home_page == 'UNKNOWN':
- file.write('homepage {0}\n'.format(home_page))
- else:
- print("No homepage found...")
- print("Looking for homepage in environment variables...")
- file.write('homepage {0}\n'.format(
- os.getenv('home_page', '')))
</del><ins>+                file.write('long_description ${description}\n\n')
+                home_page = dict['home_page']
</ins><span class="cx">
</span><del>-# for item in dict2:
-# if item['python_version'] == 'source':
-# master_var = item['url']
-# break
-# print master_var
-# master_site = '/'.join(master_var.split('/')[0:-1])
-# print master_site
-# sys.exit(1)
</del><ins>+                if home_page and not home_page == 'UNKNOWN':
+                        file.write('homepage {0}\n'.format(home_page))
+                else:
+                        print("No homepage found...")
+                        print("Looking for homepage in environment variables...")
+                        file.write('homepage {0}\n'.format(
+                                         os.getenv('home_page', '')))
</ins><span class="cx">
</span><del>- try:
- # print dict2
- # print dict2['url']
- for item in dict2:
- if item['python_version'] == 'source':
- master_var = item['url']
- break
-# print master_var
- master_site = '/'.join(master_var.split('/')[0:-1])
- ext = master_var.split('/')[-1].split('.')[-1]
- if ext == 'zip':
- zip_set = True
- else:
- zip_set = False
-# print master_site
- except:
- if dict['release_url']:
- master_site = dict['release_url']
-# print master_site
- else:
- print("No master site found...")
- print("Looking for master site in environment variables...")
- master_site = os.getenv('master_site', '')
- if master_site:
- file.write('master_sites {0}\n'.format(master_site))
- master_site_exists = True
- else:
- master_site_exists = False
</del><ins>+                try:
+                        for item in dict2:
+                                if item['python_version'] == 'source':
+                                        master_var = item['url']
+                                        break
</ins><span class="cx">
</span><del>- if zip_set:
- file.write('use_zip yes\n')
- file.write('extract.mkdir yes\n')
</del><ins>+                        if master_var:
+                                master_site = '/'.join(master_var.split('/')[0:-1])
+                                ext = master_var.split('/')[-1].split('.')[-1]
+                                if ext == 'zip':
+                                        zip_set = True
+                                else:
+                                        zip_set = False
+                except:
+                        if dict['release_url']:
+                                master_site = dict['release_url']
+                                zip_set = False
+                        else:
+                                print("No master site found...")
+                                print("Looking for master site in environment variables...")
+                                master_site = os.getenv('master_site', '')
+                                zip_set = False
</ins><span class="cx">
</span><del>- file.write('distname {0}-{1}\n\n'.format(
- dict['name'], dict['version']))
</del><ins>+                if master_site:
+                        file.write('master_sites {0}\n'.format(master_site))
+                        master_site_exists = True
+                else:
+                        master_site_exists = False
</ins><span class="cx">
</span><del>- print("Attempting to generate checksums for " + dict['name'] + "...")
- checksums_values = checksums(dict['name'], dict['version'])
- if checksums_values:
- file.write('checksums rmd160 {0} \\\n'.format(
- checksums_values[0]))
- file.write(' sha256 {0}\n\n'.format(
- checksums_values[1]))
</del><ins>+                if zip_set:
+                        file.write('use_zip yes\n')
+                        file.write('extract.mkdir yes\n')
</ins><span class="cx">
</span><del>- python_vers = dict['requires_python']
- if python_vers:
- file.write('python.versions 25 26 27 {0}\n\n'.format(
- dict['requires_python']))
- else:
- file.write('python.versions 25 26 27 32 33 34\n\n')
</del><ins>+                file.write('distname {0}-{1}\n\n'.format(
+                                 dict['name'], dict['version']))
</ins><span class="cx">
</span><del>- print("Finding dependencies...")
- file.write('if {${name} ne ${subport}} {\n')
- file.write(' depends_build-append \\\n')
- file.write(' ' +
- 'port:py${python.version}-setuptools\n')
- deps = dependencies(dict['name'], dict['version'], True)
- if deps:
- for i, dep in enumerate(deps):
- dep = dep.split('>')[0].split('=')[0]
- dep = dep.replace('[', '').replace(']', '')
- deps[i] = dep
-# print deps
- for dep in deps:
- if dep in ['setuptools', '', '\n']:
- while deps.count(dep) > 0:
- deps.remove(dep)
</del><ins>+                print("Attempting to generate checksums for " + dict['name'] + "...")
+                checksums_values = checksums(dict['name'], dict['version'])
+                if checksums_values:
+                        file.write('checksums rmd160 {0} \\\n'.format(
+                                         checksums_values[0]))
+                        file.write(' sha256 {0}\n\n'.format(
+                                         checksums_values[1]))
</ins><span class="cx">
</span><ins>+                python_vers = dict['requires_python']
+                if python_vers:
+                        file.write('python.versions 25 26 27 {0}\n\n'.format(
+                                         dict['requires_python']))
+                else:
+                        file.write('python.versions 25 26 27 32 33 34\n\n')
</ins><span class="cx">
</span><del>-# for dep in deps:
-# dep = dep.split('>')[0].split('=')[0]
-# dep = dep.replace('[','').replace(']','')
-# for item in ['setuptools', '', '\n']:
-# while deps.count(item) > 0:
-# deps.remove(item)
- if len(deps) > 0:
- file.write(' depends_run-append \\\n')
-# file.write(' ' +
-# 'port:py${python.version}-setuptools')
-# file.write(" \\\n")
- for dep in deps[:-1]:
- file.write(' ' +
- 'port:py${python.version}-' +
- dep + ' \\\n')
- else:
- file.write(' ' +
- 'port:py${python.version}-' +
- deps[-1] + '\n')
- else:
- file.write("\n")
- file.write('\n')
- file.write(' livecheck.type none\n')
- if master_site_exists:
- file.write('} else {\n')
- file.write(' livecheck.type regex\n')
- file.write(' livecheck.url ${master_sites}\n')
- file.write('}\n')
- else:
- file.write('}\n')
- print("Searching for existent port...")
- port_exists = search_port(dict['name'])
- if port_exists:
- print("Creating diff...")
- old_file = port_exists
- new_file = './dports/python/py-'+dict['name']+'/Portfile'
- diff_file = './dports/python/py-'+dict['name']+'/patch.Portfile.diff'
- create_diff(old_file, new_file, diff_file)
- print(str(os.path.abspath(diff_file))+"\n")
-# with open(diff_file) as diff:
-# print diff.read()
- print("\nIf you want to open a new ticket. Please visit")
- print("https://trac.macports.org/auth/login/?next=/newticket")
- print("to open a new ticket after logging in with your credentials.")
- else:
- print("No port found.")
</del><ins>+                print("Finding dependencies...")
+                file.write('if {${name} ne ${subport}} {\n')
+                file.write(' depends_build-append \\\n')
+                file.write(' ' +
+                                 'port:py${python.version}-setuptools\n')
+                deps = dependencies(dict['name'], dict['version'], True)
+                if deps:
+                        for i, dep in enumerate(deps):
+                                dep = dep.split('>')[0].split('=')[0]
+                                dep = dep.replace('[', '').replace(']', '')
+                                deps[i] = dep
+                        for dep in deps:
+                                if dep in ['setuptools', '', '\n']:
+                                        while deps.count(dep) > 0:
+                                                deps.remove(dep)
</ins><span class="cx">
</span><ins>+                        if len(deps) > 0:
+                                file.write(' depends_run-append \\\n')
</ins><span class="cx">
</span><ins>+                                for dep in deps[:-1]:
+                                        file.write(' ' +
+                                                         'port:py${python.version}-' +
+                                                         dep + ' \\\n')
+                                else:
+                                        file.write(' ' +
+                                                         'port:py${python.version}-' +
+                                                         deps[-1] + '\n')
+                        else:
+                                file.write("\n")
+                file.write('\n')
+                file.write(' livecheck.type none\n')
+                if master_site_exists:
+                        file.write('} else {\n')
+                        file.write(' livecheck.type regex\n')
+                        file.write(' livecheck.url ${master_sites}\n')
+                        file.write('}\n')
+                else:
+                        file.write('}\n')
+        print("Searching for existent port...")
+        port_exists = search_port(dict['name'])
+        if port_exists:
+                print("Creating diff...")
+                old_file = port_exists
+                new_file = './dports/python/py-'+dict['name']+'/Portfile'
+                diff_file = './dports/python/py-'+dict['name']+'/patch.Portfile.diff'
+                create_diff(old_file, new_file, diff_file)
+                print(str(os.path.abspath(diff_file))+"\n")
+                print("\nIf you want to open a new ticket. Please visit")
+                print("https://trac.macports.org/auth/login/?next=/newticket")
+                print("to open a new ticket after logging in with your credentials.")
+        else:
+                print("No port found.")
+
+
</ins><span class="cx"> def print_portfile(pkg_name, pkg_version=None):
</span><del>- """ Creates the directories and other commands necessary
- for a development environment """
- root_dir = os.path.abspath("./dports")
- port_dir = os.path.join(root_dir, 'python')
- home_dir = os.path.join(port_dir, 'py-'+pkg_name)
- if not os.path.exists(root_dir):
- os.makedirs(root_dir)
- try:
- command = 'portindex dports/'
- command = command.split()
- subprocess.call(command, stderr=subprocess.STDOUT)
- except:
- pass
- if not os.path.exists(port_dir):
- os.makedirs(port_dir)
- if not os.path.exists(home_dir):
- os.makedirs(home_dir)
</del><ins>+        """ Creates the directories and other commands necessary
+        for a development environment """
+        root_dir = os.path.abspath("./dports")
+        port_dir = os.path.join(root_dir, 'python')
+        home_dir = os.path.join(port_dir, 'py-'+pkg_name)
+        if not os.path.exists(root_dir):
+                os.makedirs(root_dir)
+                try:
+                        command = 'portindex dports/'
+                        command = command.split()
+                        subprocess.call(command, stderr=subprocess.STDOUT)
+                except:
+                        pass
+        if not os.path.exists(port_dir):
+                os.makedirs(port_dir)
+        if not os.path.exists(home_dir):
+                os.makedirs(home_dir)
</ins><span class="cx">
</span><del>- print("Attempting to fetch data from pypi...")
</del><ins>+        print("Attempting to fetch data from pypi...")
</ins><span class="cx">
</span><del>- dict = client.release_data(pkg_name, pkg_version)
- dict2 = client.release_urls(pkg_name, pkg_version)
- if dict and dict2:
- print("Data fetched successfully.")
- elif dict:
- print("Release Data fetched successfully.")
- elif dict2:
- print("Release url fetched successfully.")
- else:
- print("No data found.")
</del><ins>+        dict = client.release_data(pkg_name, pkg_version)
+        dict2 = client.release_urls(pkg_name, pkg_version)
+        if dict and dict2:
+                print("Data fetched successfully.")
+        elif dict:
+                print("Release Data fetched successfully.")
+        elif dict2:
+                print("Release url fetched successfully.")
+        else:
+                print("No data found.")
</ins><span class="cx">
</span><del>- file_name = os.path.join(home_dir, "Portfile")
- create_portfile(dict, file_name, dict2)
- print("SUCCESS\n")
</del><ins>+        file_name = os.path.join(home_dir, "Portfile")
+        create_portfile(dict, file_name, dict2)
+        print("SUCCESS\n")
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def main(argv):
</span><del>- """ Main function - Argument Parser """
- parser = argparse.ArgumentParser(description="Pypi2Port Tester")
</del><ins>+        """ Main function - Argument Parser """
+        parser = argparse.ArgumentParser(description="Pypi2Port Tester")
</ins><span class="cx"> # Calls list_all() which lists al available python packages
</span><del>- parser.add_argument('-l', '--list', action='store_true', dest='list',
- default=False, required=False,
- help='List all packages')
</del><ins>+        parser.add_argument('-l', '--list', action='store_true', dest='list',
+                                                default=False, required=False,
+                                                help='List all packages')
</ins><span class="cx"> # Calls search with the package_name
</span><del>- parser.add_argument('-s', '--search', action='store', type=str,
- dest='packages_search', nargs='*', required=False,
- help='Search for a package')
</del><ins>+        parser.add_argument('-s', '--search', action='store', type=str,
+                                                dest='packages_search', nargs='*', required=False,
+                                                help='Search for a package')
</ins><span class="cx"> # Calls release_data with package_name and package_version
</span><del>- parser.add_argument('-d', '--data', action='store',
- dest='packages_data', nargs='*', type=str,
- help='Releases data for a package')
</del><ins>+        parser.add_argument('-d', '--data', action='store',
+                                                dest='packages_data', nargs='*', type=str,
+                                                help='Releases data for a package')
</ins><span class="cx"> # Calls fetch_url with the various package_releases
</span><del>- parser.add_argument('-f', '--fetch', action='store', type=str,
- dest='package_fetch', nargs='*', required=False,
- help='Fetches distfiles for a package')
</del><ins>+        parser.add_argument('-f', '--fetch', action='store', type=str,
+                                                dest='package_fetch', nargs='*', required=False,
+                                                help='Fetches distfiles for a package')
</ins><span class="cx"> # Calls print_portfile with the release data available
</span><del>- parser.add_argument('-p', '--portfile', action='store', type=str,
- dest='package_portfile', nargs='*', required=False,
- help='Prints the portfile for a package')
</del><ins>+        parser.add_argument('-p', '--portfile', action='store', type=str,
+                                                dest='package_portfile', nargs='*', required=False,
+                                                help='Prints the portfile for a package')
</ins><span class="cx"> # Calls port_testing
</span><del>- parser.add_argument('-t', '--test', action='store', type=str,
- dest='package_test', nargs='*', required=False,
- help='Tests the portfile for various phase tests')
- options = parser.parse_args()
</del><ins>+        parser.add_argument('-t', '--test', action='store', type=str,
+                                                dest='package_test', nargs='*', required=False,
+                                                help='Tests the portfile for various phase tests')
+        options = parser.parse_args()
</ins><span class="cx">
</span><del>- if options.list:
- list_all()
- return
</del><ins>+        if options.list:
+                list_all()
+                return
</ins><span class="cx">
</span><del>- if options.packages_search:
- for pkg_name in options.packages_search:
- search(pkg_name)
- return
</del><ins>+        if options.packages_search:
+                for pkg_name in options.packages_search:
+                        search(pkg_name)
+                return
</ins><span class="cx">
</span><del>- if options.packages_data:
- pkg_name = options.packages_data[0]
- if len(options.packages_data) > 1:
- pkg_version = options.packages_data[1]
- release_data(pkg_name, pkg_version)
- else:
- if client.package_releases(pkg_name):
- pkg_version = client.package_releases(pkg_name)[0]
- release_data(pkg_name, pkg_version)
- else:
- print("No release found\n")
- return
</del><ins>+        if options.packages_data:
+                pkg_name = options.packages_data[0]
+                if len(options.packages_data) > 1:
+                        pkg_version = options.packages_data[1]
+                        release_data(pkg_name, pkg_version)
+                else:
+                        if client.package_releases(pkg_name):
+                                pkg_version = client.package_releases(pkg_name)[0]
+                                release_data(pkg_name, pkg_version)
+                        else:
+                                print("No release found\n")
+                return
</ins><span class="cx">
</span><del>- if options.package_fetch:
- pkg_name = options.package_fetch[0]
- if len(options.package_fetch) > 1:
- pkg_version = options.package_fetch[1]
- fetch_url(pkg_name, pkg_version)
- else:
- releases = client.package_releases(pkg_name)
- if releases:
- pkg_version = releases[0]
- fetch_url(pkg_name, pkg_version)
- else:
- print("No release found\n")
- return
</del><ins>+        if options.package_fetch:
+                pkg_name = options.package_fetch[0]
+                if len(options.package_fetch) > 1:
+                        pkg_version = options.package_fetch[1]
+                        fetch_url(pkg_name, pkg_version)
+                else:
+                        releases = client.package_releases(pkg_name)
+                        if releases:
+                                pkg_version = releases[0]
+                                fetch_url(pkg_name, pkg_version)
+                        else:
+                                print("No release found\n")
+                return
</ins><span class="cx">
</span><del>- if options.package_portfile:
- pkg_name = options.package_portfile[0]
- if len(options.package_portfile) > 1:
- pkg_version = options.package_portfile[1]
- print_portfile(pkg_name, pkg_version)
- else:
- vers = client.package_releases(pkg_name)
- if vers:
- pkg_version = vers[0]
- print_portfile(pkg_name, pkg_version)
- else:
- print("No release found\n")
- return
</del><ins>+        if options.package_portfile:
+                pkg_name = options.package_portfile[0]
+                if len(options.package_portfile) > 1:
+                        pkg_version = options.package_portfile[1]
+                        print_portfile(pkg_name, pkg_version)
+                else:
+                        vers = client.package_releases(pkg_name)
+                        if vers:
+                                pkg_version = vers[0]
+                                print_portfile(pkg_name, pkg_version)
+                        else:
+                                print("No release found\n")
+                return
</ins><span class="cx">
</span><del>- if options.package_test:
- if len(options.package_test) > 0:
- pkg_name = options.package_test[0]
- port_testing(pkg_name)
- else:
- print("No package name specified\n")
- return
</del><ins>+        if options.package_test:
+                if len(options.package_test) > 0:
+                        pkg_name = options.package_test[0]
+                        port_testing(pkg_name)
+                else:
+                        print("No package name specified\n")
+                return
</ins><span class="cx">
</span><del>- parser.print_help()
- parser.error("No input specified")
</del><ins>+        parser.print_help()
+        parser.error("No input specified")
</ins><span class="cx">
</span><span class="cx"> if __name__ == "__main__":
</span><del>- main(sys.argv[1:])
</del><ins>+        main(sys.argv[1:])
</ins></span></pre>
</div>
</div>
</body>
</html>