~jconti/recent-notifications/trunk

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Jason Conti
  • Date: 2010-03-08 18:16:22 UTC
  • Revision ID: jason.conti@gmail.com-20100308181622-gd3xbvuoxtpzjn69
Tags: 0.4.6
Adding support for gettext translations and a pointless en_US translation as an example. Using distutils-extra to automatically build the translations and the bonobo server. Replaced the build_servers target with update_prefix. This performs basically the same as build_servers except that it will do the substitution on any .in file, and it just writes the output file without the .in, instead of adding it to the data file install list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
from distutils.command.build import build
7
7
from distutils.core import setup
 
8
from DistUtilsExtra.command import *
8
9
from string import Template
9
10
 
10
11
from recent_notifications.Globals import VERSION, WEBSITE
11
12
 
12
 
class build_servers(distutils.cmd.Command):
13
 
  description = "build bonobo server files"
 
13
class update_prefix(distutils.cmd.Command):
 
14
  description = "substitute $PREFIX with the current prefix"
14
15
 
15
16
  user_options = [
16
 
      ("server-files=", None, "server.in files that should be built")
 
17
      ("files=", None, ".in files that should be updated")
17
18
  ]
18
19
 
19
20
  def initialize_options(self):
20
 
    self.server_files = "[]"
 
21
    self.files = "[]"
21
22
 
22
23
  def finalize_options(self):
23
24
    pass
24
25
 
25
26
  def run(self):
26
27
    try:
27
 
      file_set = eval(self.server_files)
 
28
      file_set = eval(self.files)
28
29
    except:
29
 
      raise Exception("Invalid server-files option: " + self.server_files)
30
 
 
31
 
    data_files = self.distribution.data_files
32
 
 
33
 
    for (target, files) in file_set:
34
 
      files_built = []
35
 
      for file in files:
36
 
        if file.endswith("server.in"):
37
 
          output_file = file[:-3]
38
 
        else:
39
 
          raise Exception("Invalid server file: " + file)
40
 
 
41
 
        print "building server file", output_file
42
 
 
43
 
        with open(file, "r") as f:
44
 
          server_data = f.read()
45
 
 
46
 
        with open(output_file, "w") as f:
47
 
          f.write(Template(server_data).substitute(PREFIX=distutils.sysconfig.PREFIX))
48
 
 
49
 
        files_built.append(output_file)
50
 
      data_files.append((target, files_built))
51
 
 
52
 
build.sub_commands.append(("build_servers", None))
 
30
      raise Exception("Invalid files option: " + self.files)
 
31
 
 
32
    for file in file_set:
 
33
      if file.endswith(".in"):
 
34
        output_file = file[:-3]
 
35
      else:
 
36
        raise Exception("Invalid file: " + file)
 
37
 
 
38
      print "updating PREFIX in file", output_file
 
39
 
 
40
      with open(file, "r") as f:
 
41
        server_data = f.read()
 
42
 
 
43
      with open(output_file, "w") as f:
 
44
        f.write(Template(server_data).safe_substitute(PREFIX=distutils.sysconfig.PREFIX))
 
45
 
 
46
build.sub_commands.append(("update_prefix", None))
53
47
 
54
48
setup(
55
49
    name="recent-notifications",
70
64
            "icons/recent-notifications.svg"])
71
65
    ],
72
66
    cmdclass={
73
 
      "build_servers": build_servers
 
67
      "build": build_extra.build_extra,
 
68
      "build_i18n": build_i18n.build_i18n,
 
69
      "update_prefix": update_prefix
74
70
    }
75
71
)
76
72