-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathsetup.py
executable file
·124 lines (102 loc) · 4.18 KB
/
setup.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
from platform import system
from subprocess import run
from setuptools import setup, Command, glob
__VERSION__ = '6.5'
PROGRAM_VERSION = __VERSION__
prefix = '/usr/local' if system() == 'FreeBSD' else sys.prefix
def datafilelist(installbase, sourcebase):
datafileList = []
for root, subFolders, files in os.walk(sourcebase):
fileList = []
for f in files:
fileList.append(os.path.join(root, f))
datafileList.append((root.replace(sourcebase, installbase), fileList))
return datafileList
class UpdateTranslationsCommand(Command):
"""Custom command to extract messages and update .po files."""
description = 'Extract messages to .pot and update .po'
user_options = [] # No custom options
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
# Define paths
pot_file = 'po/networkmgr.pot'
po_files = glob.glob('po/*.po')
# Step 1: Extract messages to .pot file
print("Extracting messages to .pot file...")
os.system(f'xgettext --from-code=UTF-8 -L Python -o {pot_file} networkmgr/*.py networkmgr')
# Step 2: Update .po files with the new .pot file
print("Updating .po files with new translations...")
for po_file in po_files:
print(f"Updating {po_file}...")
os.system(f'msgmerge -U {po_file} {pot_file}')
print("Translation update complete.")
class CreateTranslationCommand(Command):
"""Custom command to create a new .po file for a specific language."""
locale = None
description = 'Create a new .po file for the specified language'
user_options = [
('locale=', 'l', 'Locale code for the new translation (e.g., fr, es)')
]
def initialize_options(self):
self.locale = None # Initialize the locale option to None
def finalize_options(self):
if self.locale is None:
raise Exception("You must specify the locale code (e.g., --locale=fr)")
def run(self):
# Define paths
pot_file = 'po/networkmgr.pot'
po_dir = 'po'
po_file = os.path.join(po_dir, f'{self.locale}.po')
# Check if the .pot file exists
if not os.path.exists(pot_file):
print("Extracting messages to .pot file...")
os.system(f'xgettext --from-code=UTF-8 -L Python -o {pot_file} networkmgr/*.py networkmgr')
# Create the new .po file
if not os.path.exists(po_file):
print(f"Creating new {po_file} for locale '{self.locale}'...")
os.makedirs(po_dir, exist_ok=True)
os.system(f'msginit --locale={self.locale} --input={pot_file} --output-file={po_file}')
else:
print(f"PO file for locale '{self.locale}' already exists: {po_file}")
networkmgr_share = [
'src/auto-switch.py',
'src/link-up.py',
'src/setup-nic.py'
]
data_files = [
(f'{prefix}/etc/xdg/autostart', ['src/networkmgr.desktop']),
(f'{prefix}/share/networkmgr', networkmgr_share),
(f'{prefix}/share/locale/zh_CN/LC_MESSAGES', ['src/locale/zh_CN/networkmgr.mo']),
(f'{prefix}/share/locale/ru/LC_MESSAGES', ['src/locale/ru/networkmgr.mo']),
(f'{prefix}/etc/sudoers.d', ['src/sudoers.d/networkmgr'])
]
if os.path.exists('/etc/devd'):
data_files.append((f'{prefix}/etc/devd', ['src/networkmgr.conf']))
if os.path.exists('/etc/devd-openrc'):
data_files.append((f'{prefix}/etc/devd-openrc', ['src/networkmgr.conf']))
data_files.extend(datafilelist(f'{prefix}/share/icons/hicolor', 'src/icons'))
setup(
name="NetworkMgr",
version=PROGRAM_VERSION,
description="NetworkMgr is a tool to manage FreeBSD/GhostBSD network",
license='BSD',
author='Eric Turgeon',
url='https://github/GhostBSD/networkmgr/',
package_dir={'': '.'},
data_files=data_files,
install_requires=['setuptools'],
packages=['NetworkMgr'],
scripts=['networkmgr', 'networkmgr_configuration'],
cmdclass={
'create_translation': CreateTranslationCommand,
'update_translations': UpdateTranslationsCommand,
}
)
run('gtk-update-icon-cache -f /usr/local/share/icons/hicolor', shell=True)