Skip to content

Commit

Permalink
minor fixes and code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanslack committed Oct 28, 2024
1 parent 3cae226 commit a8a2b0f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 56 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ License: GPL3
Change Log:

+------------------------------------+
Sun, 13 Oct 2024 V.5.0.21
Mon, 28 Oct 2024 V.5.0.21

* Update French language (thanks to Phil Aug).
* Update Spanish language (thanks to katnatek).
Expand All @@ -17,6 +17,8 @@ Sun, 13 Oct 2024 V.5.0.21
* Improved build using pyinstaller_setup.py file.
* Improved requirements.
* Fixed some broken link.
* Fixed an issue when restoring the configuration directory, which copied
unnecessary files and directories.


+------------------------------------+
Expand Down
4 changes: 3 additions & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ videomass (5.0.21-1) UNRELEASED; urgency=medium
* Improved build using pyinstaller_setup.py file.
* Improved requirements.
* Fixed some broken link.
* Fixed an issue when restoring the configuration directory, which copied
unnecessary files and directories.

-- Gianluca Pernigotto <[email protected]> Sun, 13 Oct 2024 12:00:00 +0200
-- Gianluca Pernigotto <[email protected]> Mon, 28 Oct 2024 00:00:00 +0200

videomass (5.0.20-1) UNRELEASED; urgency=medium

Expand Down
2 changes: 1 addition & 1 deletion videomass/gui_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, redirect=True, filename=None, **kwargs):
# supported langs for online help (user guide)
}
self.data = DataSource(kwargs) # instance data
self.appset.update(self.data.get_fileconf()) # data system
self.appset.update(self.data.get_configuration()) # data system
self.iconset = None

wx.App.__init__(self, redirect, filename) # constructor
Expand Down
93 changes: 40 additions & 53 deletions videomass/vdms_sys/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Author: Gianluca Pernigotto <[email protected]>
Copyleft - 2024 Gianluca Pernigotto <[email protected]>
license: GPL3
Rev: June.14.2024
Rev: Oct.28.2024
Code checker: flake8, pylint
This file is part of Videomass.
Expand Down Expand Up @@ -60,30 +60,35 @@ def create_dirs(dirname, fconf):
return {'R': None}


def restore_presets_dir(dirconf, srcdata):
def restore_dirconf(dirconf, srcdata):
"""
Restore preset directory from source if it doesn't exist.
check existence of configuration directory
with possibility of restore.
Returns dict:
key == 'R'
key == ERROR (if any errors)
"""
if not os.path.exists(dirconf): # create the configuration directory
try:
os.mkdir(dirconf, mode=0o777)
except FileNotFoundError as err: # parent directory does not exist
return {'ERROR': err}

if not os.path.exists(os.path.join(dirconf, "presets")):
# try to restoring presets directory on videomass dir
drest = copydir_recursively(os.path.join(srcdata, "presets"), dirconf)
if drest:
return {'ERROR': drest}

return {'R': None}


def get_options(dirconf, fileconf, srcdata, makeportable):
def get_options(fileconf, makeportable):
"""
Check the application options. Reads the `settings.json`
file; if it does not exist or is unreadable try to restore
it. If `dirconf` does not exist try to restore both `dirconf`
and `settings.json`. If VERSION is not the same as the version
readed, it adds new missing items while preserving the old ones
with the same values.
it. If VERSION is not the same as the version readed, it adds
new missing items while preserving the old ones with the same
values.
Returns dict:
key == 'R'
Expand All @@ -92,31 +97,19 @@ def get_options(dirconf, fileconf, srcdata, makeportable):
conf = ConfigManager(fileconf, makeportable)
version = ConfigManager.VERSION

if os.path.exists(dirconf): # i.e ~/.conf/videomass dir
if os.path.isfile(fileconf):
data = {'R': conf.read_options()}
if not data['R']:
conf.write_options()
data = {'R': conf.read_options()}
if float(data['R']['confversion']) != version: # conf version
data['R']['confversion'] = version
new = ConfigManager.DEFAULT_OPTIONS # model
data = {'R': {**new, **data['R']}}
conf.write_options(**data['R'])
else:
conf.write_options()
data = {'R': conf.read_options()}

else: # try to restore entire configuration directory
dconf = copydir_recursively(srcdata,
os.path.dirname(dirconf),
"videomass",
)
if dconf:
data = {'ERROR': dconf}
else:
if os.path.isfile(fileconf):
data = {'R': conf.read_options()}
if not data['R']:
conf.write_options()
data = {'R': conf.read_options()}
if float(data['R']['confversion']) != version: # conf version
data['R']['confversion'] = version
new = ConfigManager.DEFAULT_OPTIONS # model
data = {'R': {**new, **data['R']}}
conf.write_options(**data['R'])
else:
conf.write_options()
data = {'R': conf.read_options()}

return data

Expand Down Expand Up @@ -248,7 +241,7 @@ def data_location(kwargs):
"""
Determines data location and modes to make the app
portable, fully portable or using conventional paths.
return data location.
Returns data location dict.
"""
if kwargs['make_portable']:
portdir = kwargs['make_portable']
Expand Down Expand Up @@ -303,31 +296,27 @@ def __init__(self, kwargs):
self.prg_icon = os.path.join(self.dataloc['icodir'], "videomass.png")
# ---------------------------------------------------------------------

def get_fileconf(self):
def get_configuration(self):
"""
Get settings.json configuration data and returns a dict object
with current data-set for bootstrap.
Get configuration data of the application.
Returns a dict object with current data-set for bootstrap.
Note: If returns a dict key == ERROR it will raise a windowed
fatal error in the gui_app bootstrap.
"""
# checks configuration directory
ckdconf = restore_dirconf(self.dataloc['confdir'],
self.dataloc['srcdata'],
)
if ckdconf.get('ERROR'):
return ckdconf

# handle configuration file
userconf = get_options(self.dataloc['confdir'],
self.dataloc['conffile'],
self.dataloc['srcdata'],
self.makeportable,
)
userconf = get_options(self.dataloc['conffile'], self.makeportable)
if userconf.get('ERROR'):
return userconf
userconf = userconf['R']

# restore presets folder
presets_rest = restore_presets_dir(self.dataloc['confdir'],
self.dataloc['srcdata'],
)
if presets_rest.get('ERROR'):
return presets_rest

# create the required directories if not existing
requiredirs = (os.path.join(self.dataloc['cachedir'], 'tmp'),
self.dataloc['logdir'],
Expand Down Expand Up @@ -358,7 +347,7 @@ def _relativize(path, relative=self.relativepaths):
try:
return os.path.relpath(path) if relative else path
except (ValueError, TypeError):
# return {'ERROR': f'{error}'} # use `as error` here
# return {'ERROR': f'{error}'} # used `as error` here
return path

return ({'ostype': platform.system(),
Expand Down Expand Up @@ -386,11 +375,9 @@ def _relativize(path, relative=self.relativepaths):

def icons_set(self, icontheme):
"""
Determines icons set assignment defined on the configuration
file (see `Set icon themes map:`, on paragraph `6- GUI setup`
in the settings.json file).
Determines icons set assignment defined on the
configuration file.
Returns a icontheme dict object.
"""
keys = ('videomass', 'A/V-Conv', 'startconv', 'fileproperties',
'playback', 'concatenate', 'preview', 'clear',
Expand Down

0 comments on commit a8a2b0f

Please sign in to comment.