-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgfxmenu.py
executable file
·106 lines (83 loc) · 3.39 KB
/
gfxmenu.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
#!/bin/env python
#
# LUNARC HPC Desktop On-Demand graphical launch tool
# Copyright (C) 2017-2024 LUNARC, Lund University
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
gfxconvert script for creating menus from launch scripts
This tool parses a given directory for launch scripts and from special
tags in the scripts creates standardised Linux menus. The tools is
configured from the GfxLauncher configuration file.
"""
import os
import sys
import getpass
import argparse
import time
import logging
from lhpcdt import integration as it
from lhpcdt import scripts as scr
from lhpcdt import config
gfxmenu_copyright = """LUNARC HPC Desktop On-Demand - Version %s
Copyright (C) 2017-2024 LUNARC, Lund University
This program comes with ABSOLUTELY NO WARRANTY; for details see LICENSE.
This is free software, and you are welcome to redistribute it
under certain conditions; see LICENSE for details.
"""
gfxmenu_copyright_short = """LUNARC HPC Desktop On-Demand - %s"""
gfxmenu_version = "0.9.16"
def main():
# ----- Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument(
"--no-launcher", help="Generate menus and scripts with direct launch.", action="store_true")
parser.add_argument(
"--config", help="Show configuration", action="store_true")
parser.add_argument(
"--silent", help="Run without output", action="store_true")
parser.add_argument("--verbose", help="Verbose logging",
action="store_true")
parser.add_argument("--force", help="Force refresh menu entries", action="store_true")
args = parser.parse_args()
# ----- Show version information
if not args.silent:
print(("LUNARC HPC Desktop - User menu tool - Version %s" % gfxmenu_version))
print("Written by Jonas Lindemann (jonas.lindemann@lunarc.lu.se)")
print("Copyright (C) 2018-2024 LUNARC, Lund University")
# ----- Read configuration
if args.verbose:
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%d-%b-%y %H:%M:%S', level=logging.DEBUG)
cfg = config.GfxConfig.create()
if args.config:
cfg.print_config()
sys.exit(0)
if not cfg.is_ok:
print("Somehting is wrong with the configuration.")
sys.exit(0)
# ----- Parse script directory
run_scripts = scr.RunScripts(cfg.script_dir)
run_scripts.launcher = os.path.join(cfg.install_dir, 'gfxlaunch')
run_scripts.parse()
script_db = run_scripts.database
# ----- Create user menu
user_menu = it.UserMenus()
user_menu.menu_name_prefix = cfg.menu_prefix
user_menu.desktop_entry_prefix = cfg.desktop_entry_prefix
user_menu.add_scripts(script_db)
user_menu.force_refresh = args.force
user_menu.generate()
if __name__ == "__main__":
main()