Commits

illume  committed 388b087

Converted all of the source with the help of 2to3 and compat library.

  • Participants
  • Parent commits a586e0a

Comments (0)

Files changed (8)

File bdist_mpkg/cmd_bdist_mpkg.py

 
 from bdist_mpkg import pkg, tools, plists
 from bdist_mpkg.util import copy_tree
-from bdist_mpkg.compat import _unicode
+from bdist_mpkg.compat import unicode_
 
 
 
 INSTALL_SCHEME_DESCRIPTIONS = dict(
-    purelib = _unicode('(Required) Pure Python modules and packages'),
-    platlib = _unicode('(Required) Python modules, extensions, and packages'),
-    headers = _unicode('(Optional) Header files for development'),
-    scripts = _unicode('(Optional) Scripts to use from the Unix shell'),
-    data    = _unicode('(Optional) Additional data files (sometimes documentation)'),
+    purelib = unicode_('(Required) Pure Python modules and packages'),
+    platlib = unicode_('(Required) Python modules, extensions, and packages'),
+    headers = unicode_('(Optional) Header files for development'),
+    scripts = unicode_('(Optional) Scripts to use from the Unix shell'),
+    data    = unicode_('(Optional) Additional data files (sometimes documentation)'),
 )
 
 class bdist_mpkg (Command):
             return None
         files, common, prefix = self.get_scheme_root(scheme)
         if prefix is not None:
-            description += _unicode('\nInstalled to: ' + tools.unicode_path(prefix))
+            description += unicode_('\nInstalled to: ' + tools.unicode_path(prefix))
         return description
 
     def get_metapackage(self):

File bdist_mpkg/compat.py

     bytes_ = str
 
 try:
+    basestring_ = basestring
+except NameError:
+    basestring_ = str
+
+try:
     raw_input_ = raw_input
 except NameError:
     raw_input_ = input

File bdist_mpkg/pkg.py

 from bdist_mpkg.templates import InstallationCheck
 
 from bdist_mpkg.compat import get_StringIO
-from bdist_mpkg.compat import _unicode
+from bdist_mpkg.compat import unicode_
 StringIO = get_StringIO()
 
 
     if description is None:
         description = dist.get_description()
     if not description:
-        description = _unicode('%s %s' % (name, version))
+        description = unicode_('%s %s' % (name, version))
 
     mkpath(os.path.join(pkgdir, 'Contents', 'Resources'))
     if not dry_run:
         write_sizes(count, size, compressed, pkgdir)
 
     if admin:
-        auth = _unicode('AdminAuthorization')
+        auth = unicode_('AdminAuthorization')
     else:
