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
|
#!/usr/bin/env python3
import os
import shutil
import subprocess
from os.path import exists, join
from pathlib import Path
from setuptools import setup
# Read README.md
this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text()
# Update the translations
PO_DIR = 'translations'
if not exists(PO_DIR):
os.makedirs(PO_DIR)
subprocess.check_call(["xgettext", "-o", join(PO_DIR, "caffeine-indicator.pot"), "--language=python", "--from-code=UTF-8", "caffeine-indicator"])
def compile_catalog(po_dir, prg_name):
po_files = []
for dirpath, _, filenames in os.walk(po_dir):
for file in filenames:
if file.split('.')[-1] == "po":
po_files.append(os.path.join(dirpath, file))
for po in po_files:
lang = po.split('/')[-1]
print("Compiling for Locale: "+"".join(lang.split(".")[:-1]))
lang = lang.split('-')[-1]
lang = lang.split('.')[0]
lang = lang.strip()
if not lang:
continue
lang_lc_dir = os.path.join('share', 'locale', lang, 'LC_MESSAGES')
if not os.path.isdir(lang_lc_dir):
os.makedirs(lang_lc_dir)
subprocess.check_call(["msgfmt", po, "-o", os.path.join(lang_lc_dir,prg_name+".mo")])
compile_catalog(PO_DIR, "caffeine-indicator")
# Add extra data files
data_files = []
for path, _, files in os.walk("share"):
if len(files) > 0:
data_files.append(tuple((path,
[join(path, file) for file in files])))
desktop_name = "caffeine.desktop"
desktop_file = join("share", "applications", desktop_name)
autostart_dir = join("etc", "xdg", "autostart")
if not exists(autostart_dir):
os.makedirs(autostart_dir)
shutil.copy(desktop_file, autostart_dir)
data_files.append(tuple(("/" + autostart_dir, [join(autostart_dir, desktop_name)])))
setup(name="cups_of_caffeine",
version="2.9.14",
description="Keep your computer awake.",
license="GPLv3",
author="Reuben Thomas",
author_email="rrt@sc3d.org",
url="https://launchpad.net/caffeine",
long_description=long_description,
long_description_content_type = "text/markdown",
data_files=data_files,
scripts=["caffeine", "caffeinate", "caffeine-indicator"],
py_modules=[], # Workaround for setuptools >= 61.0; see https://bugs.launchpad.net/caffeine/+bug/1981419
)
|