~ubuntu-branches/debian/sid/alarm-clock/sid

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/python
#encoding: utf-8

from distutils.core import setup
import glob
from distutils.command.install import install as _install
from distutils.command.install_data import install_data as _install_data
from distutils.command.build import build as _build
from distutils import cmd
import msgfmt
import os
import shutil

AppName = "alarm-clock"
FullName = "Alarm Clock"
Version = "0.9.11"
Author = "Tomasz Sałaciński"
AuthorEmail = "tsalacinski@gmail.com"
Description = "Alarm Clock for GTK written in Python"
Url = "http://www.alarm-clock.54.pl"
License = "GPLv2"

Data = [('share/alarm-clock/glade',  ['glade/main.glade']),
        ('share/alarm-clock/scalable', glob.glob('scalable/*.svg')),
		('share/alarm-clock/sound', ['sound/ring.wav']),
        ('share/pixmaps' , ['scalable/alarm-clock.svg']),
        ('share/applications' , ['alarm-clock.desktop'])]


class build_trans(cmd.Command):
    description = 'Compile .po files into .mo files'
    
    def initialize_options(self):
        pass

    def finalize_options(self):        
        pass

    def run(self):
        po_dir = os.path.join(os.path.dirname(os.curdir), 'po')
        for path, names, filenames in os.walk(po_dir):
            for f in filenames:
                if f.endswith('.po'):
                    lang = f[:len(f) - 3]
                    src = os.path.join(path, f)
                    dest_path = os.path.join('build', 'locale', lang, 'LC_MESSAGES')
                    dest = os.path.join(dest_path, 'alarm-clock.mo')
                    if not os.path.exists(dest_path):
                        os.makedirs(dest_path)
                    if not os.path.exists(dest):
                        print 'Compiling %s' % src
                        msgfmt.make(src, dest)
                    else:
                        src_mtime = os.stat(src)[8]
                        dest_mtime = os.stat(dest)[8]
                        if src_mtime > dest_mtime:
                            print 'Compiling %s' % src
                            msgfmt.make(src, dest)

# Thanks to Iain Nicol for code to save the location for installed prefix
# At runtime, we need to know where we installed the data to.

class write_data_install_path(cmd.Command):
    description = 'saves the data installation path for access at runtime'
    
    def initialize_options(self):
        self.prefix = None
        self.lib_build_dir = None

    def finalize_options(self):
        self.set_undefined_options('install',
            ('prefix', 'prefix')
        )
        self.set_undefined_options('build',
            ('build_lib', 'lib_build_dir')
        )

    def run(self):
        conf_filename = os.path.join(self.lib_build_dir,
            'alarmclock', 'Prefix.py')

        conf_file = open(conf_filename, 'r')
        data = conf_file.read()
        conf_file.close()
        data = data.replace('@datadir@', self.prefix)
        conf_file = open(conf_filename, 'w')
        conf_file.write(data)
        conf_file.close()

    def get_outputs(self): return []



class unwrite_data_install_path(cmd.Command):
    description = 'undoes write_data_install_path'

    def initialize_options(self):
        self.lib_build_dir = None

    def finalize_options(self):        
        self.set_undefined_options('build',
            ('build_lib', 'lib_build_dir')
        )

    def run(self):
        dest = os.path.join(self.lib_build_dir,
            'alarmclock', 'Prefix.py')
        shutil.copyfile('alarm-clock/Prefix.py', dest)

    def get_outputs(self): return []



class install_data(_install_data):
    def run(self):
		for lang in os.listdir('build/locale/'):
			lang_dir = os.path.join('share', 'locale', lang, 'LC_MESSAGES')
			lang_file = os.path.join('build', 'locale', lang, 'LC_MESSAGES', 'alarm-clock.mo')
			self.data_files.append( (lang_dir, [lang_file]) )
		_install_data.run(self)

class build(_build):
    sub_commands = _build.sub_commands + [('build_trans', None)]
    def run(self):
        _build.run(self)

class install(_install):
    sub_commands = [('write_data_install_path', None)] + \
        _install.sub_commands + [('unwrite_data_install_path', None)]
    def run(self):
        _install.run(self)
        os.system("chmod 777 build -R")
        os.remove("msgfmt.pyc")


cmdline = {	'build': build,
			'install': install,
			'build_trans': build_trans,
			'install_data': install_data,
			'write_data_install_path': write_data_install_path,
			'unwrite_data_install_path': unwrite_data_install_path, }


setup(name=AppName, fullname=FullName, version=Version,
    author=Author, author_email=AuthorEmail, description=Description,
    url=Url, license=License,
    scripts=["scripts/alarm-clock"],
    packages=['alarmclock'],
    package_dir = {'alarmclock': 'alarm-clock'},
	data_files=Data,
	cmdclass=cmdline
)