Philipp Hörist pushed to branch master at gajim / gajim

Commits:

1 changed file:

Changes:

  • setup.py
    ... ... @@ -9,6 +9,7 @@ if sys.version_info < (3, 5):
    9 9
     from setuptools import setup, find_packages
    
    10 10
     from setuptools import Command
    
    11 11
     from setuptools.command.build_py import build_py as _build
    
    12
    +from setuptools.command.install import install as _install
    
    12 13
     from distutils import log
    
    13 14
     from distutils.util import convert_path, newer
    
    14 15
     
    
    ... ... @@ -18,6 +19,9 @@ import gajim
    18 19
     
    
    19 20
     pos = [x for x in os.listdir('po') if x[-3:] == ".po"]
    
    20 21
     ALL_LINGUAS = sorted([os.path.split(x)[-1][:-3] for x in pos])
    
    22
    +MAN_FILES = ['gajim.1', 'gajim-history-manager.1', 'gajim-remote.1']
    
    23
    +META_FILES = [('data/org.gajim.Gajim.desktop', 'share/applications', '--desktop'),
    
    24
    +              ('data/org.gajim.Gajim.appdata.xml', 'share/metainfo', '--xml')]
    
    21 25
     cwd = os.path.dirname(os.path.realpath(__file__))
    
    22 26
     build_dir = os.path.join(cwd, "build")
    
    23 27
     
    
    ... ... @@ -53,7 +57,6 @@ def build_trans(build_cmd):
    53 57
         '''
    
    54 58
         Translate the language files into gajim.mo
    
    55 59
         '''
    
    56
    -    data_files = build_cmd.distribution.data_files
    
    57 60
         for lang in ALL_LINGUAS:
    
    58 61
             po_file = os.path.join('po', lang + '.po')
    
    59 62
             mo_file = os.path.join(build_dir, 'mo', lang, 'LC_MESSAGES', 'gajim.mo')
    
    ... ... @@ -72,7 +75,11 @@ def build_trans(build_cmd):
    72 75
                         raise SystemExit(msg)
    
    73 76
                 log.info('Compiling %s >> %s', po_file, mo_file)
    
    74 77
     
    
    75
    -        # linux specific piece:
    
    78
    +
    
    79
    +def install_trans(install_cmd):
    
    80
    +    data_files = install_cmd.distribution.data_files
    
    81
    +    for lang in ALL_LINGUAS:
    
    82
    +        mo_file = os.path.join(build_dir, 'mo', lang, 'LC_MESSAGES', 'gajim.mo')
    
    76 83
             target = 'share/locale/' + lang + '/LC_MESSAGES'
    
    77 84
             data_files.append((target, [mo_file]))
    
    78 85
     
    
    ... ... @@ -81,14 +88,12 @@ def build_man(build_cmd):
    81 88
         '''
    
    82 89
         Compress Gajim manual files
    
    83 90
         '''
    
    84
    -    data_files = build_cmd.distribution.data_files
    
    85
    -    for man in ['gajim.1', 'gajim-history-manager.1', 'gajim-remote.1']:
    
    86
    -        filename = os.path.join('data', man)
    
    87
    -        newdir = os.path.join(build_dir, 'man')
    
    88
    -        if not (os.path.isdir(newdir) or os.path.islink(newdir)):
    
    89
    -            os.makedirs(newdir)
    
    91
    +    newdir = os.path.join(build_dir, 'man')
    
    92
    +    if not (os.path.isdir(newdir) or os.path.islink(newdir)):
    
    93
    +        os.makedirs(newdir)
    
    90 94
     
    
    91
    -        import gzip
    
    95
    +    for man in MAN_FILES:
    
    96
    +        filename = os.path.join('data', man)
    
    92 97
             man_file_gz = os.path.join(newdir, man + '.gz')
    
    93 98
             if os.path.exists(man_file_gz):
    
    94 99
                 if newer(filename, man_file_gz):
    
    ... ... @@ -97,13 +102,21 @@ def build_man(build_cmd):
    97 102
                     filename = False
    
    98 103
     
    
    99 104
             if filename:
    
    105
    +            import gzip
    
    100 106
                 # Binary io, so open is OK
    
    101 107
                 with open(filename, 'rb') as f_in,\
    
    102 108
                         gzip.open(man_file_gz, 'wb') as f_out:
    
    103 109
                     f_out.writelines(f_in)
    
    104 110
                     log.info('Compiling %s >> %s', filename, man_file_gz)
    
    105 111
     
    
    106
    -        target = 'share/man/man1'
    
    112
    +
    
    113
    +def install_man(install_cmd):
    
    114
    +    data_files = install_cmd.distribution.data_files
    
    115
    +    man_dir = os.path.join(build_dir, 'man')
    
    116
    +    target = 'share/man/man1'
    
    117
    +
    
    118
    +    for man in MAN_FILES:
    
    119
    +        man_file_gz = os.path.join(man_dir, man + '.gz')
    
    107 120
             data_files.append((target, [man_file_gz]))
    
    108 121
     
    
    109 122
     
    
    ... ... @@ -111,20 +124,22 @@ def build_intl(build_cmd):
    111 124
         '''
    
    112 125
         Merge translation files into desktop and mime files
    
    113 126
         '''
    
    114
    -    data_files = build_cmd.distribution.data_files
    
    115 127
         base = build_dir
    
    116 128
     
    
    117
    -    merge_files = (('data/org.gajim.Gajim.desktop', 'share/applications', '--desktop'),
    
    118
    -                   ('data/org.gajim.Gajim.appdata.xml', 'share/metainfo', '--xml'))
    
    119
    -
    
    120
    -    for filename, target, option in merge_files:
    
    129
    +    for filename, _, option in META_FILES:
    
    121 130
             filenamelocal = convert_path(filename)
    
    122 131
             newfile = os.path.join(base, filenamelocal)
    
    123 132
             newdir = os.path.dirname(newfile)
    
    124 133
             if not(os.path.isdir(newdir) or os.path.islink(newdir)):
    
    125 134
                 os.makedirs(newdir)
    
    126 135
             merge(filenamelocal + '.in', newfile, option)
    
    127
    -        data_files.append((target, [base + '/' + filename]))
    
    136
    +
    
    137
    +
    
    138
    +def install_intl(install_cmd):
    
    139
    +    data_files = install_cmd.distribution.data_files
    
    140
    +
    
    141
    +    for filename, target, _ in META_FILES:
    
    142
    +        data_files.append((target, [build_dir + '/' + filename]))
    
    128 143
     
    
    129 144
     
    
    130 145
     def merge(in_file, out_file, option, po_dir='po'):
    
    ... ... @@ -154,6 +169,15 @@ class build(_build):
    154 169
             _build.run(self)
    
    155 170
     
    
    156 171
     
    
    172
    +class install(_install):
    
    173
    +    def run(self):
    
    174
    +        install_trans(self)
    
    175
    +        if sys.platform != 'win32':
    
    176
    +            install_man(self)
    
    177
    +            install_intl(self)
    
    178
    +        _install.run(self)
    
    179
    +
    
    180
    +
    
    157 181
     class test(Command):
    
    158 182
         description = "Run all tests"
    
    159 183
         user_options = []
    
    ... ... @@ -243,6 +267,7 @@ setup(
    243 267
         ],
    
    244 268
         cmdclass={
    
    245 269
             'build_py': build,
    
    270
    +        'install': install,
    
    246 271
             'test': test,
    
    247 272
             'test_nogui': test_nogui,
    
    248 273
             'update_po': update_po,