0release on Windows

"Bastian Eicher" <[email protected]>
Newsgroups gmane.comp.file-systems.zero-install.devel
Message-ID <[email protected]>
I've been playing around with 0release a bit and trying to get it working on
Windows. I've attached patches for my work so far.
For this to work out-of-the-box we would also need a new 0publish release
incorporating the Windows support fixes already present on the Git master.
Also, 0test would need to be redesigned to use multiprocessing rather than
os.fork().

One thing I noticed is that 0release seems to be hardwired to assume that
the local-path of an implementation is always '.' and not some subdirectory
relative to the feed. Is that correct?

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/

_______________________________________________
Zero-install-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/zero-install-devel
1-os.path.relpath.patch (application/octet-stream, 1.7 KB)
>From 4ac68bce6cbe023c96eec4dca6e29397fc609af3 Mon Sep 17 00:00:00 2001
From: Bastian Eicher <[email protected]>
Date: Tue, 30 Jun 2015 21:47:00 +0200
Subject: [PATCH] Replaced support.relative_path with os.path.relpath

---
 release.py |  2 +-
 support.py | 11 -----------
 2 files changed, 1 insertion(+), 12 deletions(-)

diff --git a/release.py b/release.py
index e3f78fb..ff2fc47 100644
--- a/release.py
+++ b/release.py
@@ -516,7 +516,7 @@ def do_release(local_feed, options):
 	if extracted_impl.main:
 		# Find main executable, relative to the archive root
 		abs_main = os.path.join(os.path.dirname(extracted_feed_path), extracted_impl.id, extracted_impl.main)
-		main = support.relative_path(archive_name + '/', abs_main)
+		main = os.path.relpath(abs_main, archive_name + os.sep)
 		if main != extracted_impl.main:
 			print "(adjusting main: '%s' for the feed inside the archive, '%s' externally)" % (extracted_impl.main, main)
 			# XXX: this is going to fail if the feed uses the new <command> syntax
diff --git a/support.py b/support.py
index 9dfeb2a..08f93ec 100644
--- a/support.py
+++ b/support.py
@@ -215,17 +215,6 @@ def get_archive_basename(impl):
 	# "2" means "path" (for Python 2.4)
 	return os.path.basename(urlparse.urlparse(impl.download_sources[0].url)[2])
 
-def relative_path(ancestor, dst):
-	stem = os.path.abspath(os.path.dirname(ancestor))
-	dst = os.path.abspath(dst)
-	if stem != '/':
-		stem += '/'
-	assert dst.startswith(stem)
-	return dst[len(stem):]
-
-assert relative_path('/foo', '/foo') == 'foo'
-assert relative_path('/foo', '/foo/bar') == 'foo/bar'
-
 def make_readonly_recursive(path):
 	for root, dirs, files in os.walk(path):
 		for d in dirs + files:
-- 
1.9.5.msysgit.1
2-os.path.patch (application/octet-stream, 2.7 KB)
>From fb9e1cce1c2abcab90a894870105a8b730ca067b Mon Sep 17 00:00:00 2001
From: Bastian Eicher <[email protected]>
Date: Tue, 30 Jun 2015 23:09:58 +0200
Subject: [PATCH] Replaced hardcoded '/' occurrences for Windows support

---
 release.py | 10 +++++-----
 scm.py     |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/release.py b/release.py
index ff2fc47..9f4eaaa 100644
--- a/release.py
+++ b/release.py
@@ -170,10 +170,10 @@ def do_release(local_feed, options):
 	local_impl = support.get_singleton_impl(local_feed)
 
 	local_impl_dir = local_impl.id
-	assert local_impl_dir.startswith('/')
+	assert os.path.isabs(local_impl_dir)
 	local_impl_dir = os.path.realpath(local_impl_dir)
 	assert os.path.isdir(local_impl_dir)
-	assert local_feed.local_path.startswith(local_impl_dir + '/')
+	assert local_feed.local_path.startswith(local_impl_dir + os.sep)
 
 	# From the impl directory to the feed
 	# NOT relative to the archive root (in general)
@@ -473,7 +473,7 @@ def do_release(local_feed, options):
 
 	export_prefix = archive_name
 	if add_toplevel_dir is not None:
-		export_prefix += '/' + add_toplevel_dir
+		export_prefix += os.sep + add_toplevel_dir
 
 	if status.created_archive and os.path.isfile(archive_file):
 		print "Archive already created"
@@ -578,11 +578,11 @@ def do_release(local_feed, options):
 			choice = support.get_choice(['Publish', 'Fail'] + maybe_diff)
 			if choice == 'Diff':
 				previous_archive_name = support.make_archive_name(local_feed.get_name(), previous_release)
-				previous_archive_file = '../%s/%s.tar.bz2' % (previous_release, previous_archive_name)
+				previous_archive_file = '..' + os.sep + previous_release + os.sep + previous_archive_name + '.tar.bz2'
 
 				# For archives created by older versions of 0release
 				if not os.path.isfile(previous_archive_file):
