
import os
import stat
import zipfile
import StringIO

package_dir = 'xyppy'
python_directive = '#!/usr/bin/env python'

packed = StringIO.StringIO()
packed_writer = zipfile.ZipFile(packed, 'w', zipfile.ZIP_DEFLATED)
for fname in os.listdir(package_dir):
    fpath = os.path.join(package_dir, fname)
    if os.path.isfile(fpath):
        packed_writer.write(fpath)
packed_writer.writestr('__main__.py', '''
from xyppy import __main__
if __name__ == '__main__':
    __main__.main()
''')
packed_writer.close()

pyfile = package_dir + '.py'
with open(pyfile, 'wb') as f:
    f.write(python_directive + '\n')
    f.write(packed.getvalue())
os.chmod(pyfile, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)


import os
import stat
import zipfile

try:
    from StringIO import StringIO
except ImportError:
    from io import BytesIO as StringIO

package_dir = 'xyppy'
python_directive = '#!/usr/bin/env python'

packed = StringIO()
packed_writer = zipfile.ZipFile(packed, 'w', zipfile.ZIP_DEFLATED)
for fname in os.listdir(package_dir):
    fpath = os.path.join(package_dir, fname)
    if os.path.isfile(fpath):
        packed_writer.write(fpath)
packed_writer.writestr('__main__.py', '''
from xyppy import __main__
if __name__ == '__main__':
    __main__.main()
''')
packed_writer.close()

pyfile = package_dir + '.py'
with open(pyfile, 'wb') as f:
    shebang = bytes((python_directive + '\n').encode('ascii'))
    f.write(shebang)
    f.write(packed.getvalue())
os.chmod(pyfile, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)

Make the build script P2/3 compatible
Make the build script P2/3 compatible

  
  import os
  import stat
  import zipfile
- import StringIO
+ 
+ try:
+     from StringIO import StringIO
+ except ImportError:
+     from io import BytesIO as StringIO
  
  package_dir = 'xyppy'
  python_directive = '#!/usr/bin/env python'
  
- packed = StringIO.StringIO()
+ packed = StringIO()
  packed_writer = zipfile.ZipFile(packed, 'w', zipfile.ZIP_DEFLATED)
  for fname in os.listdir(package_dir):
      fpath = os.path.join(package_dir, fname)
      if os.path.isfile(fpath):
          packed_writer.write(fpath)
  packed_writer.writestr('__main__.py', '''
  from xyppy import __main__
  if __name__ == '__main__':
      __main__.main()
  ''')
  packed_writer.close()
  
  pyfile = package_dir + '.py'
  with open(pyfile, 'wb') as f:
-     f.write(python_directive + '\n')
+     shebang = bytes((python_directive + '\n').encode('ascii'))
+     f.write(shebang)
      f.write(packed.getvalue())
  os.chmod(pyfile, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)
  
Make the build script P2/3 compatible
## Code Before:

import os
import stat
import zipfile
import StringIO

package_dir = 'xyppy'
python_directive = '#!/usr/bin/env python'

packed = StringIO.StringIO()
packed_writer = zipfile.ZipFile(packed, 'w', zipfile.ZIP_DEFLATED)
for fname in os.listdir(package_dir):
    fpath = os.path.join(package_dir, fname)
    if os.path.isfile(fpath):
        packed_writer.write(fpath)
packed_writer.writestr('__main__.py', '''
from xyppy import __main__
if __name__ == '__main__':
    __main__.main()
''')
packed_writer.close()

pyfile = package_dir + '.py'
with open(pyfile, 'wb') as f:
    f.write(python_directive + '\n')
    f.write(packed.getvalue())
os.chmod(pyfile, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)

## Instruction:
Make the build script P2/3 compatible
## Code After:

import os
import stat
import zipfile

try:
    from StringIO import StringIO
except ImportError:
    from io import BytesIO as StringIO

package_dir = 'xyppy'
python_directive = '#!/usr/bin/env python'

packed = StringIO()
packed_writer = zipfile.ZipFile(packed, 'w', zipfile.ZIP_DEFLATED)
for fname in os.listdir(package_dir):
    fpath = os.path.join(package_dir, fname)
    if os.path.isfile(fpath):
        packed_writer.write(fpath)
packed_writer.writestr('__main__.py', '''
from xyppy import __main__
if __name__ == '__main__':
    __main__.main()
''')
packed_writer.close()

pyfile = package_dir + '.py'
with open(pyfile, 'wb') as f:
    shebang = bytes((python_directive + '\n').encode('ascii'))
    f.write(shebang)
    f.write(packed.getvalue())
os.chmod(pyfile, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)
