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

Commits:

1 changed file:

Changes:

  • setup.py
    ... ... @@ -11,37 +11,36 @@
    11 11
     from setuptools.command.build_py import build_py as _build
    
    12 12
     from setuptools.command.install import install as _install
    
    13 13
     from distutils import log
    
    14
    -from distutils.util import convert_path, newer
    
    14
    +from distutils.util import newer
    
    15
    +from pathlib import Path
    
    15 16
     
    
    16
    -import subprocess
    
    17
    -
    
    18
    -pos = [x for x in os.listdir('po') if x[-3:] == ".po"]
    
    19
    -ALL_LINGUAS = sorted([os.path.split(x)[-1][:-3] for x in pos])
    
    17
    +pos = Path('po').glob('*.po')
    
    18
    +ALL_LINGUAS = sorted([x.stem for x in pos])
    
    20 19
     MAN_FILES = ['gajim.1', 'gajim-history-manager.1', 'gajim-remote.1']
    
    21 20
     META_FILES = [('data/org.gajim.Gajim.desktop', 'share/applications', '--desktop'),
    
    22 21
                   ('data/org.gajim.Gajim.appdata.xml', 'share/metainfo', '--xml')]
    
    23
    -cwd = os.path.dirname(os.path.realpath(__file__))
    
    24
    -build_dir = os.path.join(cwd, "build")
    
    22
    +cwd = Path(__file__).resolve().parent
    
    23
    +build_dir = cwd / 'build'
    
    25 24
     
    
    26 25
     
    
    27 26
     def update_trans():
    
    28 27
         '''
    
    29 28
         Update translation files
    
    30 29
         '''
    
    31
    -    template = os.path.join('po', 'gajim.pot')
    
    32
    -    files = [os.path.join(root, f) for root, d, files in os.walk('gajim') for f in files if os.path.isfile(
    
    33
    -        os.path.join(root, f)) and (f.endswith('.py') or f.endswith('.ui'))]
    
    34
    -    files.append(os.path.join("data", "org.gajim.Gajim.desktop.in"))
    
    35
    -    files.append(os.path.join("data", "org.gajim.Gajim.appdata.xml.in"))
    
    30
    +    template = Path('po') / 'gajim.pot'
    
    31
    +    files = list(Path('gajim').rglob('*.py'))
    
    32
    +    files.extend(Path('gajim').rglob('*.ui'))
    
    33
    +    files.append(Path('data') / 'org.gajim.Gajim.desktop.in')
    
    34
    +    files.append(Path('data') / 'org.gajim.Gajim.appdata.xml.in')
    
    36 35
         cmd = 'xgettext -c# --from-code=utf-8 --keyword=Q_ -o %s %s' % (
    
    37
    -        template, " ".join(files))
    
    36
    +        template, ' '.join([str(f) for f in files]))
    
    38 37
         if os.system(cmd) != 0:
    
    39
    -        msg = "ERROR: %s could not be created!\n" % template
    
    38
    +        msg = f'ERROR: {template} could not be created!\n'
    
    40 39
             raise SystemExit(msg)
    
    41 40
     
    
    42 41
         for lang in ALL_LINGUAS:
    
    43
    -        po_file = os.path.join('po', lang + '.po')
    
    44
    -        cmd = 'msgmerge -U %s %s' % (po_file, template)
    
    42
    +        po_file = Path('po') / (lang + '.po')
    
    43
    +        cmd = f'msgmerge -U {po_file} {template}'
    
    45 44
             if os.system(cmd) != 0:
    
    46 45
                 msg = 'ERROR: Updating language translation file failed.'
    
    47 46
                 ask = msg + '\n Continue updating y/n [n] '
    
    ... ... @@ -56,16 +55,16 @@ def build_trans(build_cmd):
    56 55
         Translate the language files into gajim.mo
    
    57 56
         '''
    
    58 57
         for lang in ALL_LINGUAS:
    
    59
    -        po_file = os.path.join('po', lang + '.po')
    
    60
    -        mo_file = os.path.join(build_dir, 'mo', lang, 'LC_MESSAGES', 'gajim.mo')
    
    61
    -        mo_dir = os.path.dirname(mo_file)
    
    62
    -        if not (os.path.isdir(mo_dir) or os.path.islink(mo_dir)):
    
    63
    -            os.makedirs(mo_dir)
    
    58
    +        po_file = Path('po') / (lang + '.po')
    
    59
    +        mo_file = build_dir / 'mo' / lang / 'LC_MESSAGES' / 'gajim.mo'
    
    60
    +        mo_dir = mo_file.parent
    
    61
    +        if not (mo_dir.is_dir() or mo_dir.is_symlink()):
    
    62
    +            mo_dir.mkdir(parents=True)
    
    64 63
     
    
    65 64
             if newer(po_file, mo_file):
    
    66
    -            cmd = 'msgfmt %s -o %s' % (po_file, mo_file)
    
    65
    +            cmd = f'msgfmt {po_file} -o {mo_file}'
    
    67 66
                 if os.system(cmd) != 0:
    
    68
    -                os.remove(mo_file)
    
    67
    +                mo_file.unlink()
    
    69 68
                     msg = 'ERROR: Building language translation files failed.'
    
    70 69
                     ask = msg + '\n Continue building y/n [n] '
    
    71 70
                     reply = input(ask)
    
    ... ... @@ -77,8 +76,8 @@ def build_trans(build_cmd):
    77 76
     def install_trans(install_cmd):
    
    78 77
         data_files = install_cmd.distribution.data_files
    
    79 78
         for lang in ALL_LINGUAS:
    
    80
    -        mo_file = os.path.join(build_dir, 'mo', lang, 'LC_MESSAGES', 'gajim.mo')
    
    81
    -        target = 'share/locale/' + lang + '/LC_MESSAGES'
    
    79
    +        mo_file = str(build_dir / 'mo' / lang / 'LC_MESSAGES' / 'gajim.mo')
    
    80
    +        target = f'share/locale/{lang}/LC_MESSAGES'
    
    82 81
             data_files.append((target, [mo_file]))
    
    83 82
     
    
    84 83
     
    
    ... ... @@ -86,35 +85,34 @@ def build_man(build_cmd):
    86 85
         '''
    
    87 86
         Compress Gajim manual files
    
    88 87
         '''
    
    89
    -    newdir = os.path.join(build_dir, 'man')
    
    90
    -    if not (os.path.isdir(newdir) or os.path.islink(newdir)):
    
    91
    -        os.makedirs(newdir)
    
    88
    +    newdir = build_dir / 'man'
    
    89
    +    if not (newdir.is_dir() or newdir.is_symlink()):
    
    90
    +        newdir.mkdir()
    
    92 91
     
    
    93 92
         for man in MAN_FILES:
    
    94
    -        filename = os.path.join('data', man)
    
    95
    -        man_file_gz = os.path.join(newdir, man + '.gz')
    
    96
    -        if os.path.exists(man_file_gz):
    
    93
    +        filename = Path('data') / man
    
    94
    +        man_file_gz = newdir / (man + '.gz')
    
    95
    +        if man_file_gz.exists():
    
    97 96
                 if newer(filename, man_file_gz):
    
    98
    -                os.remove(man_file_gz)
    
    97
    +                man_file_gz.unlink()
    
    99 98
                 else:
    
    100
    -                filename = False
    
    99
    +                continue
    
    101 100
     
    
    102
    -        if filename:
    
    103
    -            import gzip
    
    104
    -            # Binary io, so open is OK
    
    105
    -            with open(filename, 'rb') as f_in,\
    
    106
    -                    gzip.open(man_file_gz, 'wb') as f_out:
    
    107
    -                f_out.writelines(f_in)
    
    108
    -                log.info('Compiling %s >> %s', filename, man_file_gz)
    
    101
    +        import gzip
    
    102
    +        # Binary io, so open is OK
    
    103
    +        with open(filename, 'rb') as f_in,\
    
    104
    +                gzip.open(man_file_gz, 'wb') as f_out:
    
    105
    +            f_out.writelines(f_in)
    
    106
    +            log.info('Compiling %s >> %s', filename, man_file_gz)
    
    109 107
     
    
    110 108
     
    
    111 109
     def install_man(install_cmd):
    
    112 110
         data_files = install_cmd.distribution.data_files
    
    113
    -    man_dir = os.path.join(build_dir, 'man')
    
    111
    +    man_dir = build_dir / 'man'
    
    114 112
         target = 'share/man/man1'
    
    115 113
     
    
    116 114
         for man in MAN_FILES:
    
    117
    -        man_file_gz = os.path.join(man_dir, man + '.gz')
    
    115
    +        man_file_gz = str(man_dir / (man + '.gz'))
    
    118 116
             data_files.append((target, [man_file_gz]))
    
    119 117
     
    
    120 118
     
    
    ... ... @@ -125,26 +123,25 @@ def build_intl(build_cmd):
    125 123
         base = build_dir
    
    126 124
     
    
    127 125
         for filename, _, option in META_FILES:
    
    128
    -        filenamelocal = convert_path(filename)
    
    129
    -        newfile = os.path.join(base, filenamelocal)
    
    130
    -        newdir = os.path.dirname(newfile)
    
    131
    -        if not(os.path.isdir(newdir) or os.path.islink(newdir)):
    
    132
    -            os.makedirs(newdir)
    
    133
    -        merge(filenamelocal + '.in', newfile, option)
    
    126
    +        newfile = base / filename
    
    127
    +        newdir = newfile.parent
    
    128
    +        if not(newdir.is_dir() or newdir.is_symlink()):
    
    129
    +            newdir.mkdir()
    
    130
    +        merge(Path(filename + '.in'), newfile, option)
    
    134 131
     
    
    135 132
     
    
    136 133
     def install_intl(install_cmd):
    
    137 134
         data_files = install_cmd.distribution.data_files
    
    138 135
     
    
    139 136
         for filename, target, _ in META_FILES:
    
    140
    -        data_files.append((target, [build_dir + '/' + filename]))
    
    137
    +        data_files.append((target, [str(build_dir / filename)]))
    
    141 138
     
    
    142 139
     
    
    143 140
     def merge(in_file, out_file, option, po_dir='po'):
    
    144 141
         '''
    
    145 142
         Run the msgfmt command.
    
    146 143
         '''
    
    147
    -    if os.path.exists(in_file):
    
    144
    +    if in_file.exists():
    
    148 145
             cmd = (('msgfmt %(opt)s -d %(po_dir)s --template %(in_file)s '
    
    149 146
                     '-o %(out_file)s') %
    
    150 147
                    {'opt': option,