-					old_previous_archive_file = '../%s.tar.bz2' % previous_archive_name
+					old_previous_archive_file = '..' + os.sep + previous_archive_name + '.tar.bz2'
 					if os.path.isfile(old_previous_archive_file):
 						previous_archive_file = old_previous_archive_file
 
diff --git a/scm.py b/scm.py
index 6699478..f413bd1 100644
--- a/scm.py
+++ b/scm.py
@@ -106,7 +106,7 @@ class GIT(SCM):
 						"git tag -d %s") % (version, tag))
 
 	def export(self, prefix, archive_file, revision):
-		child = self._run(['archive', '--format=tar', '--prefix=' + prefix + '/', revision], stdout = subprocess.PIPE)
+		child = self._run(['archive', '--format=tar', '--prefix=' + prefix + os.sep, revision], stdout = subprocess.PIPE)
 		subprocess.check_call(['bzip2', '-'], stdin = child.stdout, stdout = file(archive_file, 'w'))
 		status = child.wait()
 		if status:
-- 
1.9.5.msysgit.1
3-portable_rename.patch (application/octet-stream, 2.5 KB)
>From 0eef53d6c342a8b623a4a791d268f9b4fe5a5e96 Mon Sep 17 00:00:00 2001
From: Bastian Eicher <[email protected]>
Date: Wed, 1 Jul 2015 00:33:34 +0200
Subject: [PATCH] Use portable_rename for Windows support

---
 compile.py | 6 +++---
 support.py | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/compile.py b/compile.py
index 19d00e0..7823c55 100644
--- a/compile.py
+++ b/compile.py
@@ -4,7 +4,7 @@
 import tempfile, shutil, os, sys
 import ConfigParser
 from logging import info
-from zeroinstall.support import basedir
+from zeroinstall.support import basedir, portable_rename
 
 import support
 
@@ -85,7 +85,7 @@ class Compiler:
 				assert os.path.exists(bin_archive_file), "Compiled binary '%s' not found!" % os.path.abspath(bin_archive_file)
 				assert os.path.getsize(bin_archive_file) == bin_size, "Compiled binary '%s' has wrong size!" % os.path.abspath(bin_archive_file)
 
-				os.rename(binary_feed + '.new', binary_feed)
+				portable_rename(binary_feed + '.new', binary_feed)
 
 	def get_binary_feeds(self):
 		return ['binary-%s.xml' % target for target in self.targets]
@@ -119,7 +119,7 @@ def build_slave(src_feed, archive_file, archive_dir_public_url, target_feed):
 		os.mkdir(depdir)
 
 		support.unpack_tarball(archive_file)
-		os.rename(impl.download_sources[0].extract, os.path.join(depdir, impl.id))
+		portable_rename(impl.download_sources[0].extract, os.path.join(depdir, impl.id))
 
 		config = ConfigParser.RawConfigParser()
 		config.add_section('compile')
diff --git a/support.py b/support.py
index 08f93ec..57c87ca 100644
--- a/support.py
+++ b/support.py
@@ -8,7 +8,7 @@ from xml.dom import minidom
 
 from zeroinstall import SafeException
 from zeroinstall.injector import model, qdom, namespaces
-from zeroinstall.support import ro_rmtree
+from zeroinstall.support import ro_rmtree, portable_rename
 from logging import info
 
 release_status_file = os.path.abspath('release-status')
@@ -75,7 +75,7 @@ def backup_if_exists(name):
 			ro_rmtree(backup)
 		else:
 			os.unlink(backup)
-	os.rename(name, backup)
+	portable_rename(name, backup)
 	print "(renamed old %s as %s; will delete on next run)" % (name, backup)
 
 def get_choice(options):
@@ -125,7 +125,7 @@ class Status(object):
 			lines = ["%s=%s\n" % (name, getattr(self, name)) for name in self.__slots__ if getattr(self, name)]
 			tmp.write(''.join(lines))
 			tmp.close()
-			os.rename(tmp_name, release_status_file)
+			portable_rename(tmp_name, release_status_file)
 			info("Wrote status to %s", release_status_file)
 		except:
 			os.unlink(tmp_name)
-- 
1.9.5.msysgit.1
4-batch-file.patch (application/octet-stream, 3.3 KB)
>From b5fe80df63e59481cba8682e299044efa81ed455 Mon Sep 17 00:00:00 2001
From: Bastian Eicher <[email protected]>
Date: Tue, 30 Jun 2015 22:15:41 +0200
Subject: [PATCH] Generate batch file instead of shell script on Windows

---
 setup.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 52 insertions(+), 5 deletions(-)

