~stephen-j-boddy/terminator/bugfix-1318542-double-chars

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Stephen Boddy
  • Date: 2015-08-08 02:11:30 UTC
  • Revision ID: stephen.j.boddy@gmail.com-20150808021130-9c1npu4gvenkcb1p
A manual has been added to Terminator
* Added source and generated html of manual, and API doc
* setup.py can install the manual (and by extension do can debuild)
* setup.py has (inactive) code for generating the html from the source
  but this will break if rtd theme is not available
* A few changes to doc strings to make the autodoc prettier
* Added help shortcut, by default F1 to open the local manual
* Added button to About tab to launch manual
* A couple of additional string to translate related to manual/help

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
PO_DIR = 'po'
20
20
MO_DIR = os.path.join('build', 'mo')
 
21
DOC_DIR = 'doc'
21
22
 
22
23
class TerminatorDist(Distribution):
23
24
  global_options = Distribution.global_options + [
 
25
    ("with-documentation", None, "Build/install the documentation"),
24
26
    ("without-gettext", None, "Don't build/install gettext .mo files"),
25
27
    ("without-icon-cache", None, "Don't attempt to run gtk-update-icon-cache")]
26
28
 
27
29
  def __init__ (self, *args):
 
30
    self.with_documentation = False
28
31
    self.without_gettext = False
29
32
    self.without_icon_cache = False
30
33
    Distribution.__init__(self, *args)
34
37
  def run (self):
35
38
    build.run (self)
36
39
 
37
 
    if self.distribution.without_gettext:
38
 
      return
39
 
 
40
 
    for po in glob.glob (os.path.join (PO_DIR, '*.po')):
41
 
      lang = os.path.basename(po[:-3])
42
 
      mo = os.path.join(MO_DIR, lang, 'terminator.mo')
43
 
 
44
 
      directory = os.path.dirname(mo)
45
 
      if not os.path.exists(directory):
46
 
        info('creating %s' % directory)
47
 
        os.makedirs(directory)
48
 
 
49
 
      if newer(po, mo):
50
 
        info('compiling %s -> %s' % (po, mo))
51
 
        try:
52
 
          rc = subprocess.call(['msgfmt', '-o', mo, po])
53
 
          if rc != 0:
54
 
            raise Warning, "msgfmt returned %d" % rc
55
 
        except Exception, e:
56
 
          error("Building gettext files failed.  Try setup.py --without-gettext [build|install]")
57
 
          error("Error: %s" % str(e))
58
 
          sys.exit(1)
59
 
 
60
 
    TOP_BUILDDIR='.'
61
 
    INTLTOOL_MERGE='intltool-merge'
62
 
    desktop_in='data/terminator.desktop.in'
63
 
    desktop_data='data/terminator.desktop'
64
 
    os.system ("C_ALL=C " + INTLTOOL_MERGE + " -d -u -c " + TOP_BUILDDIR +
65
 
               "/po/.intltool-merge-cache " + TOP_BUILDDIR + "/po " +
66
 
               desktop_in + " " + desktop_data)
 
40
    if not self.distribution.without_gettext:
 
41
      # Build the translations
 
42
      for po in glob.glob (os.path.join (PO_DIR, '*.po')):
 
43
        lang = os.path.basename(po[:-3])
 
44
        mo = os.path.join(MO_DIR, lang, 'terminator.mo')
 
45
 
 
46
        directory = os.path.dirname(mo)
 
47
        if not os.path.exists(directory):
 
48
          info('creating %s' % directory)
 
49
          os.makedirs(directory)
 
50
 
 
51
        if newer(po, mo):
 
52
          info('compiling %s -> %s' % (po, mo))
 
53
          try:
 
54
            rc = subprocess.call(['msgfmt', '-o', mo, po])
 
55
            if rc != 0:
 
56
              raise Warning, "msgfmt returned %d" % rc
 
57
          except Exception, e:
 
58
            error("Building gettext files failed.  Try setup.py --without-gettext [build|install]")
 
59
            error("Error: %s" % str(e))
 
60
            sys.exit(1)
 
61
 
 
62
      TOP_BUILDDIR='.'
 
63
      INTLTOOL_MERGE='intltool-merge'
 
64
      desktop_in='data/terminator.desktop.in'
 
65
      desktop_data='data/terminator.desktop'
 
66
      os.system ("C_ALL=C " + INTLTOOL_MERGE + " -d -u -c " + TOP_BUILDDIR +
 
67
                 "/po/.intltool-merge-cache " + TOP_BUILDDIR + "/po " +
 
68
                 desktop_in + " " + desktop_data)
 
69
 
 
70
    if self.distribution.with_documentation:
 
71
      # Build the documentation
 
72
      for doc_folder in (glob.glob (os.path.join (DOC_DIR, 'manual*')) + [os.path.join (DOC_DIR, 'apidoc')]):
 
73
        if os.path.isfile(os.path.join(doc_folder, 'Makefile')):
 
74
          old_cwd = os.getcwd()
 
75
          os.chdir(doc_folder)
 
76
          os.system("make clean")
 
77
          os.system("make html")
 
78
          os.chdir(old_cwd)
67
79
 
68
80
class Uninstall(Command):
69
81
  description = "Attempt an uninstall from an install --record file"
126
138
class InstallData(install_data):
127
139
  def run (self):
128
140
    self.data_files.extend (self._find_mo_files ())
 
141
    self.data_files.extend (self._find_doc_files ())
129
142
    install_data.run (self)
130
143
    if not self.distribution.without_icon_cache:
131
144
      self._update_icon_cache ()
149
162
 
150
163
    return data_files
151
164
 
 
165
  def _find_doc_files (self):
 
166
    data_files = []
 
167
 
 
168
    if self.distribution.with_documentation:
 
169
      for doc_folder in (glob.glob (os.path.join (DOC_DIR, 'manual*')) + [os.path.join (DOC_DIR, 'apidoc')]):
 
170
        # construct new path
 
171
        src = os.path.join(doc_folder, '_build', 'html')
 
172
        dest_sub = os.path.split(doc_folder[:])[1]
 
173
        if dest_sub[:6] == 'manual':
 
174
          dest_sub = 'html'+dest_sub[6:]
 
175
        dest = os.path.join('share', 'doc', 'terminator', dest_sub)
 
176
        if os.path.isdir(src):
 
177
          for dirpath, dirnames, filenames in os.walk(src):
 
178
            cut_elem_count = len(doc_folder.split(os.sep)) + 2
 
179
            dest_sub = os.path.join(dirpath.split(os.sep)[cut_elem_count:])
 
180
            full_dest_folder = os.path.join(dest, *dest_sub)
 
181
            full_src_filenames = [os.path.join(dirpath, filename) for filename in filenames]
 
182
            data_files.append((full_dest_folder, full_src_filenames))
 
183
 
 
184
    return data_files
 
185
 
152
186
class Test(Command):
153
187
  user_options = []
154
188
  def initialize_options(self):