~umang/indicator-stickynotes/trunk

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Umang Varma
  • Date: 2012-06-24 22:40:32 UTC
  • Revision ID: git-v1:74f9ef705fe3bc56fbb9d773d766a36a489f9075
Made python code pwd agnostic (hopefully)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python3
2
2
# -*- coding: utf-8 -*-
3
3
4
 
# Copyright © 2012-2018 Umang Varma <umang.me@gmail.com>
 
4
# Copyright © 2012 Umang Varma <umang.me@gmail.com>
5
5
6
6
# This file is part of indicator-stickynotes.
7
7
19
19
# indicator-stickynotes.  If not, see <http://www.gnu.org/licenses/>.
20
20
 
21
21
from distutils.core import setup
22
 
from distutils.cmd import Command
23
 
import distutils.command.build, distutils.command.install_data, \
24
 
    distutils.command.clean
25
 
 
26
 
from subprocess import call
27
 
 
28
22
import glob
29
 
import os
30
 
import sys
31
 
import shutil
32
 
 
33
 
sys.dont_write_bytecode = True
34
 
from stickynotes.info import PO_DIR, MO_DIR, LOCALE_DOMAIN
35
 
sys.dont_write_bytecode = False
36
 
 
37
 
class BuildPo(Command):
38
 
    """Builds translation files
39
 
    
40
 
    This is useful for testing translations that haven't been installed"""
41
 
    user_options = []
42
 
    def initialize_options(self):
43
 
        pass
44
 
    def finalize_options(self):
45
 
        pass
46
 
    def run(self):
47
 
        """Compiles .po files in PO_DIR to .mo files in MO_DIR"""
48
 
        for file in glob.glob(os.path.join(PO_DIR, "*.po")):
49
 
            locale = os.path.splitext(os.path.basename(file))[0]
50
 
            dest = os.path.join(MO_DIR, locale, "LC_MESSAGES",
51
 
                    LOCALE_DOMAIN + ".mo")
52
 
            os.makedirs(os.path.dirname(dest), exist_ok=True)
53
 
            try:
54
 
                ret = call(["msgfmt", "-o", dest, file])
55
 
            except OSError:
56
 
                raise Exception("Error: Unable to run msgfmt")
57
 
            if ret:
58
 
                raise Exception("Error: msgfmt returned error code {0}" \
59
 
                        .format(ret))
60
 
 
61
 
class Build(distutils.command.build.build):
62
 
    # build should depend on build_po
63
 
    sub_commands = distutils.command.build.build.sub_commands + \
64
 
            [('build_po', None)]
65
 
 
66
 
class Clean(distutils.command.clean.clean):
67
 
    def run(self):
68
 
        # delete MO_DIR files before cleaning everything else
69
 
        print("Deleting {0}/ and contents".format(MO_DIR))
70
 
        shutil.rmtree(MO_DIR, ignore_errors=True)
71
 
        return super().run()
72
 
 
73
 
class InstallData(distutils.command.install_data.install_data):
74
 
    """Find icon and translation files before continuing install process"""
75
 
 
76
 
    def run(self):
77
 
        self.data_files.extend([(os.path.join("/usr/share/", dir),
78
 
            [os.path.join(dir, file) for file in files]) for dir, subdirs,
79
 
            files in os.walk("locale") if files])
80
 
        return super().run()
81
 
 
82
 
def main():
83
 
    # Default data files
84
 
    data_files = [('', ('COPYING', 'style.css', 'StickyNotes.ui',
85
 
                    'style_global.css', 'GlobalDialogs.ui',
86
 
                    'SettingsCategory.ui')),
87
 
                ('/usr/share/applications', ('indicator-stickynotes.desktop',)),
88
 
                ('Icons', glob.glob("Icons/*.png"))]
89
 
    # Icon themes
90
 
    icon_themes = ["hicolor", "ubuntu-mono-dark", "ubuntu-mono-light"]
91
 
    for theme in icon_themes:
92
 
        data_files.extend([(os.path.join("/usr/share/icons/", theme,
93
 
            os.path.relpath(dir, "Icons/" + theme)), [os.path.join(
94
 
                dir, file) for file in files])
95
 
            for dir, subdirs, files in os.walk("Icons/" + theme) if files])
96
 
 
97
 
    setup(name='indicator-stickynotes',
98
 
            version='0.5.10',
99
 
            description='Sticky Notes Indicator',
100
 
            author='Umang Varma',
101
 
            author_email='umang.me@gmail.com',
102
 
            url='https://www.launchpad.net/indicator-stickynotes/',
103
 
            packages=['stickynotes',],
104
 
            scripts=['indicator-stickynotes.py',],
105
 
            data_files=data_files,
106
 
            cmdclass={'build': Build, 'install_data': InstallData,
107
 
                'build_po': BuildPo, 'clean':Clean},
108
 
            long_description="Write reminders on notes with Indicator "
109
 
                "Stickynotes")
110
 
 
111
 
if __name__ == "__main__":
112
 
    main()
 
23
 
 
24
setup(name='indicator-stickynotes',
 
25
        version='0.1',
 
26
        description='Sticky Notes AppIndicator',
 
27
        author='Umang Varma',
 
28
        author_email='umang.me@gmail.com',
 
29
        url='https://www.launchpad.net/indicator-stickynotes/',
 
30
        packages=['stickynotes',],
 
31
        scripts=['indicator-stickynotes.py',],
 
32
        data_files=[('Icons', glob.glob("Icons/*.png")),
 
33
            ('/usr/share/icons/hicolor/48x48/apps/',
 
34
                ('Icons/48x48/indicator-stickynotes.png',)),
 
35
            ('/usr/share/icons/hicolor/256x256/apps/',
 
36
                ('Icons/256x256/indicator-stickynotes.png',)),
 
37
            ('/usr/share/applications/',
 
38
                ('indicator-stickynotes.desktop',)),
 
39
            ('', ('COPYING', 'style.css', 'StickyNotes.glade')),]
 
40
        )