summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Drung <bdrung@debian.org>2013-01-19 02:17:03 +0100
committerBenjamin Drung <bdrung@debian.org>2013-01-19 02:17:03 +0100
commitf0437c38b9faa188a35f712811eaef346998641d (patch)
tree70be24584e62bdf783781d17d2201c7a8f3fe824
parentb7bd3a4d395db373eadd9ddf90b4dedb08754b43 (diff)
install-xpi: Search in the parent directories for a debian/ directory.
This change make install-xpi work with debhelper's --sourcedirectory parameter. Closes: #698033
-rwxr-xr-xinstall-xpi57
1 files changed, 36 insertions, 21 deletions
diff --git a/install-xpi b/install-xpi
index 495492d..a05c462 100755
--- a/install-xpi
+++ b/install-xpi
@@ -37,17 +37,30 @@ LICENSE_PATTERN_LIST = (
COMMAND_LINE_SYNTAX_ERROR = 1
XPI_FILE_DOES_NOT_EXISTS = 2
-def check_package_directory(script_name):
- """Check if the debian/ directory and files like debian/control exist."""
- if not os.path.isdir("debian"):
- sys.stderr.write(script_name + ": Error: Failed to find debian/ "
- "directory. Please execute the script in a Debian "
- "source package.\n")
- sys.exit(1)
- if not os.path.isfile("debian/control"):
+def get_debian_directory(script_name):
+ """Return the path to the debian/ directory.
+
+ Search for a debian/ directory in the current working directory and crawling
+ up the parent directories until one is found. The script will fail if no
+ debian/ directory is found or the debian/ directory does not contain a
+ control file."""
+ base_directory = os.getcwd()
+ while not os.path.isdir(os.path.join(base_directory, "debian")):
+ parent_directory = os.path.split(base_directory)[0]
+ if base_directory == parent_directory:
+ sys.stderr.write(script_name + ": Error: Failed to find a debian/ "
+ "directory. Please execute this script inside a "
+ "Debian source package.\n")
+ sys.exit(1)
+ else:
+ base_directory = parent_directory
+ package_directory = os.path.join(base_directory, "debian")
+ # Check if debian/control exists.
+ if not os.path.isfile(os.path.join(package_directory, "control")):
sys.stderr.write(script_name + ": Error: debian/control file is "
"missing.\n")
sys.exit(1)
+ return package_directory
def get_query_field_id_as_list(rdf_path, query_string):
ret = []
@@ -71,8 +84,8 @@ def get_extension_id(install_rdf):
"SELECT ?id WHERE {?x em:targetApplication [] . ?x em:id ?id }"))
return extension_ids.pop()
-def get_arch(package):
- lines = open("debian/control").readlines()
+def get_arch(package, debian_directory):
+ lines = open(os.path.join(debian_directory, "control")).readlines()
package_lines = filter(lambda x: x.find("Package:") >= 0, lines)
packages = map(lambda x: x[x.find(":")+1:].strip(), package_lines)
architecture_lines = filter(lambda x: x.find("Architecture:") >= 0, lines)
@@ -95,7 +108,8 @@ def get_xul_apps():
return rows
def install_xpi(script_name, package, xpi_file, exclude, install_dir, links,
- correct_permissions, remove_licenses, system_prefs, verbose=False):
+ correct_permissions, remove_licenses, system_prefs, debian_directory,
+ verbose=False):
# get xpi file content list
if not os.path.isfile(xpi_file):
print >> sys.stderr, "%s: Error: xpi file %s does not exist." % \
@@ -105,14 +119,14 @@ def install_xpi(script_name, package, xpi_file, exclude, install_dir, links,
xpi_content = zfobj.namelist()
# determine installation directory
- if get_arch(package) == "all":
+ if get_arch(package, debian_directory) == "all":
lib_share_dir = "share"
else:
lib_share_dir = "lib"
if install_dir is None:
install_dir = os.path.join("usr", lib_share_dir, "xul-ext",
package.replace("xul-ext-", ""))
- copy_dir = os.path.join("debian", package, install_dir.strip("/"))
+ copy_dir = os.path.join(debian_directory, package, install_dir.strip("/"))
if verbose:
print "%s: install directory: %s" % (script_name, install_dir)
@@ -165,15 +179,16 @@ def install_xpi(script_name, package, xpi_file, exclude, install_dir, links,
f.endswith(".js"), xpi_content)
if len(preferences) > 0:
prefdir = os.path.join("etc", "xul-ext")
- full_prefdir = os.path.join("debian", package, prefdir)
+ full_prefdir = os.path.join(debian_directory, package, prefdir)
if not os.path.exists(full_prefdir):
os.makedirs(full_prefdir)
prefname = package.replace("xul-ext-", "") + ".js"
# create system preference file
f = open(os.path.join(full_prefdir, prefname), "w")
- if os.path.isfile(os.path.join("debian", package + ".js")):
+ config_file = os.path.join(debian_directory, package + ".js")
+ if os.path.isfile(config_file):
# use debian/package.js as configuration file if it exists
- content = open(os.path.join("debian", package + ".js")).read()
+ content = open(config_file).read()
# replace @INSTALLDIR@ by the actual installation directory
content = content.replace("@INSTALLDIR@",
os.path.join("/", install_dir))
@@ -210,8 +225,8 @@ def install_xpi(script_name, package, xpi_file, exclude, install_dir, links,
print " ".join(command)
subprocess.call(command)
-def get_first_package():
- lines = open("debian/control").readlines()
+def get_first_package(debian_directory):
+ lines = open(os.path.join(debian_directory, "control")).readlines()
package_lines = filter(lambda x: x.find("Package:") >= 0, lines)
packages = map(lambda x: x[x.find(":")+1:].strip(), package_lines)
return packages[0]
@@ -256,10 +271,10 @@ def main():
(script_name, ", ".join(args))
sys.exit(COMMAND_LINE_SYNTAX_ERROR)
- check_package_directory(script_name)
+ debian_directory = get_debian_directory(script_name)
if options.package is None:
- options.package = get_first_package()
+ options.package = get_first_package(debian_directory)
if options.verbose:
print script_name + ": Install %s into package %s." % \
@@ -268,7 +283,7 @@ def main():
install_xpi(script_name, options.package, args[0], options.exclude,
options.install_dir, set(options.links),
options.correct_permissions, options.remove_licenses,
- options.system_prefs, options.verbose)
+ options.system_prefs, debian_directory, options.verbose)
if __name__ == "__main__":
main()