Commit c36cd5eb authored by arbennett's avatar arbennett
Browse files

Adding python3 support to installer.

parent 8a93732c
......@@ -12,15 +12,16 @@
# The Python ICE Installer
# ******************************************************************************
from __future__ import print_function
import os
import sys
import glob
import time
import stat
import errno
import shutil
import tarfile
import zipfile
import urllib2
import fnmatch
import platform
import datetime
......@@ -28,6 +29,12 @@ import argparse
import itertools
import subprocess
if sys.version_info >= (3,0):
import urllib.request as urllib2
else:
import urllib2
def parse_args(args):
""" Parse command line arguments and return them. """
parser = argparse.ArgumentParser(description="ICE Installer script.",
......@@ -163,11 +170,12 @@ def download_packages(opts, os_type, arch_type):
fname = get_package_file(pkg, os_type, arch_type)
files[pkg] = fname
if not opts.skip_download:
print "Downloading " + pkg + ":",
print("Downloading " + pkg + ":")
url = package_urls[pkg] + fname
u = urllib2.urlopen(url)
f = open(fname, 'wb')
fsize = int(u.info().getheaders("Content-length")[0])
info = {k.lower():v for k,v in dict(u.info()).items()}
fsize = int(info['content-length'])
dl_size = 0
block = 8192
while True:
......@@ -175,10 +183,10 @@ def download_packages(opts, os_type, arch_type):
if not buffer: break
dl_size += len(buffer)
f.write(buffer)
status = r"%5.2f%% complete" % (dl_size * 100. / fsize)
status = r" %5.2f%%" % (dl_size * 100. / fsize)
status = status + chr(8)*(len(status)+1)
print status,
print ""
print(status,end='')
print("")
return files
......@@ -200,7 +208,9 @@ def untar_package(pkg, file_path, out_path):
print("Unpacking " + file_path + "....")
mkdir_p(out_path)
pkg = tarfile.open(file_path)
dir_name = pkg.getnames()[0]
dir_name = os.path.commonprefix(pkg.getnames())
if os.path.isdir(os.path.join(out_path, dir_name)):
shutil.rmtree(os.path.join(out_path,dir_name))
pkg.extractall(out_path)
pkg.close()
return dir_name
......@@ -221,7 +231,7 @@ def undmg_package(pkg, file_path, out_path):
content = find_dir(mnt_point, "Resources")
if content is None:
return
print " Copying " + content + " to " + os.path.join(out_path,pkg) + "...."
print(" Copying " + content + " to " + os.path.join(out_path,pkg) + "....")
if os.path.exists(os.path.join(out_path, pkg)):
shutil.rmtree(os.path.join(out_path, pkg))
shutil.copytree(content, os.path.join(out_path,pkg))
......@@ -232,7 +242,7 @@ def undmg_package(pkg, file_path, out_path):
def unpack_packages(opts, pkg_files):
""" Delegates unpacking of packages """
dirs = dict()
for pkg, archive in pkg_files.iteritems():
for pkg, archive in pkg_files.items():
if archive.endswith(".tar.gz") or archive.endswith(".tgz") or archive.endswith(".tar"):
dirs[pkg] = untar_package(pkg, archive, opts.prefix)
elif archive.endswith(".zip"):
......@@ -338,7 +348,6 @@ def windows_install(opts, pkg_dirs):
if "HDFJava" in pkg_dirs.keys():
print("Installing HDFJava...")
install_script = find_file(opts.prefix, "HDFView*.exe")
print install_script
install_cmd = [install_script]
subprocess.call(install_cmd, shell=True)
......@@ -383,9 +392,16 @@ def linux_post(opts, pkgs):
f.write(urllib2.urlopen('https://raw.githubusercontent.com/eclipse/ice/master/org.eclipse.ice.client.rcp/splash.bmp').read())
if 'SUDO_USER' in os.environ:
user = os.environ['SUDO_USER']
os.chmod(os.path.join(opts.prefix, "ICE"), 0755)
else:
user = os.environ['USER']
os.chmod(os.path.join(opts.prefix, "ICE"), stat.S_IXUSR | \
stat.S_IRUSR | \
stat.S_IWUSR | \
stat.S_IRGRP | \
stat.S_IWGRP | \
stat.S_IROTH | \
stat.S_IWOTH)
mkdir_p(os.path.join('/home', user, ".local", "share", "applications"))
with open(os.path.join('/home', user, ".local", "share", "applications","ICE.desktop"),'w') as f:
f.write("[Desktop Entry]")
......@@ -414,7 +430,7 @@ def osx_post(opts, pkgs):
f.write('\nexport DYLD_LIBRARY_PATH=' + visit_libdir + ':$DYLD_LIBRARY_PATH')
f.write('\nexec `dirname $0`/ICE $0')
f.write('\n')
os.chmod(os.path.join(opts.prefix, "ICE.app", "Contents", "MacOS", "ice.sh"), 0755)
os.chmod(os.path.join(opts.prefix, "ICE.app", "Contents", "MacOS", "ice.sh"), stat.S_IXUSR)
ice_preferences = find_file(opts.prefix, 'ICE.ini')
with open(ice_preferences, 'a') as f:
f.write("\n-Xdock:name=Eclipse ICE")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment