<!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>[125795] users/gaurav/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/125795">125795</a></dd>
<dt>Author</dt> <dd>gaurav@macports.org</dd>
<dt>Date</dt> <dd>2014-09-26 08:27:58 -0700 (Fri, 26 Sep 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Removed Tcl magic and used usr/bin/env only</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#usersgauravpypi2portpypi2port">users/gaurav/pypi2port/pypi2port</a></li>
<li><a href="#usersgauravpypi2portpypi2portpy">users/gaurav/pypi2port/pypi2port.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="usersgauravpypi2portpypi2port"></a>
<div class="modfile"><h4>Modified: users/gaurav/pypi2port/pypi2port (125794 => 125795)</h4>
<pre class="diff"><span>
<span class="info">--- users/gaurav/pypi2port/pypi2port        2014-09-26 15:23:13 UTC (rev 125794)
+++ users/gaurav/pypi2port/pypi2port        2014-09-26 15:27:58 UTC (rev 125795)
</span><span class="lines">@@ -1,24 +1,18 @@
</span><del>-#! /bin/sh
-""":"
-exec python $0 ${1+"$@"}
-"""
-__doc__ = """...Script for pypi2port module written for "The Macports Project"
- participating in Google Summer of Code 2014..."""
-
</del><ins>+#!/usr/bin/env python
</ins><span class="cx"> # -*- coding: utf-8 -*-
</span><del>-# !/usr/bin/env python
</del><span class="cx">
</span><span class="cx"> import argparse
</span><span class="cx"> import sys
</span><span class="cx"> import os
</span><del>-import urllib2
</del><span class="cx"> import hashlib
</span><span class="cx"> import zipfile
</span><del>-from progressbar import *
</del><ins>+import progressbar as pb
</ins><span class="cx"> try:
</span><span class="cx"> import xmlrpclib
</span><ins>+ from urllib2 import urlopen
</ins><span class="cx"> except ImportError:
</span><span class="cx"> import xmlrpc.client as xmlrpclib
</span><ins>+ from urllib.request import urlopen
</ins><span class="cx"> import textwrap
</span><span class="cx"> import string
</span><span class="cx"> import shutil
</span><span class="lines">@@ -26,53 +20,43 @@
</span><span class="cx"> import difflib
</span><span class="cx"> import subprocess
</span><span class="cx"> import requests
</span><del>-import shlex
-import getpass
</del><span class="cx">
</span><span class="cx"> client = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Lists all packages available in pypi database """
-
-
</del><span class="cx"> def list_all():
</span><ins>+ """ Lists all packages available in pypi database """
</ins><span class="cx"> list_packages = client.list_packages()
</span><span class="cx"> for package in list_packages:
</span><del>- print package
</del><ins>+ print(package)
</ins><span class="cx">
</span><span class="cx">
</span><del>-""" Searches for a particular package by the name classifier """
-
-
</del><span class="cx"> def search(pkg_name):
</span><ins>+ """ Searches for a particular package by the name classifier """
</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, '-->', value[key]
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Fetches the release data for a paticular package based on
- the package_name and package_version """
-
-
</del><span class="cx"> def release_data(pkg_name, pkg_version):
</span><ins>+ """ Fetches the release data for a paticular package based on
+ the package_name and package_version """
</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="cx"> for key in values.keys():
</span><span class="cx"> print key, '-->', values[key]
</span><span class="cx"> else:
</span><del>- print "No such package found."
- print "Please specify the exact package name."
</del><ins>+ print("No such package found.")
+ print("Please specify the exact package name.")
</ins><span class="cx"> return
</span><span class="cx"> return
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Fetches the distfile for a particular package name and release_url """
-
-
</del><span class="cx"> def fetch(pkg_name, dict):
</span><del>- print "Fetching distfiles..."
</del><ins>+ """ Fetches the distfile for a particular package name and release_url """
+ print("Fetching distfiles...")
</ins><span class="cx"> checksum_md5 = dict['md5_digest']
</span><span class="cx"> parent_dir = './sources'
</span><span class="cx"> home_dir = parent_dir + '/' + 'python'
</span><span class="lines">@@ -87,15 +71,15 @@
</span><span class="cx"> url = dict['url']
</span><span class="cx"> file_name = src_dir + '/' + dict['filename']
</span><span class="cx">
</span><del>- u = urllib2.urlopen(url)
</del><ins>+ u = urlopen(url)
</ins><span class="cx"> with open(file_name, 'wb') as f:
</span><span class="cx"> meta = u.info()
</span><span class="cx"> file_size = int(meta.getheaders("Content-Length")[0])
</span><span class="cx">
</span><del>- widgets = ['Fetching: ', Percentage(), ' ',
- Bar(marker=RotatingMarker(), left='[', right=']'),
- ' ', ETA(), ' ', FileTransferSpeed()]
- pbar = ProgressBar(widgets=widgets, maxval=int(file_size))
</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))
</ins><span class="cx"> pbar.start()
</span><span class="cx">
</span><span class="cx"> file_size_dl = 0
</span><span class="lines">@@ -113,7 +97,7 @@
</span><span class="cx">
</span><span class="cx"> checksum_md5_calc = hashlib.md5(open(file_name).read()).hexdigest()
</span><span class="cx"> if str(checksum_md5) == str(checksum_md5_calc):
</span><del>- print 'Successfully fetched'
</del><ins>+ print('Successfully fetched')
</ins><span class="cx"> ext = file_name.split('.')[-1]
</span><span class="cx"> if ext == 'egg':
</span><span class="cx"> zip = zipfile.ZipFile(file_name)
</span><span class="lines">@@ -122,41 +106,37 @@
</span><span class="cx"> zip.extract(name, src_dir)
</span><span class="cx"> return file_name
</span><span class="cx"> else:
</span><del>- print 'Aborting due to inconsistency on checksums\n'
</del><ins>+ print('Aborting due to inconsistency on checksums\n')
</ins><span class="cx"> try:
</span><span class="cx"> os.remove(file_name)
</span><del>- except OSError, e:
- print "Error: %s - %s." % (e.filename, e.strerror)
</del><ins>+ except OSError as e:
+ print("Error: %s - %s." % (e.filename, e.strerror))
</ins><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Checks for the checksums and dependecies for a particular python package
- on the basis of package_name and package_version """
-
-
</del><span class="cx"> def fetch_url(pkg_name, pkg_version, checksum=False, deps=False):
</span><ins>+ """ Checks for the checksums and dependecies for a particular python package
+ on the basis of package_name and package_version """
</ins><span class="cx"> values = client.release_urls(pkg_name, pkg_version)
</span><span class="cx"> if checksum:
</span><del>-# print values
</del><ins>+ # print values
</ins><span class="cx"> for value in values:
</span><del>- if value['filename'].split('.')[-1] == 'gz' or value['filename'].split('.')[-1] == 'zip':
</del><ins>+ if value['filename'].split('.')[-1] in ('gz', 'zip'):
</ins><span class="cx"> return fetch(pkg_name, value)
</span><span class="cx"> else:
</span><span class="cx"> for value in values:
</span><span class="cx"> return fetch(pkg_name, value)
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Finds dependencies for a particular package on the basis of
- package_name and package_version """
-
-
</del><span class="cx"> def dependencies(pkg_name, pkg_version, deps=False):
</span><ins>+ """ Finds dependencies for a particular package on the basis of
+ package_name and package_version """
</ins><span class="cx"> flag = False
</span><span class="cx"> if not deps:
</span><span class="cx"> return
</span><span class="cx"> values = client.release_urls(pkg_name, pkg_version)
</span><span class="cx"> for value in values:
</span><del>- if not(value['filename'].split('.')[-1] == 'gz' or value['filename'].split('.')[-1] == 'zip'):
</del><ins>+ if value['filename'].split('.')[-1] in ('gz', 'zip'):
</ins><span class="cx"> fetch(pkg_name, value)
</span><span class="cx"> try:
</span><span class="cx"> with open('./sources/python/py-'
</span><span class="lines">@@ -170,7 +150,7 @@
</span><span class="cx"> ignore_errors=True)
</span><span class="cx"> items = os.listdir('./sources/python/py-' + pkg_name)
</span><span class="cx"> for item in items[:]:
</span><del>- if not(item.split('.')[-1] == 'gz' or item.split('.')[-1] == 'zip'):
</del><ins>+ if item.split('.')[-1] not in ('gz', 'zip'):
</ins><span class="cx"> os.remove('./sources/python/py-'
</span><span class="cx"> + pkg_name + '/' + item)
</span><span class="cx"> items.remove(item)
</span><span class="lines">@@ -186,7 +166,7 @@
</span><span class="cx"> ignore_errors=True)
</span><span class="cx"> items = os.listdir('./sources/python/py-'+pkg_name)
</span><span class="cx"> for item in items[:]:
</span><del>- if not(item.split('.')[-1] == 'gz' or item.split('.')[-1] == 'zip'):
</del><ins>+ if item.split('.')[-1] not in ('gz', 'zip'):
</ins><span class="cx"> os.remove('./sources/python/py-'+pkg_name+'/'+item)
</span><span class="cx"> items.remove(item)
</span><span class="cx"> if not items:
</span><span class="lines">@@ -196,10 +176,8 @@
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Creates a diff file for an existent port """
-
-
</del><span class="cx"> def create_diff(old_file, new_file, diff_file):
</span><ins>+ """ Creates a diff file for an existent port """
</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">@@ -208,39 +186,31 @@
</span><span class="cx"> # b = open(new_file).readlines()
</span><span class="cx"> diff_string = difflib.unified_diff(a, b, "Portfile.orig", "Portfile")
</span><span class="cx"> with open(diff_file, 'w') as d:
</span><del>- try:
- while 1:
- d.write(diff_string.next())
- except:
- pass
</del><ins>+ d.writelines(diff_string)
</ins><span class="cx">
</span><span class="cx">
</span><del>-""" Searches for an existent port by its name """
-
-
</del><span class="cx"> def search_port(name):
</span><ins>+ """ Searches for an existent port by its name """
</ins><span class="cx"> try:
</span><span class="cx"> command = "port file name:^py-" + name + "$"
</span><span class="cx"> command = command.split()
</span><span class="cx"> existing_portfile = \
</span><span class="cx"> subprocess.check_output(command, stderr=subprocess.STDOUT).strip()
</span><span class="cx"> return existing_portfile
</span><del>- except Exception, e:
</del><ins>+ except Exception:
</ins><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Generates checksums for a package on the basis of the distfile fetched by
- its package_name and package_version """
-
-
</del><span class="cx"> def checksums(pkg_name, pkg_version):
</span><ins>+ """ Generates checksums for a package on the basis of the distfile fetched by
+ its package_name and package_version """
</ins><span class="cx"> flag = False
</span><del>- print "Attempting to fetch distfiles..."
</del><ins>+ print("Attempting to fetch distfiles...")
</ins><span class="cx"> file_name = fetch_url(pkg_name, pkg_version, True)
</span><span class="cx"> if file_name:
</span><span class="cx"> checksums = []
</span><span class="cx"> try:
</span><del>- print "Generating checksums..."
</del><ins>+ print("Generating checksums...")
</ins><span class="cx"> command = "openssl rmd160 "+file_name
</span><span class="cx"> command = command.split()
</span><span class="cx"> rmd160 = subprocess.check_output(command, stderr=subprocess.STDOUT)
</span><span class="lines">@@ -259,34 +229,30 @@
</span><span class="cx"> try:
</span><span class="cx"> if flag:
</span><span class="cx"> os.rmdir(dir)
</span><del>- except OSError as ex:
</del><ins>+ except OSError:
</ins><span class="cx"> pass
</span><span class="cx"> return checksums
</span><span class="cx"> except:
</span><del>- print "Error\n"
</del><ins>+ print("Error\n")
</ins><span class="cx"> return
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Searches if the distfile listed is present or not """
-
-
</del><span class="cx"> def search_distfile(name, version):
</span><ins>+ """ Searches if the distfile listed is present or not """
</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="cx"> if not r.status_code == 200:
</span><del>- raise Error('No distfile')
</del><ins>+ raise Exception('No distfile')
</ins><span class="cx"> except:
</span><del>- print "No distfile found"
- print "Please set a DISTFILE env var before generating the portfile"
</del><ins>+ print("No distfile found")
+ print("Please set a DISTFILE env var before generating the portfile")
</ins><span class="cx"> sys.exit(0)
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Maps the license passed to the already present list of
- licences available in Macports """
-
-
</del><span class="cx"> def search_license(license):
</span><ins>+ """ Maps the license passed to the already present list of
+ licences available in Macports """
</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">@@ -305,10 +271,8 @@
</span><span class="cx"> return licenses[i]
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Port Testing function for various phase implementations """
-
-
</del><span class="cx"> def port_testing(name, portv='27'):
</span><ins>+ """ Port Testing function for various phase implementations """
</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">@@ -316,14 +280,14 @@
</span><span class="cx">
</span><span class="cx"> for phase in [port_fetch, port_checksum, port_extract, port_configure,
</span><span class="cx"> port_build, port_destroot, port_clean]:
</span><del>- print phase.__name__
</del><ins>+ print(phase.__name__)
</ins><span class="cx"> phase_output = phase(name, portv)
</span><span class="cx"> if phase_output:
</span><del>- print phase.__name__ + " - SUCCESS"
</del><ins>+ print(phase.__name__ + " - SUCCESS")
</ins><span class="cx"> else:
</span><del>- print phase.__name__ + " FAILED"
</del><ins>+ print(phase.__name__ + " FAILED")
</ins><span class="cx"> port_clean(name, portv)
</span><del>- print "Exiting"
</del><ins>+ print("Exiting")
</ins><span class="cx"> sys.exit(1)
</span><span class="cx">
</span><span class="cx"> euid = os.geteuid()
</span><span class="lines">@@ -332,125 +296,107 @@
</span><span class="cx"> os.execlpe('sudo', *args)
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Fetch phase implementation """
-
-
</del><span class="cx"> def port_fetch(name, portv='27'):
</span><ins>+ """ Fetch phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t fetch dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Checksum phase implementation """
-
-
</del><span class="cx"> def port_checksum(name, portv='27'):
</span><ins>+ """ Checksum phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t checksum dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Checksum phase implementation """
-
-
</del><span class="cx"> def port_extract(name, portv='27'):
</span><ins>+ """ Checksum phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t extract dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Patch phase implementation """
-
-
</del><span class="cx"> def port_patch(name, portv='27'):
</span><ins>+ """ Patch phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t patch dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Configure phase implementation """
-
-
</del><span class="cx"> def port_configure(name, portv='27'):
</span><ins>+ """ Configure phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t configure dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Build phase implementation """
-
-
</del><span class="cx"> def port_build(name, portv='27'):
</span><ins>+ """ Build phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t build dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Destroot phase implementation """
-
-
</del><span class="cx"> def port_destroot(name, portv='27'):
</span><ins>+ """ Destroot phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t destroot dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Clean phase implementation """
-
-
</del><span class="cx"> def port_clean(name, portv='27'):
</span><ins>+ """ Clean phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t clean dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</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 """
-
-
</del><span class="cx"> def create_portfile(dict, file_name, dict2):
</span><ins>+ """ Creates a portfile on the basis of the release_data and release_url fetched
+ on the basis of package_name and package_version """
</ins><span class="cx"> search_distfile(dict['name'], dict['version'])
</span><del>- print "Creating Portfile for pypi package " + dict['name'] + "..."
</del><ins>+ print("Creating Portfile for pypi package " + dict['name'] + "...")
</ins><span class="cx"> with open(file_name, 'w') as file:
</span><span class="cx"> file.write('# -*- coding: utf-8; mode: tcl; tab-width: 4; ')
</span><span class="cx"> file.write('indent-tabs-mode: nil; c-basic-offset: 4 ')
</span><span class="lines">@@ -475,8 +421,8 @@
</span><span class="cx"> file.write('maintainers {0}\n\n'.format(
</span><span class="cx"> os.getenv('maintainer', 'nomaintainer')))
</span><span class="cx"> else:
</span><del>- print "No maintainers found..."
- print "Looking for maintainers in environment variables..."
</del><ins>+ print("No maintainers found...")
+ print("Looking for maintainers in environment variables...")
</ins><span class="cx"> file.write('maintainers {0}\n\n'.format(
</span><span class="cx"> os.getenv('maintainer', 'nomaintainer')))
</span><span class="cx">
</span><span class="lines">@@ -499,7 +445,7 @@
</span><span class="cx"> file.write("{0} \\\n".format(sum_line))
</span><span class="cx"> else:
</span><span class="cx"> file.write('description None\n\n')
</span><del>- description = dict['description']
</del><ins>+# description = dict['description']
</ins><span class="cx"> # if description:
</span><span class="cx"> # description = description.encode('utf-8')
</span><span class="cx"> # description = filter(lambda x: x in string.printable, description)
</span><span class="lines">@@ -526,8 +472,8 @@
</span><span class="cx"> if home_page and not home_page == 'UNKNOWN':
</span><span class="cx"> file.write('homepage {0}\n'.format(home_page))
</span><span class="cx"> else:
</span><del>- print "No homepage found..."
- print "Looking for homepage in environment variables..."
</del><ins>+ print("No homepage found...")
+ print("Looking for homepage in environment variables...")
</ins><span class="cx"> file.write('homepage {0}\n'.format(
</span><span class="cx"> os.getenv('home_page', '')))
</span><span class="cx">
</span><span class="lines">@@ -541,8 +487,8 @@
</span><span class="cx"> # sys.exit(1)
</span><span class="cx">
</span><span class="cx"> try:
</span><del>-# print dict2
-# print dict2['url']
</del><ins>+ # print dict2
+ # print dict2['url']
</ins><span class="cx"> for item in dict2:
</span><span class="cx"> if item['python_version'] == 'source':
</span><span class="cx"> master_var = item['url']
</span><span class="lines">@@ -560,8 +506,8 @@
</span><span class="cx"> master_site = dict['release_url']
</span><span class="cx"> # print master_site
</span><span class="cx"> else:
</span><del>- print "No master site found..."
- print "Looking for master site in environment variables..."
</del><ins>+ print("No master site found...")
+ print("Looking for master site in environment variables...")
</ins><span class="cx"> master_site = os.getenv('master_site', '')
</span><span class="cx"> if master_site:
</span><span class="cx"> file.write('master_sites {0}\n'.format(master_site))
</span><span class="lines">@@ -576,7 +522,7 @@
</span><span class="cx"> file.write('distname {0}-{1}\n\n'.format(
</span><span class="cx"> dict['name'], dict['version']))
</span><span class="cx">
</span><del>- print "Attempting to generate checksums for " + dict['name'] + "..."
</del><ins>+ print("Attempting to generate checksums for " + dict['name'] + "...")
</ins><span class="cx"> checksums_values = checksums(dict['name'], dict['version'])
</span><span class="cx"> if checksums_values:
</span><span class="cx"> file.write('checksums rmd160 {0} \\\n'.format(
</span><span class="lines">@@ -591,16 +537,16 @@
</span><span class="cx"> else:
</span><span class="cx"> file.write('python.versions 25 26 27 32 33 34\n\n')
</span><span class="cx">
</span><del>- print "Finding dependencies..."
</del><ins>+ print("Finding dependencies...")
</ins><span class="cx"> file.write('if {${name} ne ${subport}} {\n')
</span><span class="cx"> file.write(' depends_build-append \\\n')
</span><span class="cx"> file.write(' ' +
</span><span class="cx"> 'port:py${python.version}-setuptools\n')
</span><span class="cx"> deps = dependencies(dict['name'], dict['version'], True)
</span><span class="cx"> if deps:
</span><del>- for i,dep in enumerate(deps):
</del><ins>+ for i, dep in enumerate(deps):
</ins><span class="cx"> dep = dep.split('>')[0].split('=')[0]
</span><del>- dep = dep.replace('[','').replace(']','')
</del><ins>+ dep = dep.replace('[', '').replace(']', '')
</ins><span class="cx"> deps[i] = dep
</span><span class="cx"> # print deps
</span><span class="cx"> for dep in deps:
</span><span class="lines">@@ -639,29 +585,27 @@
</span><span class="cx"> file.write('}\n')
</span><span class="cx"> else:
</span><span class="cx"> file.write('}\n')
</span><del>- print "Searching for existent port..."
</del><ins>+ print("Searching for existent port...")
</ins><span class="cx"> port_exists = search_port(dict['name'])
</span><span class="cx"> if port_exists:
</span><del>- print "Creating diff..."
</del><ins>+ print("Creating diff...")
</ins><span class="cx"> old_file = port_exists
</span><span class="cx"> new_file = './dports/python/py-'+dict['name']+'/Portfile'
</span><span class="cx"> diff_file = './dports/python/py-'+dict['name']+'/patch.Portfile.diff'
</span><span class="cx"> create_diff(old_file, new_file, diff_file)
</span><del>- print str(os.path.abspath(diff_file))+"\n"
</del><ins>+ print(str(os.path.abspath(diff_file))+"\n")
</ins><span class="cx"> # with open(diff_file) as diff:
</span><span class="cx"> # print diff.read()
</span><del>- 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."
</del><ins>+ 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.")
</ins><span class="cx"> else:
</span><del>- print "No port found."
</del><ins>+ print("No port found.")
</ins><span class="cx">
</span><span class="cx">
</span><del>-""" Creates the directories and other commands necessary
- for a development environment """
-
-
</del><span class="cx"> def print_portfile(pkg_name, pkg_version=None):
</span><ins>+ """ Creates the directories and other commands necessary
+ for a development environment """
</ins><span class="cx"> root_dir = os.path.abspath("./dports")
</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">@@ -678,28 +622,26 @@
</span><span class="cx"> if not os.path.exists(home_dir):
</span><span class="cx"> os.makedirs(home_dir)
</span><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><span class="cx"> dict = client.release_data(pkg_name, pkg_version)
</span><span class="cx"> dict2 = client.release_urls(pkg_name, pkg_version)
</span><span class="cx"> if dict and dict2:
</span><del>- print "Data fetched successfully."
</del><ins>+ print("Data fetched successfully.")
</ins><span class="cx"> elif dict:
</span><del>- print "Release Data fetched successfully."
</del><ins>+ print("Release Data fetched successfully.")
</ins><span class="cx"> elif dict2:
</span><del>- print "Release url fetched successfully."
</del><ins>+ print("Release url fetched successfully.")
</ins><span class="cx"> else:
</span><del>- print "No data found."
</del><ins>+ print("No data found.")
</ins><span class="cx">
</span><span class="cx"> file_name = os.path.join(home_dir, "Portfile")
</span><span class="cx"> create_portfile(dict, file_name, dict2)
</span><del>- print "SUCCESS\n"
</del><ins>+ print("SUCCESS\n")
</ins><span class="cx">
</span><span class="cx">
</span><del>-""" Main function - Argument Parser """
-
-
</del><span class="cx"> def main(argv):
</span><ins>+ """ Main function - Argument Parser """
</ins><span class="cx"> parser = argparse.ArgumentParser(description="Pypi2Port Tester")
</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 class="lines">@@ -731,13 +673,11 @@
</span><span class="cx"> list_all()
</span><span class="cx"> return
</span><span class="cx">
</span><del>-
</del><span class="cx"> if options.packages_search:
</span><span class="cx"> for pkg_name in options.packages_search:
</span><span class="cx"> search(pkg_name)
</span><span class="cx"> return
</span><span class="cx">
</span><del>-
</del><span class="cx"> if options.packages_data:
</span><span class="cx"> pkg_name = options.packages_data[0]
</span><span class="cx"> if len(options.packages_data) > 1:
</span><span class="lines">@@ -748,10 +688,9 @@
</span><span class="cx"> pkg_version = client.package_releases(pkg_name)[0]
</span><span class="cx"> release_data(pkg_name, pkg_version)
</span><span class="cx"> else:
</span><del>- print "No release found\n"
</del><ins>+ print("No release found\n")
</ins><span class="cx"> return
</span><span class="cx">
</span><del>-
</del><span class="cx"> if options.package_fetch:
</span><span class="cx"> pkg_name = options.package_fetch[0]
</span><span class="cx"> if len(options.package_fetch) > 1:
</span><span class="lines">@@ -763,10 +702,9 @@
</span><span class="cx"> pkg_version = releases[0]
</span><span class="cx"> fetch_url(pkg_name, pkg_version)
</span><span class="cx"> else:
</span><del>- print "No release found\n"
</del><ins>+ print("No release found\n")
</ins><span class="cx"> return
</span><span class="cx">
</span><del>-
</del><span class="cx"> if options.package_portfile:
</span><span class="cx"> pkg_name = options.package_portfile[0]
</span><span class="cx"> if len(options.package_portfile) > 1:
</span><span class="lines">@@ -778,16 +716,15 @@
</span><span class="cx"> pkg_version = vers[0]
</span><span class="cx"> print_portfile(pkg_name, pkg_version)
</span><span class="cx"> else:
</span><del>- print "No release found\n"
</del><ins>+ print("No release found\n")
</ins><span class="cx"> return
</span><span class="cx">
</span><del>-
</del><span class="cx"> if options.package_test:
</span><span class="cx"> if len(options.package_test) > 0:
</span><span class="cx"> pkg_name = options.package_test[0]
</span><span class="cx"> port_testing(pkg_name)
</span><span class="cx"> else:
</span><del>- print "No package name specified\n"
</del><ins>+ print("No package name specified\n")
</ins><span class="cx"> return
</span><span class="cx">
</span><span class="cx"> parser.print_help()
</span></span></pre></div>
<a id="usersgauravpypi2portpypi2portpy"></a>
<div class="modfile"><h4>Modified: users/gaurav/pypi2port/pypi2port.py (125794 => 125795)</h4>
<pre class="diff"><span>
<span class="info">--- users/gaurav/pypi2port/pypi2port.py        2014-09-26 15:23:13 UTC (rev 125794)
+++ users/gaurav/pypi2port/pypi2port.py        2014-09-26 15:27:58 UTC (rev 125795)
</span><span class="lines">@@ -1,24 +1,18 @@
</span><del>-#! /bin/sh
-""":"
-exec python $0 ${1+"$@"}
-"""
-__doc__ = """...Script for pypi2port module written for "The Macports Project"
- participating in Google Summer of Code 2014..."""
-
</del><ins>+#!/usr/bin/env python
</ins><span class="cx"> # -*- coding: utf-8 -*-
</span><del>-# !/usr/bin/env python
</del><span class="cx">
</span><span class="cx"> import argparse
</span><span class="cx"> import sys
</span><span class="cx"> import os
</span><del>-import urllib2
</del><span class="cx"> import hashlib
</span><span class="cx"> import zipfile
</span><del>-from progressbar import *
</del><ins>+import progressbar as pb
</ins><span class="cx"> try:
</span><span class="cx"> import xmlrpclib
</span><ins>+ from urllib2 import urlopen
</ins><span class="cx"> except ImportError:
</span><span class="cx"> import xmlrpc.client as xmlrpclib
</span><ins>+ from urllib.request import urlopen
</ins><span class="cx"> import textwrap
</span><span class="cx"> import string
</span><span class="cx"> import shutil
</span><span class="lines">@@ -26,53 +20,43 @@
</span><span class="cx"> import difflib
</span><span class="cx"> import subprocess
</span><span class="cx"> import requests
</span><del>-import shlex
-import getpass
</del><span class="cx">
</span><span class="cx"> client = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Lists all packages available in pypi database """
-
-
</del><span class="cx"> def list_all():
</span><ins>+ """ Lists all packages available in pypi database """
</ins><span class="cx"> list_packages = client.list_packages()
</span><span class="cx"> for package in list_packages:
</span><del>- print package
</del><ins>+ print(package)
</ins><span class="cx">
</span><span class="cx">
</span><del>-""" Searches for a particular package by the name classifier """
-
-
</del><span class="cx"> def search(pkg_name):
</span><ins>+ """ Searches for a particular package by the name classifier """
</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, '-->', value[key]
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Fetches the release data for a paticular package based on
- the package_name and package_version """
-
-
</del><span class="cx"> def release_data(pkg_name, pkg_version):
</span><ins>+ """ Fetches the release data for a paticular package based on
+ the package_name and package_version """
</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="cx"> for key in values.keys():
</span><span class="cx"> print key, '-->', values[key]
</span><span class="cx"> else:
</span><del>- print "No such package found."
- print "Please specify the exact package name."
</del><ins>+ print("No such package found.")
+ print("Please specify the exact package name.")
</ins><span class="cx"> return
</span><span class="cx"> return
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Fetches the distfile for a particular package name and release_url """
-
-
</del><span class="cx"> def fetch(pkg_name, dict):
</span><del>- print "Fetching distfiles..."
</del><ins>+ """ Fetches the distfile for a particular package name and release_url """
+ print("Fetching distfiles...")
</ins><span class="cx"> checksum_md5 = dict['md5_digest']
</span><span class="cx"> parent_dir = './sources'
</span><span class="cx"> home_dir = parent_dir + '/' + 'python'
</span><span class="lines">@@ -87,15 +71,15 @@
</span><span class="cx"> url = dict['url']
</span><span class="cx"> file_name = src_dir + '/' + dict['filename']
</span><span class="cx">
</span><del>- u = urllib2.urlopen(url)
</del><ins>+ u = urlopen(url)
</ins><span class="cx"> with open(file_name, 'wb') as f:
</span><span class="cx"> meta = u.info()
</span><span class="cx"> file_size = int(meta.getheaders("Content-Length")[0])
</span><span class="cx">
</span><del>- widgets = ['Fetching: ', Percentage(), ' ',
- Bar(marker=RotatingMarker(), left='[', right=']'),
- ' ', ETA(), ' ', FileTransferSpeed()]
- pbar = ProgressBar(widgets=widgets, maxval=int(file_size))
</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))
</ins><span class="cx"> pbar.start()
</span><span class="cx">
</span><span class="cx"> file_size_dl = 0
</span><span class="lines">@@ -113,7 +97,7 @@
</span><span class="cx">
</span><span class="cx"> checksum_md5_calc = hashlib.md5(open(file_name).read()).hexdigest()
</span><span class="cx"> if str(checksum_md5) == str(checksum_md5_calc):
</span><del>- print 'Successfully fetched'
</del><ins>+ print('Successfully fetched')
</ins><span class="cx"> ext = file_name.split('.')[-1]
</span><span class="cx"> if ext == 'egg':
</span><span class="cx"> zip = zipfile.ZipFile(file_name)
</span><span class="lines">@@ -122,41 +106,37 @@
</span><span class="cx"> zip.extract(name, src_dir)
</span><span class="cx"> return file_name
</span><span class="cx"> else:
</span><del>- print 'Aborting due to inconsistency on checksums\n'
</del><ins>+ print('Aborting due to inconsistency on checksums\n')
</ins><span class="cx"> try:
</span><span class="cx"> os.remove(file_name)
</span><del>- except OSError, e:
- print "Error: %s - %s." % (e.filename, e.strerror)
</del><ins>+ except OSError as e:
+ print("Error: %s - %s." % (e.filename, e.strerror))
</ins><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Checks for the checksums and dependecies for a particular python package
- on the basis of package_name and package_version """
-
-
</del><span class="cx"> def fetch_url(pkg_name, pkg_version, checksum=False, deps=False):
</span><ins>+ """ Checks for the checksums and dependecies for a particular python package
+ on the basis of package_name and package_version """
</ins><span class="cx"> values = client.release_urls(pkg_name, pkg_version)
</span><span class="cx"> if checksum:
</span><del>-# print values
</del><ins>+ # print values
</ins><span class="cx"> for value in values:
</span><del>- if value['filename'].split('.')[-1] == 'gz' or value['filename'].split('.')[-1] == 'zip':
</del><ins>+ if value['filename'].split('.')[-1] in ('gz', 'zip'):
</ins><span class="cx"> return fetch(pkg_name, value)
</span><span class="cx"> else:
</span><span class="cx"> for value in values:
</span><span class="cx"> return fetch(pkg_name, value)
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Finds dependencies for a particular package on the basis of
- package_name and package_version """
-
-
</del><span class="cx"> def dependencies(pkg_name, pkg_version, deps=False):
</span><ins>+ """ Finds dependencies for a particular package on the basis of
+ package_name and package_version """
</ins><span class="cx"> flag = False
</span><span class="cx"> if not deps:
</span><span class="cx"> return
</span><span class="cx"> values = client.release_urls(pkg_name, pkg_version)
</span><span class="cx"> for value in values:
</span><del>- if not(value['filename'].split('.')[-1] == 'gz' or value['filename'].split('.')[-1] == 'zip'):
</del><ins>+ if value['filename'].split('.')[-1] in ('gz', 'zip'):
</ins><span class="cx"> fetch(pkg_name, value)
</span><span class="cx"> try:
</span><span class="cx"> with open('./sources/python/py-'
</span><span class="lines">@@ -170,7 +150,7 @@
</span><span class="cx"> ignore_errors=True)
</span><span class="cx"> items = os.listdir('./sources/python/py-' + pkg_name)
</span><span class="cx"> for item in items[:]:
</span><del>- if not(item.split('.')[-1] == 'gz' or item.split('.')[-1] == 'zip'):
</del><ins>+ if item.split('.')[-1] not in ('gz', 'zip'):
</ins><span class="cx"> os.remove('./sources/python/py-'
</span><span class="cx"> + pkg_name + '/' + item)
</span><span class="cx"> items.remove(item)
</span><span class="lines">@@ -186,7 +166,7 @@
</span><span class="cx"> ignore_errors=True)
</span><span class="cx"> items = os.listdir('./sources/python/py-'+pkg_name)
</span><span class="cx"> for item in items[:]:
</span><del>- if not(item.split('.')[-1] == 'gz' or item.split('.')[-1] == 'zip'):
</del><ins>+ if item.split('.')[-1] not in ('gz', 'zip'):
</ins><span class="cx"> os.remove('./sources/python/py-'+pkg_name+'/'+item)
</span><span class="cx"> items.remove(item)
</span><span class="cx"> if not items:
</span><span class="lines">@@ -196,10 +176,8 @@
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Creates a diff file for an existent port """
-
-
</del><span class="cx"> def create_diff(old_file, new_file, diff_file):
</span><ins>+ """ Creates a diff file for an existent port """
</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">@@ -208,39 +186,31 @@
</span><span class="cx"> # b = open(new_file).readlines()
</span><span class="cx"> diff_string = difflib.unified_diff(a, b, "Portfile.orig", "Portfile")
</span><span class="cx"> with open(diff_file, 'w') as d:
</span><del>- try:
- while 1:
- d.write(diff_string.next())
- except:
- pass
</del><ins>+ d.writelines(diff_string)
</ins><span class="cx">
</span><span class="cx">
</span><del>-""" Searches for an existent port by its name """
-
-
</del><span class="cx"> def search_port(name):
</span><ins>+ """ Searches for an existent port by its name """
</ins><span class="cx"> try:
</span><span class="cx"> command = "port file name:^py-" + name + "$"
</span><span class="cx"> command = command.split()
</span><span class="cx"> existing_portfile = \
</span><span class="cx"> subprocess.check_output(command, stderr=subprocess.STDOUT).strip()
</span><span class="cx"> return existing_portfile
</span><del>- except Exception, e:
</del><ins>+ except Exception:
</ins><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Generates checksums for a package on the basis of the distfile fetched by
- its package_name and package_version """
-
-
</del><span class="cx"> def checksums(pkg_name, pkg_version):
</span><ins>+ """ Generates checksums for a package on the basis of the distfile fetched by
+ its package_name and package_version """
</ins><span class="cx"> flag = False
</span><del>- print "Attempting to fetch distfiles..."
</del><ins>+ print("Attempting to fetch distfiles...")
</ins><span class="cx"> file_name = fetch_url(pkg_name, pkg_version, True)
</span><span class="cx"> if file_name:
</span><span class="cx"> checksums = []
</span><span class="cx"> try:
</span><del>- print "Generating checksums..."
</del><ins>+ print("Generating checksums...")
</ins><span class="cx"> command = "openssl rmd160 "+file_name
</span><span class="cx"> command = command.split()
</span><span class="cx"> rmd160 = subprocess.check_output(command, stderr=subprocess.STDOUT)
</span><span class="lines">@@ -259,34 +229,30 @@
</span><span class="cx"> try:
</span><span class="cx"> if flag:
</span><span class="cx"> os.rmdir(dir)
</span><del>- except OSError as ex:
</del><ins>+ except OSError:
</ins><span class="cx"> pass
</span><span class="cx"> return checksums
</span><span class="cx"> except:
</span><del>- print "Error\n"
</del><ins>+ print("Error\n")
</ins><span class="cx"> return
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Searches if the distfile listed is present or not """
-
-
</del><span class="cx"> def search_distfile(name, version):
</span><ins>+ """ Searches if the distfile listed is present or not """
</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="cx"> if not r.status_code == 200:
</span><del>- raise Error('No distfile')
</del><ins>+ raise Exception('No distfile')
</ins><span class="cx"> except:
</span><del>- print "No distfile found"
- print "Please set a DISTFILE env var before generating the portfile"
</del><ins>+ print("No distfile found")
+ print("Please set a DISTFILE env var before generating the portfile")
</ins><span class="cx"> sys.exit(0)
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Maps the license passed to the already present list of
- licences available in Macports """
-
-
</del><span class="cx"> def search_license(license):
</span><ins>+ """ Maps the license passed to the already present list of
+ licences available in Macports """
</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">@@ -305,10 +271,8 @@
</span><span class="cx"> return licenses[i]
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Port Testing function for various phase implementations """
-
-
</del><span class="cx"> def port_testing(name, portv='27'):
</span><ins>+ """ Port Testing function for various phase implementations """
</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">@@ -316,14 +280,14 @@
</span><span class="cx">
</span><span class="cx"> for phase in [port_fetch, port_checksum, port_extract, port_configure,
</span><span class="cx"> port_build, port_destroot, port_clean]:
</span><del>- print phase.__name__
</del><ins>+ print(phase.__name__)
</ins><span class="cx"> phase_output = phase(name, portv)
</span><span class="cx"> if phase_output:
</span><del>- print phase.__name__ + " - SUCCESS"
</del><ins>+ print(phase.__name__ + " - SUCCESS")
</ins><span class="cx"> else:
</span><del>- print phase.__name__ + " FAILED"
</del><ins>+ print(phase.__name__ + " FAILED")
</ins><span class="cx"> port_clean(name, portv)
</span><del>- print "Exiting"
</del><ins>+ print("Exiting")
</ins><span class="cx"> sys.exit(1)
</span><span class="cx">
</span><span class="cx"> euid = os.geteuid()
</span><span class="lines">@@ -332,125 +296,107 @@
</span><span class="cx"> os.execlpe('sudo', *args)
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Fetch phase implementation """
-
-
</del><span class="cx"> def port_fetch(name, portv='27'):
</span><ins>+ """ Fetch phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t fetch dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Checksum phase implementation """
-
-
</del><span class="cx"> def port_checksum(name, portv='27'):
</span><ins>+ """ Checksum phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t checksum dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Checksum phase implementation """
-
-
</del><span class="cx"> def port_extract(name, portv='27'):
</span><ins>+ """ Checksum phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t extract dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Patch phase implementation """
-
-
</del><span class="cx"> def port_patch(name, portv='27'):
</span><ins>+ """ Patch phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t patch dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Configure phase implementation """
-
-
</del><span class="cx"> def port_configure(name, portv='27'):
</span><ins>+ """ Configure phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t configure dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Build phase implementation """
-
-
</del><span class="cx"> def port_build(name, portv='27'):
</span><ins>+ """ Build phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t build dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Destroot phase implementation """
-
-
</del><span class="cx"> def port_destroot(name, portv='27'):
</span><ins>+ """ Destroot phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t destroot dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>-""" Clean phase implementation """
-
-
</del><span class="cx"> def port_clean(name, portv='27'):
</span><ins>+ """ Clean phase implementation """
</ins><span class="cx"> try:
</span><span class="cx"> command = "sudo port -t clean dports/python/py-" + \
</span><span class="cx"> name + " subport=py" + portv + "-" + name
</span><span class="cx"> command = command.split()
</span><del>- phase_output = subprocess.check_call(command, stderr=subprocess.STDOUT)
</del><ins>+ subprocess.check_call(command, stderr=subprocess.STDOUT)
</ins><span class="cx"> return True
</span><span class="cx"> except:
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</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 """
-
-
</del><span class="cx"> def create_portfile(dict, file_name, dict2):
</span><ins>+ """ Creates a portfile on the basis of the release_data and release_url fetched
+ on the basis of package_name and package_version """
</ins><span class="cx"> search_distfile(dict['name'], dict['version'])
</span><del>- print "Creating Portfile for pypi package " + dict['name'] + "..."
</del><ins>+ print("Creating Portfile for pypi package " + dict['name'] + "...")
</ins><span class="cx"> with open(file_name, 'w') as file:
</span><span class="cx"> file.write('# -*- coding: utf-8; mode: tcl; tab-width: 4; ')
</span><span class="cx"> file.write('indent-tabs-mode: nil; c-basic-offset: 4 ')
</span><span class="lines">@@ -475,8 +421,8 @@
</span><span class="cx"> file.write('maintainers {0}\n\n'.format(
</span><span class="cx"> os.getenv('maintainer', 'nomaintainer')))
</span><span class="cx"> else:
</span><del>- print "No maintainers found..."
- print "Looking for maintainers in environment variables..."
</del><ins>+ print("No maintainers found...")
+ print("Looking for maintainers in environment variables...")
</ins><span class="cx"> file.write('maintainers {0}\n\n'.format(
</span><span class="cx"> os.getenv('maintainer', 'nomaintainer')))
</span><span class="cx">
</span><span class="lines">@@ -499,7 +445,7 @@
</span><span class="cx"> file.write("{0} \\\n".format(sum_line))
</span><span class="cx"> else:
</span><span class="cx"> file.write('description None\n\n')
</span><del>- description = dict['description']
</del><ins>+# description = dict['description']
</ins><span class="cx"> # if description:
</span><span class="cx"> # description = description.encode('utf-8')
</span><span class="cx"> # description = filter(lambda x: x in string.printable, description)
</span><span class="lines">@@ -526,8 +472,8 @@
</span><span class="cx"> if home_page and not home_page == 'UNKNOWN':
</span><span class="cx"> file.write('homepage {0}\n'.format(home_page))
</span><span class="cx"> else:
</span><del>- print "No homepage found..."
- print "Looking for homepage in environment variables..."
</del><ins>+ print("No homepage found...")
+ print("Looking for homepage in environment variables...")
</ins><span class="cx"> file.write('homepage {0}\n'.format(
</span><span class="cx"> os.getenv('home_page', '')))
</span><span class="cx">
</span><span class="lines">@@ -541,8 +487,8 @@
</span><span class="cx"> # sys.exit(1)
</span><span class="cx">
</span><span class="cx"> try:
</span><del>-# print dict2
-# print dict2['url']
</del><ins>+ # print dict2
+ # print dict2['url']
</ins><span class="cx"> for item in dict2:
</span><span class="cx"> if item['python_version'] == 'source':
</span><span class="cx"> master_var = item['url']
</span><span class="lines">@@ -560,8 +506,8 @@
</span><span class="cx"> master_site = dict['release_url']
</span><span class="cx"> # print master_site
</span><span class="cx"> else:
</span><del>- print "No master site found..."
- print "Looking for master site in environment variables..."
</del><ins>+ print("No master site found...")
+ print("Looking for master site in environment variables...")
</ins><span class="cx"> master_site = os.getenv('master_site', '')
</span><span class="cx"> if master_site:
</span><span class="cx"> file.write('master_sites {0}\n'.format(master_site))
</span><span class="lines">@@ -576,7 +522,7 @@
</span><span class="cx"> file.write('distname {0}-{1}\n\n'.format(
</span><span class="cx"> dict['name'], dict['version']))
</span><span class="cx">
</span><del>- print "Attempting to generate checksums for " + dict['name'] + "..."
</del><ins>+ print("Attempting to generate checksums for " + dict['name'] + "...")
</ins><span class="cx"> checksums_values = checksums(dict['name'], dict['version'])
</span><span class="cx"> if checksums_values:
</span><span class="cx"> file.write('checksums rmd160 {0} \\\n'.format(
</span><span class="lines">@@ -591,16 +537,16 @@
</span><span class="cx"> else:
</span><span class="cx"> file.write('python.versions 25 26 27 32 33 34\n\n')
</span><span class="cx">
</span><del>- print "Finding dependencies..."
</del><ins>+ print("Finding dependencies...")
</ins><span class="cx"> file.write('if {${name} ne ${subport}} {\n')
</span><span class="cx"> file.write(' depends_build-append \\\n')
</span><span class="cx"> file.write(' ' +
</span><span class="cx"> 'port:py${python.version}-setuptools\n')
</span><span class="cx"> deps = dependencies(dict['name'], dict['version'], True)
</span><span class="cx"> if deps:
</span><del>- for i,dep in enumerate(deps):
</del><ins>+ for i, dep in enumerate(deps):
</ins><span class="cx"> dep = dep.split('>')[0].split('=')[0]
</span><del>- dep = dep.replace('[','').replace(']','')
</del><ins>+ dep = dep.replace('[', '').replace(']', '')
</ins><span class="cx"> deps[i] = dep
</span><span class="cx"> # print deps
</span><span class="cx"> for dep in deps:
</span><span class="lines">@@ -639,29 +585,27 @@
</span><span class="cx"> file.write('}\n')
</span><span class="cx"> else:
</span><span class="cx"> file.write('}\n')
</span><del>- print "Searching for existent port..."
</del><ins>+ print("Searching for existent port...")
</ins><span class="cx"> port_exists = search_port(dict['name'])
</span><span class="cx"> if port_exists:
</span><del>- print "Creating diff..."
</del><ins>+ print("Creating diff...")
</ins><span class="cx"> old_file = port_exists
</span><span class="cx"> new_file = './dports/python/py-'+dict['name']+'/Portfile'
</span><span class="cx"> diff_file = './dports/python/py-'+dict['name']+'/patch.Portfile.diff'
</span><span class="cx"> create_diff(old_file, new_file, diff_file)
</span><del>- print str(os.path.abspath(diff_file))+"\n"
</del><ins>+ print(str(os.path.abspath(diff_file))+"\n")
</ins><span class="cx"> # with open(diff_file) as diff:
</span><span class="cx"> # print diff.read()
</span><del>- 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."
</del><ins>+ 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.")
</ins><span class="cx"> else:
</span><del>- print "No port found."
</del><ins>+ print("No port found.")
</ins><span class="cx">
</span><span class="cx">
</span><del>-""" Creates the directories and other commands necessary
- for a development environment """
-
-
</del><span class="cx"> def print_portfile(pkg_name, pkg_version=None):
</span><ins>+ """ Creates the directories and other commands necessary
+ for a development environment """
</ins><span class="cx"> root_dir = os.path.abspath("./dports")
</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">@@ -678,28 +622,26 @@
</span><span class="cx"> if not os.path.exists(home_dir):
</span><span class="cx"> os.makedirs(home_dir)
</span><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><span class="cx"> dict = client.release_data(pkg_name, pkg_version)
</span><span class="cx"> dict2 = client.release_urls(pkg_name, pkg_version)
</span><span class="cx"> if dict and dict2:
</span><del>- print "Data fetched successfully."
</del><ins>+ print("Data fetched successfully.")
</ins><span class="cx"> elif dict:
</span><del>- print "Release Data fetched successfully."
</del><ins>+ print("Release Data fetched successfully.")
</ins><span class="cx"> elif dict2:
</span><del>- print "Release url fetched successfully."
</del><ins>+ print("Release url fetched successfully.")
</ins><span class="cx"> else:
</span><del>- print "No data found."
</del><ins>+ print("No data found.")
</ins><span class="cx">
</span><span class="cx"> file_name = os.path.join(home_dir, "Portfile")
</span><span class="cx"> create_portfile(dict, file_name, dict2)
</span><del>- print "SUCCESS\n"
</del><ins>+ print("SUCCESS\n")
</ins><span class="cx">
</span><span class="cx">
</span><del>-""" Main function - Argument Parser """
-
-
</del><span class="cx"> def main(argv):
</span><ins>+ """ Main function - Argument Parser """
</ins><span class="cx"> parser = argparse.ArgumentParser(description="Pypi2Port Tester")
</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 class="lines">@@ -731,13 +673,11 @@
</span><span class="cx"> list_all()
</span><span class="cx"> return
</span><span class="cx">
</span><del>-
</del><span class="cx"> if options.packages_search:
</span><span class="cx"> for pkg_name in options.packages_search:
</span><span class="cx"> search(pkg_name)
</span><span class="cx"> return
</span><span class="cx">
</span><del>-
</del><span class="cx"> if options.packages_data:
</span><span class="cx"> pkg_name = options.packages_data[0]
</span><span class="cx"> if len(options.packages_data) > 1:
</span><span class="lines">@@ -748,10 +688,9 @@
</span><span class="cx"> pkg_version = client.package_releases(pkg_name)[0]
</span><span class="cx"> release_data(pkg_name, pkg_version)
</span><span class="cx"> else:
</span><del>- print "No release found\n"
</del><ins>+ print("No release found\n")
</ins><span class="cx"> return
</span><span class="cx">
</span><del>-
</del><span class="cx"> if options.package_fetch:
</span><span class="cx"> pkg_name = options.package_fetch[0]
</span><span class="cx"> if len(options.package_fetch) > 1:
</span><span class="lines">@@ -763,10 +702,9 @@
</span><span class="cx"> pkg_version = releases[0]
</span><span class="cx"> fetch_url(pkg_name, pkg_version)
</span><span class="cx"> else:
</span><del>- print "No release found\n"
</del><ins>+ print("No release found\n")
</ins><span class="cx"> return
</span><span class="cx">
</span><del>-
</del><span class="cx"> if options.package_portfile:
</span><span class="cx"> pkg_name = options.package_portfile[0]
</span><span class="cx"> if len(options.package_portfile) > 1:
</span><span class="lines">@@ -778,16 +716,15 @@
</span><span class="cx"> pkg_version = vers[0]
</span><span class="cx"> print_portfile(pkg_name, pkg_version)
</span><span class="cx"> else:
</span><del>- print "No release found\n"
</del><ins>+ print("No release found\n")
</ins><span class="cx"> return
</span><span class="cx">
</span><del>-
</del><span class="cx"> if options.package_test:
</span><span class="cx"> if len(options.package_test) > 0:
</span><span class="cx"> pkg_name = options.package_test[0]
</span><span class="cx"> port_testing(pkg_name)
</span><span class="cx"> else:
</span><del>- print "No package name specified\n"
</del><ins>+ print("No package name specified\n")
</ins><span class="cx"> return
</span><span class="cx">
</span><span class="cx"> parser.print_help()
</span></span></pre>
</div>
</div>
</body>
</html>