-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·171 lines (144 loc) · 5.66 KB
/
setup.py
File metadata and controls
executable file
·171 lines (144 loc) · 5.66 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python
"""
Setup script for Setup Station.
Setup Station is GhostBSD's post-installation setup utility, providing
a GTK+ interface for language, keyboard, timezone, network, and user configuration.
"""
import os
import sys
from setuptools import setup, Command
import glob
from DistUtilsExtra.command.build_extra import build_extra
from DistUtilsExtra.command.build_i18n import build_i18n
from DistUtilsExtra.command.clean_i18n import clean_i18n
prefix = sys.prefix
__VERSION__ = '0.1'
PROGRAM_VERSION = __VERSION__
def data_file_list(install_base, source_base):
"""
Generate list of data files for installation.
Args:
install_base: Base installation path
source_base: Source directory to scan
Returns:
List of (install_path, files) tuples for setuptools
"""
data = []
for root, subFolders, files in os.walk(source_base):
file_list = []
for f in files:
file_list.append(os.path.join(root, f))
# Only add directories that actually have files
if file_list:
data.append((root.replace(source_base, install_base), file_list))
return data
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/setup-station.pot'
po_files = glob.glob('po/*.po')
# Check if .pot file exists, create it if it doesn't
if not os.path.exists(pot_file):
print(f"POT file {pot_file} does not exist. Creating it...")
else:
print("Updating existing .pot file...")
# Step 1: Extract messages to .pot file (create or update)
print("Extracting messages to .pot file...")
os.makedirs('po', exist_ok=True)
os.system(
f'xgettext --from-code=UTF-8 -L Python --keyword=get_text -o {pot_file}'
' setup_station/*.py setup-station-init'
)
# Verify .pot file was created successfully
if not os.path.exists(pot_file):
print(f"Error: Failed to create {pot_file}")
return
# Fix charset to UTF-8 in the .pot file
print("Setting charset to UTF-8 in .pot file...")
os.system(f"sed -i '' 's/charset=CHARSET/charset=UTF-8/g' {pot_file}")
# 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/setup-station.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.makedirs(po_dir, exist_ok=True)
os.system(
f'xgettext --from-code=UTF-8 -L Python --keyword=get_text -o {pot_file}'
' setup_station/*.py setup-station-init'
)
# Fix charset to UTF-8 in the .pot file
print("Setting charset to UTF-8 in .pot file...")
os.system(f"sed -i '' 's/charset=CHARSET/charset=UTF-8/g' {pot_file}")
# 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}")
lib_setup_station_image = [
'src/image/G_logo.gif',
'src/image/install-gbsd.png',
'src/image/install-gbsd.svg',
'src/image/logo.png',
'src/image/disk.png',
'src/image/laptop.png',
'src/image/install.png',
'src/image/installation.jpg'
]
data_files = [
(f'{prefix}/lib/setup-station', ['src/ghostbsd-style.css']),
(f'{prefix}/lib/setup-station/image', lib_setup_station_image),
(f'{prefix}/share/applications', ['src/setup-station.desktop'])
]
# Add locale files if they exist
if os.path.exists('build/mo'):
data_files.extend(data_file_list(f'{prefix}/share/locale', 'build/mo'))
setup(
name="setup-station",
version=PROGRAM_VERSION,
description="Setup Station - GhostBSD post-installation setup utility",
license='BSD',
author='Eric Turgeon',
url='https://github.com/GhostBSD/setup-station/',
package_dir={'': '.'},
install_requires=['setuptools'],
packages=['setup_station'],
scripts=['setup-station-init'],
data_files=data_files,
cmdclass={
'create_translation': CreateTranslationCommand,
'update_translations': UpdateTranslationsCommand,
"build": build_extra,
"build_i18n": build_i18n,
"clean": clean_i18n
}
)