Skip to content

Commit

Permalink
Add mk langpack task for building a Komodo langpack for translation on
Browse files Browse the repository at this point in the history
babelzilla.org.


git-svn-id: http://svn.openkomodo.com/repos/openkomodo/trunk@1775 b87d16e7-d29f-4ee1-b5ec-817d645d335f
  • Loading branch information
Trent Mick committed Jul 10, 2008
1 parent e1e67fb commit 9144280
Showing 1 changed file with 195 additions and 0 deletions.
195 changes: 195 additions & 0 deletions Makefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import re
import sys
from pprint import pprint
import codecs
from collections import defaultdict
import subprocess

from mklib import Task, Configuration, Alias, include
from mklib import sh
Expand All @@ -30,6 +32,107 @@ class cfg(Configuration):
prefix = "bk"


class langpack(Task):
"""Make a lang-pack XPI for translation on babelzilla.org.
See this thread for background:
http://community.activestate.com/forum-topic/localizing-komodo-using-babelzilla-dream-team
"""
LANGPACK_VERSION = "0.1"

def _svnversion_from_dir(self, dir):
try:
p = subprocess.Popen(["svnversion"], cwd=dir, stdout=subprocess.PIPE)
except EnvironmentError, ex:
self.log.debug("error running 'svnversion': %s", ex)
return None
version = p.stdout.read().strip()
status = p.wait()
if status:
self.log.debug("error running 'svnversion': status=%r", status)
return None
return version

def _writefile(self, path, content, encoding=None):
self.log.info("create `%s'", path)
f = codecs.open(path, 'w', encoding)
try:
f.write(content)
finally:
f.close()

def make(self):
build_dir = join(self.dir, "build", "langpack")
pkg_dir = join(self.dir, "packages")
locale_dir = join(self.dir, "src", "chrome", "komodo", "locale")

# Clean build dir.
if exists(build_dir):
sh.rm(build_dir, self.log)
os.makedirs(build_dir)

# Create the package contents.
os.makedirs(join(build_dir, "chrome"))
sh.cp(locale_dir, join(build_dir, "chrome", "locale"),
recursive=True,
log=self.log.info)
for dirpath, dnames, fnames in os.walk(build_dir):
if ".svn" in dnames:
sh.rm(join(dirpath, ".svn"), self.log)
dnames.remove(".svn")
for fname in [".consign", "Conscript"]:
if fname in fnames:
sh.rm(join(dirpath, fname), self.log)
self._writefile(join(build_dir, "chrome.manifest"),
"locale komodo-langpack en-US chrome/locale/en-US/")
self._writefile(join(build_dir, "install.rdf"), _dedent("""\
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:name>Komodo Langpack</em:name>
<em:description>Interface Langpack for Komodo</em:description>
<em:version>%s</em:version>
<em:id>[email protected]</em:id>
<em:creator>ActiveState</em:creator>
<em:type>2</em:type>
<!-- Komodo IDE -->
<em:targetApplication>
<Description>
<em:id>{36E66FA0-F259-11D9-850E-000D935D3368}</em:id>
<em:minVersion>4.0</em:minVersion>
<em:maxVersion>4.*</em:maxVersion>
</Description>
</em:targetApplication>
<!-- Komodo Edit -->
<em:targetApplication>
<Description>
<em:id>{b1042fb5-9e9c-11db-b107-000d935d3368}</em:id>
<em:minVersion>4.0</em:minVersion>
<em:maxVersion>4.*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>
"""))

# Package it up.
if not exists(pkg_dir):
os.makedirs(pkg_dir)
version = self._svnversion_from_dir(locale_dir)
pkg_name = ["Komodo", "LangPack"]
if version:
pkg_name.append("r%s" % version)
pkg_name = '-'.join(pkg_name) + ".xpi"
pkg_path = join(pkg_dir, pkg_name)
sh.run_in_dir('zip -rq "%s" .' % abspath(pkg_path), build_dir,
self.log.info)
self.log.info("created `%s'", pkg_path)


class todo(Task):
"""Print out todo's and xxx's in the docs area."""
def make(self):
Expand Down Expand Up @@ -124,3 +227,95 @@ def _entities_from_dtd_path(self, dtd_path):
for hit in self._dtd_entity_re.findall(dtd):
#print hit
yield hit




#---- internal support stuff

# Recipe: dedent (0.1.2)
def _dedentlines(lines, tabsize=8, skip_first_line=False):
"""_dedentlines(lines, tabsize=8, skip_first_line=False) -> dedented lines
"lines" is a list of lines to dedent.
"tabsize" is the tab width to use for indent width calculations.
"skip_first_line" is a boolean indicating if the first line should
be skipped for calculating the indent width and for dedenting.
This is sometimes useful for docstrings and similar.
Same as dedent() except operates on a sequence of lines. Note: the
lines list is modified **in-place**.
"""
DEBUG = False
if DEBUG:
print "dedent: dedent(..., tabsize=%d, skip_first_line=%r)"\
% (tabsize, skip_first_line)
indents = []
margin = None
for i, line in enumerate(lines):
if i == 0 and skip_first_line: continue
indent = 0
for ch in line:
if ch == ' ':
indent += 1
elif ch == '\t':
indent += tabsize - (indent % tabsize)
elif ch in '\r\n':
continue # skip all-whitespace lines
else:
break
else:
continue # skip all-whitespace lines
if DEBUG: print "dedent: indent=%d: %r" % (indent, line)
if margin is None:
margin = indent
else:
margin = min(margin, indent)
if DEBUG: print "dedent: margin=%r" % margin

if margin is not None and margin > 0:
for i, line in enumerate(lines):
if i == 0 and skip_first_line: continue
removed = 0
for j, ch in enumerate(line):
if ch == ' ':
removed += 1
elif ch == '\t':
removed += tabsize - (removed % tabsize)
elif ch in '\r\n':
if DEBUG: print "dedent: %r: EOL -> strip up to EOL" % line
lines[i] = lines[i][j:]
break
else:
raise ValueError("unexpected non-whitespace char %r in "
"line %r while removing %d-space margin"
% (ch, line, margin))
if DEBUG:
print "dedent: %r: %r -> removed %d/%d"\
% (line, ch, removed, margin)
if removed == margin:
lines[i] = lines[i][j+1:]
break
elif removed > margin:
lines[i] = ' '*(removed-margin) + lines[i][j+1:]
break
else:
if removed:
lines[i] = lines[i][removed:]
return lines

def _dedent(text, tabsize=8, skip_first_line=False):
"""_dedent(text, tabsize=8, skip_first_line=False) -> dedented text
"text" is the text to dedent.
"tabsize" is the tab width to use for indent width calculations.
"skip_first_line" is a boolean indicating if the first line should
be skipped for calculating the indent width and for dedenting.
This is sometimes useful for docstrings and similar.
textwrap.dedent(s), but don't expand tabs to spaces
"""
lines = text.splitlines(1)
_dedentlines(lines, tabsize=tabsize, skip_first_line=skip_first_line)
return ''.join(lines)

0 comments on commit 9144280

Please sign in to comment.