-        auth = _unicode('RootAuthorization')
+        auth = unicode_('RootAuthorization')
 
     ninfo = plists.pkg_info(name, version)
     ninfo.update(dict(

File bdist_mpkg/plists.py

 
 import bdist_mpkg
 from bdist_mpkg import tools
+from bdist_mpkg.compat import unicode_
+from bdist_mpkg.compat import basestring_
 
 def _major_minor(v):
     rval = [0, 0]
 
 def common_info(name, version):
     # Keys that can appear in any package
-    name, version = unicode(name), tools.Version(version)
+    name, version = unicode_(name), tools.Version(version)
     major, minor = _major_minor(version)
     return dict(
-        CFBundleGetInfoString=u'%s %s' % (name, version),
-        CFBundleIdentifier=u'org.pythonmac.%s' % (name,),
+        CFBundleGetInfoString=unicode_('%s %s' % (name, version)),
+        CFBundleIdentifier=unicode_('org.pythonmac.%s' % (name,)),
         CFBundleName=name,
-        CFBundleShortVersionString=unicode(version),
+        CFBundleShortVersionString=unicode_(version),
         IFMajorVersion=major,
         IFMinorRevision=minor,
         IFPkgFormatVersion=0.10000000149011612,
-        IFRequirementDicts=[path_requirement(u'/')],
+        IFRequirementDicts=[path_requirement(unicode_('/'))],
         PythonInfoDict=dict(
-            PythonLongVersion=unicode(sys.version),
-            PythonShortVersion=unicode(sys.version[:3]),
-            PythonExecutable=unicode(sys.executable),
+            PythonLongVersion=unicode_(sys.version),
+            PythonShortVersion=unicode_(sys.version[:3]),
+            PythonExecutable=unicode_(sys.executable),
             bdist_mpkg=dict(
-                version=unicode(bdist_mpkg.__version__),
+                version=unicode_(bdist_mpkg.__version__),
             ),
         ),
     )
     # Keys that can only appear in single packages
     d.update(dict(
         IFPkgFlagAllowBackRev=False,
-        IFPkgFlagAuthorizationAction=u'AdminAuthorization',
-        #IFPkgFlagDefaultLocation=u'/Library/Python/2.3',
+        IFPkgFlagAuthorizationAction=unicode_('AdminAuthorization'),
+        #IFPkgFlagDefaultLocation=unicode_('/Library/Python/2.3'),
         IFPkgFlagFollowLinks=True,
         IFPkgFlagInstallFat=False,
         IFPkgFlagIsRequired=False,
         IFPkgFlagOverwritePermissions=False,
         IFPkgFlagRelocatable=False,
-        IFPkgFlagRestartAction=u'NoRestart',
+        IFPkgFlagRestartAction=unicode_('NoRestart'),
         IFPkgFlagRootVolumeOnly=True,
         IFPkgFlagUpdateInstalledLangauges=False,
     ))
     return d
 
-def path_requirement(SpecArgument, Level=u'requires', **kw):
+def path_requirement(SpecArgument, Level=unicode_('requires'), **kw):
     return dict(
         Level=Level,
-        SpecType=u'file',
-        SpecArgument=tools.unicode_path(SpecArgument),
-        SpecProperty=u'NSFileType',
-        TestOperator=u'eq',
-        TestObject=u'NSFileTypeDirectory',
+        SpecType=unicode_('file'),
+        SpecArgument=tools.unicode__path(SpecArgument),
+        SpecProperty=unicode_('NSFileType'),
+        TestOperator=unicode_('eq'),
+        TestObject=unicode_('NSFileTypeDirectory'),
         **kw
     )
 
 FRIENDLY_PREFIX = {
-    os.path.expanduser(u'~/Library/Frameworks') : u'User',
-    u'/System/Library/Frameworks' : u'Apple',
-    u'/Library/Frameworks' : u'python.org',
-    u'/opt/local' : u'DarwinPorts',
-    u'/usr/local' : u'Unix',
-    u'/sw' : u'Fink',
+    os.path.expanduser(unicode_('~/Library/Frameworks')) : unicode_('User'),
+    unicode_('/System/Library/Frameworks') : unicode_('Apple'),
+    unicode_('/Library/Frameworks') : unicode_('python.org'),
+    unicode_('/opt/local') : unicode_('DarwinPorts'),
+    unicode_('/usr/local') : unicode_('Unix'),
+    unicode_('/sw') : unicode_('Fink'),
 }
 
 def python_requirement(pkgname, prefix=None, version=None, **kw):
         dprefix = os.path.dirname(fmwkprefix)
     else:
         dprefix = prefix
-    dprefix = tools.unicode_path(dprefix)
-    name = u'%s Python %s' % (FRIENDLY_PREFIX.get(dprefix, dprefix), version)
+    dprefix = tools.unicode__path(dprefix)
+    name = unicode_('%s Python %s') % (FRIENDLY_PREFIX.get(dprefix, dprefix), version)
     kw.setdefault('LabelKey', name)
-    title = u'%s requires %s to install.' % (pkgname, name,)
+    title = unicode_('%s requires %s to install.' % (pkgname, name,))
     kw.setdefault('TitleKey', title)
     kw.setdefault('MessageKey', title)
     return path_requirement(prefix, **kw)
         if items is not None:
             p = dict(items())
         else:
-            if isinstance(p, basestring):
+            if isinstance(p, basestring_):
                 p = [p]
-            p = dict(zip(
-                (u'IFPkgFlagPackageLocation', u'IFPkgFlagPackageSelection'),
+            p = dict(list(zip(
+                (unicode_('IFPkgFlagPackageLocation', unicode_('IFPkgFlagPackageSelection'))),
                 p
-            ))
+            )))
         npackages.append(p)
     d.update(dict(
-        IFPkgFlagComponentDirectory=u'./Contents/Packages',
+        IFPkgFlagComponentDirectory=unicode_('./Contents/Packages'),
         IFPkgFlagPackageList=npackages,
     ))
     return d
 
 def checkpath_plugin(path):
-    if not isinstance(path, unicode):
-        path = unicode(path, encoding)
+    if not isinstance(path, unicode_):
+        path = unicode_(path, encoding)
     return dict(
-        searchPlugin=u'CheckPath',
+        searchPlugin=unicode_('CheckPath'),
         path=path,
     )
 
 def common_description(name, version):
-    name, version = unicode(name), tools.Version(version)
+    name, version = unicode_(name), tools.Version(version)
     return dict(
         IFPkgDescriptionTitle=name,
-        IFPkgDescriptionVersion=unicode(version),
+        IFPkgDescriptionVersion=unicode_(version),
     )
 
 def write(dct, path):

File bdist_mpkg/script_bdist_mpkg.py

     g = dict(globals())
     g['__file__'] = sys.argv[0]
     g['__name__'] = '__main__'
-    execfile(sys.argv[0], g, g)
+
+    try:
+        #python3 does not have execfile
+        execfile_ = execfile
+        execfile_(sys.argv[0], g, g)
+    except NameError:
+        exec(compile(open(sys.argv[0]).read(), sys.argv[0], 'exec'), g, g)
+    
 
 if __name__ == '__main__':
     main()

File bdist_mpkg/templates.py

+from bdist_mpkg.compat import unicode_
+
 InstallationCheck = dict(
     postjaguar=(
-        u"#!/bin/sh\nexit 112\n",
-        u'"16" = "This package requires Mac OS X 10.3 or later";',
+        unicode_("#!/bin/sh\nexit 112\n"),
+        unicode_('"16" = "This package requires Mac OS X 10.6 or later";'),
     ),
-    prepanther=(u"""#!/bin/sh
+    prepanther=(unicode_("""#!/bin/sh
 #
 # We use IFRequirementDicts anyway and "parse" it to find where expect
 # Python to be.  It's remotely possible that Python is not installed
 echo "Package: $1"
 echo "Expected path not found: $IPATH"
 exit 112
-""",
-        u'"16" = "This package requires MacPython to be installed";',
+"""),
+        unicode_('"16" = "This package requires MacPython to be installed";'),
     ),
 )

File bdist_mpkg/tools.py

 from distutils.dir_util import mkpath
 import distutils.core
 
+from bdist_mpkg.compat import unicode_
+
+
 try:
     set
 except NameError:
     try:
         return distutils.core.run_setup(*args, **kwargs)
     finally:
-        for k,v in d.iteritems():
+        for k,v in list(d.items()):
             setattr(distutils.core, k, v)
 
 def adminperms(src, verbose=0, dry_run=0):
     return os.stat(dest).st_size
 
 def unicode_path(path, encoding=sys.getfilesystemencoding()):
-    if isinstance(path, unicode):
+    if isinstance(path, unicode_):
         return path
-    return unicode(path, encoding)
+    return unicode_(path, encoding)
 
 def walk_files(path):
     for root, dirs, files in os.walk(path):
         path = os.path.dirname(path)
     s = os.stat(path)
     mode = s.st_mode
-    return (mode & 00002) or (s.st_gid == gid and mode & 00020)
+    #return (mode & 00002) or (s.st_gid == gid and mode & 00020)
+    return (mode & 2) or (s.st_gid == gid and mode & 16) # 00002 is 2, and 00020 is 16.
 
 def reduce_size(files):
     return sum([os.stat(fn).st_size for fn in files])

File bdist_mpkg/util.py

 import os, sys
+from bdist_mpkg.compat import unicode_
+from bdist_mpkg.compat import geterror
+
 try:
     set
 except NameError:
     from sets import Set as set
 
 def fsencoding(s, encoding=sys.getfilesystemencoding()):
-    if isinstance(s, unicode):
+    if isinstance(s, unicode_):
         s = s.encode(encoding)
     return s
 
             "cannot copy tree '%s': not a directory" % src)
     try:
         names = os.listdir(src)
-    except os.error, (errno, errstr):
+    #except os.error, (errno, errstr):
+    except os.error:
+        an_error = geterror()
         if dry_run:
             names = []
         else:
             raise DistutilsFileError("error listing files in '%s': %s" % (
-                src, errstr))
+                src, an_error))
 
     if not dry_run:
         mkpath(dst)