diff --git a/setup.py b/setup.py
index 17a3dea..5570df0 100644
--- a/setup.py
+++ b/setup.py
@@ -18,8 +18,54 @@ def init_releases_directory(feed):
 
 	master_feed_name = feed.get_name().replace(' ', '-') + '.xml'
 
-	make_release = file('make-release', 'w')
-	make_release.write("""#!/bin/sh
+	if os.name == 'nt':
+		make_release = file('make-release.bat', 'w')
+		make_release.write("""@echo off
+
+:: The directory people will download the releases from.
+:: This will appear in the remote feed file.
+::set ARCHIVE_DIR_PUBLIC_URL=http://placeholder.org/releases/%%RELEASE_VERSION%%
+set ARCHIVE_DIR_PUBLIC_URL=
+
+:: The path to the main feed.
+:: The new version is added here when you publish a release.
+::set MASTER_FEED_FILE="$HOME/public_html/feeds/MyProg.xml"
+set MASTER_FEED_FILE=%s
+
+:: A shell command to upload the generated archive file to the
+:: public server (corresponds to %%ARCHIVE_DIR_PUBLIC_URL%%, which is
+:: used to download it again).
+:: If unset, you'll have to upload it yourself.
+::set ARCHIVE_UPLOAD_COMMAND=scp %%* me@myhost:/var/www/releases/%%RELEASE_VERSION%%/
+set ARCHIVE_UPLOAD_COMMAND=
+
+:: A shell command to upload the master feed (%%MASTER_FEED_FILE%%) and
+:: related files to your web server. It will be downloaded using the
+:: feed's URL. If unset, you'll have to upload it yourself.
+::set MASTER_FEED_UPLOAD_COMMAND=scp %%* me@myhost:/var/www/feeds/
+set MASTER_FEED_UPLOAD_COMMAND=
+
+:: Your public version control repository. When publishing, the new
+:: HEAD and the release tag will be pushed to this using a command
+:: such as "git-push main master v0.1"
+:: If unset, you'll have to update it yourself.
+::set PUBLIC_SCM_REPOSITORY=origin
+set PUBLIC_SCM_REPOSITORY=
+
+cd /d "%%~dp0"
+0launch %s --release %s ^
+ --archive-dir-public-url="%%ARCHIVE_DIR_PUBLIC_URL%%" ^
+ --master-feed-file="%%MASTER_FEED_FILE%%" ^
+ --archive-upload-command="%%ARCHIVE_UPLOAD_COMMAND%%" ^
+ --master-feed-upload-command="%%MASTER_FEED_UPLOAD_COMMAND%%" ^
+ --public-scm-repository="%%PUBLIC_SCM_REPOSITORY%%" ^
+ %%*
+""" % (master_feed_name, release_uri, feed.local_path))
+		make_release.close()
+		print "Success - created script:\n %s" % os.path.abspath('make-release.bat')
+	else:
+		make_release = file('make-release', 'w')
+		make_release.write("""#!/bin/sh
 
 # The directory people will download the releases from.
 # This will appear in the remote feed file.
@@ -60,7 +106,8 @@ exec 0launch %s --release %s \\
  --public-scm-repository="$PUBLIC_SCM_REPOSITORY" \\
  "$@"
 """ % (master_feed_name, release_uri, feed.local_path))
-	make_release.close()
-	os.chmod('make-release', 0775 & ~umask)
-	print "Success - created script:\n %s\nNow edit it with your local settings." % os.path.abspath('make-release')
+		make_release.close()
+		os.chmod('make-release', 0775 & ~umask)
+		print "Success - created script:\n %s" % os.path.abspath('make-release')
+	print "Now edit it with your local settings."
 	print "Then, create new releases by running it."
-- 
1.9.5.msysgit.1
5-set_released.patch (application/octet-stream, 1 KB)
>From fd8d8b3da951941e436f017bbf3f581c414c04ce Mon Sep 17 00:00:00 2001
From: Bastian Eicher <[email protected]>
Date: Wed, 1 Jul 2015 00:38:17 +0200
Subject: [PATCH] Do not use set_released = ''

On Windows an empty command-line argument is skipped / treated as non-existant
---
 release.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/release.py b/release.py
index 9f4eaaa..c9089c6 100644
--- a/release.py
+++ b/release.py
@@ -254,7 +254,7 @@ def do_release(local_feed, options):
 
 	def set_to_snapshot(snapshot_version):
 		assert snapshot_version.endswith('-post')
-		support.publish(local_feed.local_path, set_released = '', set_version = snapshot_version)
+		support.publish(local_feed.local_path, set_version = snapshot_version)
 		do_version_substitutions(local_impl_dir, version_substitutions, snapshot_version)
 		scm.commit('Start development series %s' % snapshot_version, branch = TMP_BRANCH_NAME, parent = TMP_BRANCH_NAME)
 		status.new_snapshot_version = scm.get_head_revision()
-- 
1.9.5.msysgit.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.