2012-07-05 04:21:49 -04:00
|
|
|
from os import walk, remove
|
2012-07-09 03:02:52 -04:00
|
|
|
from os.path import sep, join, exists, normpath
|
2012-08-02 17:28:49 -04:00
|
|
|
from re import findall, sub
|
2012-07-10 05:39:45 -04:00
|
|
|
from distutils.core import setup
|
|
|
|
from distutils.command.install import install
|
|
|
|
from pprint import pprint
|
|
|
|
from fileinput import FileInput
|
|
|
|
from re import sub, match
|
2012-07-05 04:21:49 -04:00
|
|
|
|
2012-07-16 04:56:04 -04:00
|
|
|
from Configuration import *
|
2012-07-05 04:21:49 -04:00
|
|
|
|
|
|
|
class Setup:
|
|
|
|
|
2012-07-09 03:02:52 -04:00
|
|
|
config = Configuration()
|
2012-08-02 17:28:49 -04:00
|
|
|
manifest_path = "MANIFEST"
|
2012-07-05 04:21:49 -04:00
|
|
|
|
2012-08-24 22:51:43 -04:00
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
2012-07-05 04:21:49 -04:00
|
|
|
def remove_old_mainfest(self):
|
2012-08-02 17:28:49 -04:00
|
|
|
path = self.manifest_path
|
2012-07-05 04:21:49 -04:00
|
|
|
if exists(path):
|
|
|
|
remove(path)
|
|
|
|
|
|
|
|
def build_package_list(self):
|
|
|
|
packages = []
|
2012-08-25 17:33:43 -04:00
|
|
|
config = self.config.get_section("setup")
|
|
|
|
locations = [config["package-root"]] + config["additional-packages"]
|
2012-08-25 00:46:05 -04:00
|
|
|
for location in locations:
|
|
|
|
if exists(location):
|
|
|
|
for root, dirs, files in walk(location, followlinks=True):
|
|
|
|
packages.append(root.replace(sep, "."))
|
2012-07-05 04:21:49 -04:00
|
|
|
return packages
|
|
|
|
|
2012-07-10 05:39:45 -04:00
|
|
|
def build_data_map(self):
|
2012-07-07 02:26:29 -04:00
|
|
|
include = []
|
2012-07-09 02:16:59 -04:00
|
|
|
config = self.config.get_section("setup")
|
2012-07-09 03:02:52 -04:00
|
|
|
exclude = map(normpath, config["data-exclude"])
|
2012-07-05 04:21:49 -04:00
|
|
|
for root, dirs, files in walk("."):
|
2012-07-10 05:39:45 -04:00
|
|
|
dirs = self.remove_excluded(dirs, root, exclude)
|
|
|
|
files = [join(root, f) for f in self.remove_excluded(files, root,
|
|
|
|
exclude)]
|
|
|
|
if files:
|
|
|
|
include.append((normpath(join(config["installation-path"],
|
|
|
|
root)), files))
|
2012-07-05 04:21:49 -04:00
|
|
|
return include
|
|
|
|
|
2012-07-10 05:39:45 -04:00
|
|
|
def remove_excluded(self, paths, root, exclude):
|
2012-07-09 03:02:52 -04:00
|
|
|
removal = []
|
2012-07-10 05:39:45 -04:00
|
|
|
for path in paths:
|
|
|
|
if normpath(join(root, path)) in exclude:
|
|
|
|
removal.append(path)
|
|
|
|
for path in removal:
|
|
|
|
paths.remove(path)
|
|
|
|
return paths
|
2012-07-09 03:02:52 -04:00
|
|
|
|
2012-07-05 04:21:49 -04:00
|
|
|
def translate_title(self):
|
2012-08-02 17:28:49 -04:00
|
|
|
config = self.config.get_section("setup")
|
|
|
|
title = config["title"].replace(" ", config["whitespace-placeholder"])
|
|
|
|
return sub("[^\w-]", config["special-char-placeholder"], title)
|
2012-07-05 04:21:49 -04:00
|
|
|
|
|
|
|
def build_description(self):
|
2012-07-10 05:39:45 -04:00
|
|
|
description = ""
|
|
|
|
path = self.config.get("setup", "description-file")
|
|
|
|
if exists(path):
|
2012-12-23 05:20:36 -05:00
|
|
|
description = "\n%s\n%s\n%s" % (file(path).read(),
|
|
|
|
"Changelog\n=========",
|
|
|
|
self.translate_changelog())
|
2012-07-10 05:39:45 -04:00
|
|
|
return description
|
2012-07-05 04:21:49 -04:00
|
|
|
|
|
|
|
def translate_changelog(self):
|
|
|
|
translation = ""
|
2012-07-09 04:43:39 -04:00
|
|
|
path = self.config.get("setup", "changelog")
|
|
|
|
if exists(path):
|
|
|
|
lines = file(path).readlines()
|
|
|
|
package_name = lines[0].split()[0]
|
|
|
|
for line in lines:
|
|
|
|
line = line.strip()
|
|
|
|
if line.startswith(package_name):
|
|
|
|
version = findall("\((.*)\)", line)[0]
|
|
|
|
translation += "\n%s\n%s\n" % (version, "-" * len(version))
|
|
|
|
elif line and not line.startswith("--"):
|
|
|
|
if line.startswith("*"):
|
|
|
|
translation += line + "\n"
|
|
|
|
else:
|
|
|
|
translation += " " + line + "\n"
|
2012-07-05 04:21:49 -04:00
|
|
|
return translation
|
2012-07-10 05:39:45 -04:00
|
|
|
|
2012-08-24 22:51:43 -04:00
|
|
|
def setup(self, windows=[], options={}):
|
2012-08-25 05:51:37 -04:00
|
|
|
print "running setup..."
|
2012-08-02 17:28:49 -04:00
|
|
|
self.remove_old_mainfest()
|
2012-07-10 05:39:45 -04:00
|
|
|
config = self.config.get_section("setup")
|
2012-08-25 16:24:40 -04:00
|
|
|
scripts = []
|
|
|
|
if config["init-script"]:
|
|
|
|
scripts.append(config["init-script"])
|
2012-07-10 05:39:45 -04:00
|
|
|
setup(cmdclass={"install": insert_resources_path},
|
|
|
|
name=self.translate_title(),
|
|
|
|
packages=self.build_package_list(),
|
2012-08-25 16:24:40 -04:00
|
|
|
scripts=scripts,
|
2012-07-10 05:39:45 -04:00
|
|
|
data_files=self.build_data_map(),
|
|
|
|
requires=config["requirements"],
|
|
|
|
version=config["version"],
|
|
|
|
description=config["summary"],
|
|
|
|
classifiers=config["classifiers"],
|
|
|
|
long_description=self.build_description(),
|
|
|
|
license=config["license"],
|
|
|
|
platforms=config["platforms"],
|
|
|
|
author=config["contact-name"],
|
|
|
|
author_email=config["contact-email"],
|
2012-08-25 05:51:37 -04:00
|
|
|
url=config["url"],
|
|
|
|
windows=windows,
|
|
|
|
options=options)
|
2012-07-10 05:39:45 -04:00
|
|
|
|
|
|
|
|
|
|
|
class insert_resources_path(install):
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
install.run(self)
|
|
|
|
self.edit_game_object_file()
|
|
|
|
|
|
|
|
def edit_game_object_file(self):
|
|
|
|
config = Configuration().get_section("setup")
|
|
|
|
for path in self.get_outputs():
|
|
|
|
if path.endswith(config["main-object"]):
|
|
|
|
for line in FileInput(path, inplace=True):
|
|
|
|
pattern = "^ *{0} *=.*".\
|
|
|
|
format(config["resources-path-identifier"])
|
|
|
|
if match(pattern, line):
|
|
|
|
line = sub("=.*$", "= \"{0}\"".\
|
|
|
|
format(config["installation-path"]), line)
|
|
|
|
print line.strip("\n")
|