| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# Copyright 2014 (C) Raster Software Vigo (Sergio Costas) |
| 4 |
# |
| 5 |
# This file is part of DeVeDe-NG |
| 6 |
# |
| 7 |
# DeVeDe-NG is free software; you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License version 3 |
| 9 |
# as published by the Free Software Foundation. |
| 10 |
# |
| 11 |
# DeVeDe-NG is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/> |
| 18 |
|
| 19 |
from gi.repository import GObject |
| 20 |
import os |
| 21 |
import importlib.metadata |
| 22 |
import platform |
| 23 |
|
| 24 |
|
| 25 |
class configuration(GObject.GObject): |
| 26 |
|
| 27 |
current_configuration = None |
| 28 |
__gsignals__ = {'disc_type': (GObject.SIGNAL_RUN_FIRST, None, (str,))} |
| 29 |
|
| 30 |
@staticmethod |
| 31 |
def get_config(): |
| 32 |
if configuration.current_configuration is None: |
| 33 |
configuration.current_configuration = configuration() |
| 34 |
if (configuration.current_configuration._fill_config()): |
| 35 |
configuration.current_configuration = None |
| 36 |
return configuration.current_configuration |
| 37 |
|
| 38 |
def __init__(self): |
| 39 |
GObject.GObject.__init__(self) |
| •40 |
self.version = '4.21.3.1' |
| 41 |
print("Version: " + self.version) |
| 42 |
|
| 43 |
def _get_config_folder(self): |
| 44 |
config_folder = os.environ.get("$XDG_CONFIG_HOME") |
| 45 |
if config_folder is None: |
| 46 |
config_folder = os.path.join(os.environ.get("HOME"), ".config") |
| 47 |
config_folder = os.path.join(config_folder, "devedeng") |
| 48 |
if not os.path.exists(config_folder): |
| 49 |
os.makedirs(config_folder) |
| 50 |
return config_folder |
| 51 |
|
| 52 |
def _fill_config(self): |
| 53 |
self.cores = os.cpu_count() |
| 54 |
if 'sched_getaffinity' in dir(os): |
| 55 |
self.cores = len(os.sched_getaffinity(0)) |
| 56 |
if platform.system() == 'FreeBSD': |
| 57 |
self.cores = int(os.popen("sysctl -n kern.smp.cores").read().split('\n')[0]) |
| 58 |
|
| 59 |
self.log = "" |
| 60 |
self.static_log = "" |
| 61 |
self.disc_type = None |
| 62 |
|
| 63 |
# try: |
| 64 |
# os.stat("/usr/share/devedeng/wselect_disk.ui") |
| 65 |
# is_local = False |
| 66 |
# except: |
| 67 |
# pass |
| 68 |
|
| 69 |
# if is_local is None: |
| 70 |
# try: |
| 71 |
# os.stat("/usr/local/share/devedeng/wselect_disk.ui") |
| 72 |
# is_local = True |
| 73 |
# except: |
| 74 |
# pass |
| 75 |
|
| 76 |
# if is_local is None: |
| 77 |
# return True |
| 78 |
# else: |
| 79 |
# if (is_local): |
| 80 |
# # locales must be always at /usr/share/locale because |
| 81 |
# # Gtk.Builder always search there |
| 82 |
# self.share_locale = "/usr/share/locale" |
| 83 |
# self.glade = "/usr/local/share/devedeng" |
| 84 |
# self.pic_path = "/usr/local/share/devedeng" |
| 85 |
# self.other_path = "/usr/local/share/devedeng" |
| 86 |
# self.help_path = "/usr/local/share/doc/devedeng" |
| 87 |
# else: |
| 88 |
# self.share_locale = "/usr/share/locale" |
| 89 |
# self.glade = "/usr/share/devedeng" |
| 90 |
# self.pic_path = "/usr/share/devedeng" |
| 91 |
# self.other_path = "/usr/share/devedeng" |
| 92 |
# self.help_path = "/usr/share/doc/devedeng" |
| 93 |
|
| 94 |
data_dir = os.path.join(os.path.dirname(__file__), 'data') |
| 95 |
self.share_locale = os.path.join(data_dir, "locale") |
| 96 |
self.glade = os.path.join(data_dir, "interface") |
| 97 |
self.pic_path = os.path.join(data_dir, "pixmaps") |
| 98 |
self.other_path = data_dir |
| •99 |
self.help_path = "/usr/share/doc/devedeng/html/" |
| 100 |
|
| 101 |
self.gettext_domain = "devedeng" |
| 102 |
|
| 103 |
self.PAL = True |
| 104 |
self.tmp_folder = "/var/tmp" |
| 105 |
self.multicore = self.cores |
| 106 |
self.final_folder = os.environ.get("HOME") |
| 107 |
self.sub_language = None |
| 108 |
self.sub_codepage = None |
| 109 |
self.film_analizer = None |
| 110 |
self.film_player = None |
| 111 |
self.film_converter = None |
| 112 |
self.menu_converter = None |
| 113 |
self.subtitles_font_size = 28 |
| 114 |
self.sub_language = None |
| 115 |
self.sub_codepage = None |
| 116 |
self.burner = None |
| 117 |
self.mkiso = None |
| 118 |
self.subt_fill_color = (1, 1, 1, 1) |
| 119 |
self.subt_outline_color = (0, 0, 0, 1) |
| 120 |
self.subt_outline_thickness = 0.0 |
| 121 |
|
| 122 |
config_folder = self._get_config_folder() |
| 123 |
config_path = os.path.join(config_folder, "devedeng.cfg") |
| 124 |
if not os.path.exists(config_path): |
| 125 |
# old config file |
| 126 |
config_path = os.path.join(os.environ.get("HOME"), ".devedeng") |
| 127 |
|
| 128 |
try: |
| 129 |
config_data = open(config_path, "r") |
| 130 |
for linea in config_data: |
| 131 |
linea = linea.strip() |
| 132 |
if linea == "": |
| 133 |
continue |
| 134 |
if linea[0] == "#": |
| 135 |
continue |
| 136 |
if linea[:13] == "video_format:": |
| 137 |
if linea[13:].strip() == "pal": |
| 138 |
self.PAL = True |
| 139 |
elif linea[13:].strip() == "ntsc": |
| 140 |
self.PAL = False |
| 141 |
continue |
| 142 |
if linea[:12] == "temp_folder:": |
| 143 |
self.tmp_folder = linea[12:].strip() |
| 144 |
continue |
| 145 |
if linea[:10] == "multicore:": |
| 146 |
self.multicore = int(linea[10:].strip()) |
| 147 |
continue |
| 148 |
if linea[:13] == "final_folder:": |
| 149 |
self.final_folder = linea[13:].strip() |
| 150 |
continue |
| 151 |
if linea[:13] == "sub_language:": |
| 152 |
self.sub_language = linea[13:].strip() |
| 153 |
continue |
| 154 |
if linea[:13] == "sub_codepage:": |
| 155 |
self.sub_codepage = linea[13:].strip() |
| 156 |
continue |
| 157 |
if linea[:14] == "film_analizer:": |
| 158 |
self.film_analizer = linea[14:].strip() |
| 159 |
continue |
| 160 |
if linea[:12] == "film_player:": |
| 161 |
self.film_player = linea[12:].strip() |
| 162 |
continue |
| 163 |
if linea[:15] == "film_converter:": |
| 164 |
self.film_converter = linea[15:].strip() |
| 165 |
continue |
| 166 |
if linea[:15] == "menu_converter:": |
| 167 |
self.menu_converter = linea[15:].strip() |
| 168 |
continue |
| 169 |
if linea[:7] == "burner:": |
| 170 |
self.burner = linea[7:].strip() |
| 171 |
continue |
| 172 |
if linea[:6] == "mkiso:": |
| 173 |
self.mkiso = linea[6:].strip() |
| 174 |
continue |
| 175 |
if linea[:19] == "subtitle_font_size:": |
| 176 |
self.subtitles_font_size = int(linea[19:].strip()) |
| 177 |
continue |
| 178 |
if linea[:20] == "subtitle_fill_color:": |
| 179 |
c = linea[20:].strip().split(",") |
| 180 |
self.subt_fill_color = ( |
| 181 |
float(c[0]), float(c[1]), float(c[2]), 1.0) |
| 182 |
if linea[:23] == "subtitle_outline_color:": |
| 183 |
c = linea[23:].strip().split(",") |
| 184 |
self.subt_outline_color = ( |
| 185 |
float(c[0]), float(c[1]), float(c[2]), 1.0) |
| 186 |
if linea[:27] == "subtitle_outilne_thickness:": |
| 187 |
self.subt_outline_thickness = float(linea[27:].strip()) |
| 188 |
config_data.close() |
| 189 |
except: |
| 190 |
pass |
| 191 |
|
| 192 |
return False |
| 193 |
|
| 194 |
def set_disc_type(self, disc_type): |
| 195 |
|
| 196 |
self.disc_type = disc_type |
| 197 |
self.clear_static_log() |
| 198 |
self.clear_log() |
| 199 |
self.emit('disc_type', disc_type) |
| 200 |
|
| 201 |
def save_config(self): |
| 202 |
|
| 203 |
config_path = os.path.join(self._get_config_folder(), "devedeng.cfg") |
| 204 |
try: |
| 205 |
config_data = open(config_path, "w") |
| 206 |
config_data.write("video_format:") |
| 207 |
if (self.PAL): |
| 208 |
config_data.write("pal\n") |
| 209 |
else: |
| 210 |
config_data.write("ntsc\n") |
| 211 |
if (self.tmp_folder is not None): |
| 212 |
config_data.write("temp_folder:" + str(self.tmp_folder) + "\n") |
| 213 |
config_data.write("multicore:" + str(self.multicore) + "\n") |
| 214 |
if (self.final_folder is not None): |
| 215 |
config_data.write("final_folder:" + |
| 216 |
str(self.final_folder) + "\n") |
| 217 |
if (self.sub_language is not None): |
| 218 |
config_data.write("sub_language:" + |
| 219 |
str(self.sub_language) + "\n") |
| 220 |
if (self.sub_codepage is not None): |
| 221 |
config_data.write("sub_codepage:" + |
| 222 |
str(self.sub_codepage) + "\n") |
| 223 |
if (self.film_analizer is not None): |
| 224 |
config_data.write("film_analizer:" + |
| 225 |
str(self.film_analizer) + "\n") |
| 226 |
if (self.film_player is not None): |
| 227 |
config_data.write( |
| 228 |
"film_player:" + str(self.film_player) + "\n") |
| 229 |
if (self.film_converter is not None): |
| 230 |
config_data.write("film_converter:" + |
| 231 |
str(self.film_converter) + "\n") |
| 232 |
if (self.menu_converter is not None): |
| 233 |
config_data.write("menu_converter:" + |
| 234 |
str(self.menu_converter) + "\n") |
| 235 |
if self.burner is not None: |
| 236 |
config_data.write("burner:" + str(self.burner) + "\n") |
| 237 |
if self.mkiso is not None: |
| 238 |
config_data.write("mkiso:" + str(self.mkiso) + "\n") |
| 239 |
if (self.sub_codepage is not None): |
| 240 |
config_data.write("sub_codepage:" + |
| 241 |
str(self.sub_codepage) + "\n") |
| 242 |
if (self.sub_language is not None): |
| 243 |
config_data.write("sub_language:" + |
| 244 |
str(self.sub_language) + "\n") |
| 245 |
config_data.write("subtitle_font_size:" + |
| 246 |
str(self.subtitles_font_size) + "\n") |
| 247 |
config_data.write("subtitle_fill_color:" + str(self.subt_fill_color[0]) + "," + str( |
| 248 |
self.subt_fill_color[1]) + "," + str(self.subt_fill_color[2]) + "\n") |
| 249 |
config_data.write("subtitle_outline_color:" + str(self.subt_outline_color[0]) + "," + str( |
| 250 |
self.subt_outline_color[1]) + "," + str(self.subt_outline_color[2]) + "\n") |
| 251 |
config_data.write("subtitle_outilne_thickness:" + |
| 252 |
str(self.subt_outline_thickness)) |
| 253 |
|
| 254 |
config_data.close() |
| 255 |
# remove old configuration files |
| 256 |
config_path = os.path.join(os.environ.get("HOME"), ".devedeng") |
| 257 |
if os.path.exists(config_path): |
| 258 |
os.remove(config_path) |
| 259 |
except: |
| 260 |
pass |
| 261 |
|
| 262 |
def append_log(self, data, cr=True): |
| 263 |
|
| 264 |
self.log += data |
| 265 |
if (cr): |
| 266 |
self.log += "\n" |
| 267 |
|
| 268 |
def append_static_log(self, data, cr=True): |
| 269 |
|
| 270 |
self.static_log += data |
| 271 |
if (cr): |
| 272 |
self.static_log += "\n" |
| 273 |
|
| 274 |
def clear_log(self): |
| 275 |
|
| 276 |
self.log = "" |
| 277 |
|
| 278 |
def clear_static_log(self): |
| 279 |
|
| 280 |
self.static_log = "" |
| 281 |
|
| 282 |
def get_log(self): |
| 283 |
|
| 284 |
return "Static data:\n\n" + self.static_log + "\n\nDynamic data:\n\n" + self.log |