Package: zeroinstall-injector
Version: 0.29-1
X-Debbugs-CC: [EMAIL PROTECTED]
Priority: wishlist
Tags: patch

0alias does not allow the user to specify the path to link into and
instead guesses (incorrectly in my case) on its own. This patch allows
the path to be specified.

The same code used to check $PATH for a writable path (and the same
error message if this is not possible) is used to verify the user
supplied path.

Note that this does NOT check to see if the specified path is in $PATH.

Matthew

-- 
I must take issue with the term "a mere child", for it has been my
invariable experience that the company of a mere child is infinitely
preferable to that of a mere adult.
                                           --  Fran Lebowitz
--- 0alias~	2007-05-13 09:53:22.000000000 +0100
+++ 0alias	2007-09-19 17:41:38.609077973 +0100
@@ -12,29 +12,38 @@
 		return "setenv %s %s" % (name, value)
 	return "export %s=%s" % (name, value)
 
-for first_path in os.environ['PATH'].split(':'):
-	if os.path.realpath(first_path).startswith(basedir.xdg_cache_home):
-		pass # print "Skipping cache", first_path
-	elif not os.access(first_path, os.W_OK):
-		pass # print "No access", first_path
+def find_path(paths):
+	"""Find the first writable path in : separated list."""
+	for path in paths.split(':'):
+		if os.path.realpath(path).startswith(basedir.xdg_cache_home):
+			pass # print "Skipping cache", first_path
+		elif not os.access(path, os.W_OK):
+			pass # print "No access", first_path
+		else:
+			break
 	else:
-		break
-else:
-	print >>sys.stderr, ("No writable non-cache directory in $PATH, which currently contains:\n\n%s\n"
-		"To create a directory for your scripts, use these commands:\n"
-		"$ mkdir ~/bin\n"
-		"$ %s" % ('\n'.join(os.environ['PATH'].split(':')), export('PATH', '$HOME/bin:$PATH')))
-	sys.exit(1)
+		print >>sys.stderr, ("No writable non-cache directory in $PATH, which currently contains:\n\n%s\n\n"
+				     "To create a directory for your scripts, use these commands:\n"
+				     "$ mkdir ~/bin\n"
+				     "$ %s\n"
+				     "or specify a writable path with --path"
+				     % ('\n'.join(os.environ['PATH'].split(':')), export('PATH', '$HOME/bin:$PATH')))
+		sys.exit(1)
+
+	return path
+
+first_path = find_path(os.environ['PATH'])
 
 parser = OptionParser(usage="usage: %%prog [options] alias [interface [command]]\n\n"
 		"Creates a script in the first usable directory in $PATH\n"
-		"(%s) to run 'interface'.\n"
+		"(%s) to run 'interface' unless overridden by --path.\n"
 		"If no interface is given, edits the policy for an existing alias.\n"
 		"For interfaces providing more than one command, the desired command\n"
 		"may also be given." % first_path)
 parser.add_option("-m", "--manpage", help="show the manual page for an existing alias", action='store_true')
 parser.add_option("-r", "--resolve", help="show the URI for an alias", action='store_true')
 parser.add_option("-V", "--version", help="display version information", action='store_true')
+parser.add_option("-p", "--path", help="install in DIR", dest="user_path", metavar="DIR")
 parser.disable_interspersed_args()
 
 (options, args) = parser.parse_args()
@@ -65,6 +74,9 @@
 		parser.print_help()
 		sys.exit(1)
 
+if options.user_path:
+	first_path = find_path(options.user_path)
+
 if interface_uri is None:
 	try:
 		if not os.path.isabs(alias_prog):

Reply via email to