[122368] branches/gsoc14-pip2port/pypi2port.py

gaurav at macports.org gaurav at macports.org
Mon Jul 21 10:30:18 PDT 2014


Revision: 122368
          https://trac.macports.org/changeset/122368
Author:   gaurav at macports.org
Date:     2014-07-21 10:30:18 -0700 (Mon, 21 Jul 2014)
Log Message:
-----------
Changes by pixilla (unified diff etc.)

Modified Paths:
--------------
    branches/gsoc14-pip2port/pypi2port.py

Modified: branches/gsoc14-pip2port/pypi2port.py
===================================================================
--- branches/gsoc14-pip2port/pypi2port.py	2014-07-21 17:20:33 UTC (rev 122367)
+++ branches/gsoc14-pip2port/pypi2port.py	2014-07-21 17:30:18 UTC (rev 122368)
@@ -23,6 +23,7 @@
 import shutil
 import re
 import difflib
+import subprocess
 
 client = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
 
@@ -176,13 +177,10 @@
             print ""
         return False
 
-def create_diff(name, port):
-    diff_file = './dports/python/'+name+'/'+name+'.diff'
-    fromfile = './dports/python/'+name+'/Portfile'
-    tofile = '/opt/mports/trunk/dports/python/'+port+'/Portfile'
-    a = open(fromfile).readlines()
-    b = open(tofile).readlines()
-    diff_string = difflib.ndiff(a,b)
+def create_diff(old_file, new_file, diff_file):
+    a = open(old_file).readlines()
+    b = open(new_file).readlines()
+    diff_string = difflib.unified_diff(a,b,"Portfile.orig","Portfile")
     with open(diff_file, 'w') as d:
         try:
             while 1:
@@ -192,17 +190,12 @@
 
 
 def search_port(name):
-    for port in os.listdir('/opt/mports/trunk/dports/python'):
-        if '-' in port:
-            port = port.split('-')
-            prefix = port[0]
-            port = ''.join(port[1:])
-        if port == name:
-                if prefix:
-                    port = prefix+'-'+port
-                create_diff(name, port)
-                return True
-    return False
+    try:
+        command = "port file name:^py-" + name + "$"
+        existing_portfile = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT).strip()
+        return existing_portfile
+    except Exception, e:
+        return False
 
 def checksums(pkg_name, pkg_version):
     flag = False
@@ -362,10 +355,14 @@
             file.write('}\n')
         else:
             file.write('}\n')
+    port_exists = search_port(dict['name'])
+    if port_exists:
+        old_file = port_exists
+        new_file = './dports/python/'+dict['name']+'/Portfile'
+        diff_file = './dports/python/'+dict['name']+'/patch.Portfile.diff'
+        create_diff(old_file, new_file, diff_file)
 
-    search_port(dict['name'])
 
-
 def print_portfile(pkg_name, pkg_version=None):
     print "\n"
     root_dir = os.path.abspath("./dports")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140721/e72ec44b/attachment.html>


More information about the macports-changes mailing list