thg /

# A distutils setup script to install TortoiseHg in Windows and Posix
# environments.
# On Windows, this script is mostly used to build a stand-alone
# TortoiseHg package.  See installer\build.txt for details. The other
# use is to report the current version of the TortoiseHg source.

import time
import sys
import os
from distutils.core import setup
from import build
from distutils.spawn import spawn, find_executable

class build_mo(build):

    description = "build translations (.mo files)"

    def run(self):
        if not find_executable('msgfmt'):
            self.warn("could not find msgfmt executable, no translations "
                     "will be built")

        podir = 'i18n'
        if not os.path.isdir(podir):
            self.warn("could not find %s/ directory" % podir)

        join = os.path.join
        for po in os.listdir(podir):
            if not po.endswith('.po'):
            if not (po.find('tortoisehg-') == 0):
                self.warn("Found file '%s' that was not tortoisehg .po" % po)
            pofile = join(podir, po)
            modir = join('locale', po[11:-3], 'LC_MESSAGES')
            mofile = join(modir, '')
            cmd = ['msgfmt', '-v', '-o', mofile, pofile]
            if sys.platform != 'sunos5':
                # msgfmt on Solaris does not know about -c
            self.make_file([pofile], mofile, spawn, (cmd,))
            self.distribution.data_files.append((join('tortoisehg', modir),

build.sub_commands.append(('build_mo', None))

cmdclass = {
        'build_mo': build_mo}

def setup_windows():
    # Specific definitios for Windows NT-alike installations
    _scripts = []
    _data_files = []
    _packages = ['hggtk', 'hggtk.logview', 'thgutil']
    extra = {}
    hgextmods = []

    try: import py2exe
    except ImportError:
        if '--version' not in sys.argv:

    if 'py2exe' in sys.argv:
        # FIXME: quick hack to include installed hg extensions in py2exe binary
        import hgext
        hgextdir = os.path.dirname(hgext.__file__)
        hgextmods = set(["hgext." + os.path.splitext(f)[0]
                      for f in os.listdir(hgextdir)])
        _data_files = [(root, [os.path.join(root, file_) for file_ in files])
                            for root, dirs, files in os.walk('icons')]

    # add library files to support PyGtk-based dialogs/windows
    includes = ['dbhash', 'pango', 'atk', 'pangocairo', 'cairo', 'gobject']

    # Manually include other modules py2exe can't find by itself.
    if 'hgext.highlight' in hgextmods:
        includes += ['pygments.*', 'pygments.lexers.*', 'pygments.formatters.*',
                     'pygments.filters.*', 'pygments.styles.*']
    if 'hgext.patchbomb' in hgextmods:
        includes += ['email.*', 'email.mime.*']

    extra['options'] = {
       "py2exe" : {
           # This is one way to ensure that hgtk can find its icons when
           # running in a py2exe environment. It also makes debugging easier.
           "skip_archive" : 1,

           # Don't pull in all this MFC stuff used by the makepy UI.
           "excludes" : "pywin,pywin.dialogs,pywin.dialogs.list",

           # add library files to support PyGtk-based dialogs/windows
           # Note:
           #    after py2exe build, copy GTK's etc and lib directories into
           #    the dist directory created by py2exe.
           #    also needed is the GTK's share/themes (as dist/share/themes), 
           #    for dialogs to display in MS-Windows XP theme.
           "includes" : includes + list(hgextmods),
           "optimize" : 1

    return _scripts, _packages, _data_files, extra

def setup_posix():
    # Specific definitios for Posix installations
    _extra = {}
    _scripts = ['hgtk']
    _packages = ['hggtk', 'hggtk.logview', 'thgutil']
    _data_files = [(os.path.join('share/pixmaps/tortoisehg', root),
        [os.path.join(root, file_) for file_ in files])
        for root, dirs, files in os.walk('icons')]
    _data_files += [(os.path.join('share', root),
        [os.path.join(root, file_) for file_ in files])
        for root, dirs, files in os.walk('locale')]
    _data_files += [('lib/nautilus/extensions-2.0/python',

    # Create a  Distributions will need to supply their own
    cfgfile = os.path.join('thgutil', '')
    if not os.path.exists(cfgfile):
        f = open(cfgfile, "w")
        f.write('bin_path     = "/usr/bin"\n')
        f.write('license_path = "/usr/share/doc/tortoisehg/Copying.txt.gz"\n')
        f.write('locale_path  = "/usr/share/locale"\n')
        f.write('icon_path    = "/usr/share/pixmaps/tortoisehg/icons"\n')

    return _scripts, _packages, _data_files, _extra

if == "nt":
    (scripts, packages, data_files, extra) = setup_windows()
    desc='Windows shell extension for Mercurial VCS'
    (scripts, packages, data_files, extra) = setup_posix()
    desc='TortoiseHg dialogs for Mercurial VCS'

    l = os.popen('hg -R . id -it').read().split()
    while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
    version = l and l[-1] or 'unknown' # latest tag or revision number
    if version.endswith('+'):
        version += time.strftime('%Y%m%d')
except OSError:
    version = "unknown"

verfile = os.path.join("thgutil", "")
if version != 'unknown' or not os.path.exists(verfile):
    f = file(verfile, "w")
    f.write('# this file is autogenerated by\n')
    f.write('version = "%s"\n' % version)
    import thgutil.__version__
    version = thgutil.__version__.version

        author='TK Soh',
        license='GNU GPL2',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.