Skip to content

Commit

Permalink
Merge pull request #509 from SeeSpotRun/gui/setup
Browse files Browse the repository at this point in the history
Gui/setup
  • Loading branch information
SeeSpotRun authored May 27, 2021
2 parents 14bae9b + 2b6c370 commit 1a142fc
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 26 deletions.
6 changes: 6 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,12 @@ for suffix in ['libelf', 'gettext', 'fiemap', 'blkid', 'gui']:
dest='with_' + suffix
)

AddOption(
'--without-schemas-compile',
action='store_false', dest='schemas_compile', default=True,
help="don't compile glib schemas after install"
)

env = Environment(PREFIX = GetOption('prefix'))

if 'install' in COMMAND_LINE_TARGETS:
Expand Down
29 changes: 17 additions & 12 deletions gui/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ GSCHEMA_DIR_SUFFIX = 'share/glib-2.0/schemas'
GUI_DIR = 'gui'
FILES_RECORD = '.files.txt'
FILES_RECORD_FULL = os.path.join(GUI_DIR, FILES_RECORD)
PREFIX = env['PREFIX']
COMPILE_SCHEMAS = GetOption('schemas_compile')

def which(program):
def is_exe(fpath):
Expand Down Expand Up @@ -39,10 +41,12 @@ if 'install' in COMMAND_LINE_TARGETS and GetOption('with_gui'):
py_install = env.Command(
'always.install',
['setup.py'],
'cd {} && {} setup.py install --record {}'.format(
'cd {} && {} setup.py install --prefix {} --record {} {}'.format(
GUI_DIR,
python_exe,
FILES_RECORD
PREFIX,
FILES_RECORD,
'--compile-schemas' if COMPILE_SCHEMAS else ''
)
)
env.Alias('install', py_install)
Expand All @@ -62,16 +66,17 @@ if 'uninstall' in COMMAND_LINE_TARGETS and GetOption('with_gui'):
except OSError as err:
print('Could not open {}: '.format(FILES_RECORD_FULL), err)

# recompile remaining glib schemas after deleting ours
print('Recompiling glib schemas')
gschema_dir = os.path.join(env['PREFIX'], GSCHEMA_DIR_SUFFIX)
compile_command = [
'glib-compile-schemas',
gschema_dir]
try:
subprocess.call(compile_command)
except subprocess.CalledProcessError as err:
print("Error recompiling glib schemas post uninstall")
if COMPILE_SCHEMAS:
# recompile remaining glib schemas after deleting ours
print('Recompiling glib schemas')
gschema_dir = os.path.join(env['PREFIX'], GSCHEMA_DIR_SUFFIX)
compile_command = [
'glib-compile-schemas',
gschema_dir]
try:
subprocess.call(compile_command)
except subprocess.CalledProcessError as err:
print("Error recompiling glib schemas post uninstall")


env.Alias('uninstall',
Expand Down
57 changes: 43 additions & 14 deletions gui/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from distutils.core import setup
from distutils.command.install_data import install_data
from distutils.command.install import install

import os
import sys
Expand All @@ -12,18 +13,31 @@
GRESOURCE_DIR = 'shredder/resources'
GRESOURCE_FILE = 'shredder.gresource.xml'
GSCHEMA_DIR_SUFFIX = 'share/glib-2.0/schemas'
COMPILE_SCHEMAS = 0

def read_version():
with open('../.version', 'r') as handle:
version_string = handle.read()

return version_string.strip()

class install_glib_resources(install_data):
class install_glib_resources(install):
user_options = install.user_options + [
('compile-schemas', None, 'Compile glib schemas after install (default false)')
]

def initialize_options(self):
install.initialize_options(self)
self.compile_schemas = 0

def finalize_options(self):
install.finalize_options(self)
global COMPILE_SCHEMAS
COMPILE_SCHEMAS = self.compile_schemas

def run(self):
self._build_gresources()
super().run()
self._build_gschemas()

def _build_gresources(self):
'''
Expand All @@ -39,26 +53,38 @@ def _build_gresources(self):
except subprocess.CalledProcessError as err:
print('==> Failed :(')


class compile_glib_schemas(install_data):

def run(self):
super().run()
if COMPILE_SCHEMAS == 1:
self._build_gschemas()
else:
print("==> Not compiling glib schemas")
self.print_compile_instructions()

def gschema_dir(self):
return os.path.join(self.install_dir, GSCHEMA_DIR_SUFFIX)

def print_compile_instructions(self):
print('==> You may need to compile glib schemas manually:\n')
print(' sudo glib-compile-schemas {}\n'.format(
self.gschema_dir()))


def _build_gschemas(self):
'''
Make sure the schema file is updated after installation,
otherwise the gui will trace trap.
'''
print('==> Compiling GLib Schema files')
# Use 'self.install_dir' to build the path, so that it works
# for both global and local '--user' installs.
gschema_dir = os.path.join(self.install_dir, GSCHEMA_DIR_SUFFIX)
compile_command = [
'glib-compile-schemas',
gschema_dir]
try:
subprocess.call(compile_command)
subprocess.call(['glib-compile-schemas', self.gschema_dir()])
print('==> OK!')
except subprocess.CalledProcessError as err:
print('==> Could not update schemas: ', err)
print('==> Please run the following manually:\n')
print(' sudo {}'.format(' '.join(compile_command)))
else:
print('==> OK!')
self.print_compile_instructions()


setup(
Expand All @@ -71,7 +97,10 @@ def _build_gschemas(self):
url='https://rmlint.rtfd.org',
license='GPLv3',
platforms='any',
cmdclass={'install_data': install_glib_resources},
cmdclass={
'install': install_glib_resources,
'install_data': compile_glib_schemas
},
packages=['shredder', 'shredder.views'],
package_data={'': [
'resources/*.gresource'
Expand Down

0 comments on commit 1a142fc

Please sign in to comment.