From d4ac59f25523b8812ca08e24b151e525a35951e4 Mon Sep 17 00:00:00 2001 From: Kyle MacFarlane Date: Mon, 21 Sep 2009 17:51:13 +0100 Subject: [PATCH] Added support for mklink on NT6 systems --- collective/recipe/omelette/__init__.py | 8 ++--- collective/recipe/omelette/utils.py | 59 +++++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/collective/recipe/omelette/__init__.py b/collective/recipe/omelette/__init__.py index aaba819..9482992 100644 --- a/collective/recipe/omelette/__init__.py +++ b/collective/recipe/omelette/__init__.py @@ -20,11 +20,9 @@ contents of a lists of eggs. See README.txt for details. """ import os -import sys -import shutil import logging import zc.recipe.egg -from collective.recipe.omelette.utils import symlink, unlink, islink, rmtree, WIN32 +from collective.recipe.omelette.utils import symlink, islink, rmtree, WIN32, NT6 NAMESPACE_STANZA = """# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages try: @@ -164,8 +162,8 @@ class Recipe(object): self.logger.warn("Warning: (While processing egg %s) Package '%s' not found. Skipping." % (project_name, package_name)) continue if not os.path.exists(link_location): - if WIN32 and not os.path.isdir(package_location): - self.logger.warn("Warning: (While processing egg %s) Can't link files on Windows (%s -> %s). Skipping." % (project_name, package_location, link_location)) + if WIN32 and not NT6 and not os.path.isdir(package_location): + self.logger.warn("Warning: (While processing egg %s) Can't link files on this version of Windows (%s -> %s). Skipping." % (project_name, package_location, link_location)) continue symlink(package_location, link_location) else: diff --git a/collective/recipe/omelette/utils.py b/collective/recipe/omelette/utils.py index 18414f1..2c07ece 100644 --- a/collective/recipe/omelette/utils.py +++ b/collective/recipe/omelette/utils.py @@ -1,8 +1,11 @@ import sys, os, shutil WIN32 = False +NT6 = False if sys.platform[:3].lower() == "win": WIN32 = True + if sys.getwindowsversion()[0] >= 6: + NT6 = True if WIN32: @@ -12,30 +15,54 @@ if WIN32: stdout.close() return output - # find the junction utility; warn if missing - JUNCTION = "junction.exe" - found = False - for path in os.environ['PATH'].split(';'): - if os.path.exists(os.path.join(path, JUNCTION)): - found = True - break - if not found: - raise EnvironmentError, "Junction.exe not found in path. Collective.recipe.omelette cannot continue. See omelette's README.txt." + if not NT6: + # find the junction utility; warn if missing + JUNCTION = "junction.exe" + found = False + for path in os.environ['PATH'].split(';'): + if os.path.exists(os.path.join(path, JUNCTION)): + found = True + break + if not found: + raise EnvironmentError, "Junction.exe not found in path. Collective.recipe.omelette cannot continue. See omelette's README.txt." def symlink(src, dest): - cmd = "%s %s %s" % (JUNCTION, os.path.abspath(dest), os.path.abspath(src),) + if NT6: + if os.path.isdir(src): + dir_link = "/D" + else: + dir_link = "" + cmd = "mklink %s %s %s" % (dir_link, os.path.abspath(dest), os.path.abspath(src),) + else: + cmd = "%s %s %s" % (JUNCTION, os.path.abspath(dest), os.path.abspath(src),) _run(cmd) def unlink(dest): - cmd = "%s -d %s" % (JUNCTION, os.path.abspath(dest),) + dest = os.path.abspath(dest) + if NT6: + if os.path.isdir(dest): + cmd = "rmdir %s" % (dest,) + else: + cmd = "del %s" % (dest,) + else: + cmd = "%s -d %s" % (JUNCTION, dest,) _run(cmd) def islink(dest): - cmd = "%s %s" % (JUNCTION, os.path.abspath(dest),) - output = _run(cmd) - return "Substitute Name:" in output - - + if NT6: + dest = os.path.abspath(dest) + cmd = "%s %s" % ("dir", os.path.dirname(dest),) + output = _run(cmd) + for row in output.split('\\n'): + # for files and for directories + if '