]> git.ipfire.org Git - people/stevee/pakfire.git/blob - src/scripts/pakfire
cli: Move exception handling into Cli base class
[people/stevee/pakfire.git] / src / scripts / pakfire
1 #!/usr/bin/python3
2 ###############################################################################
3 # #
4 # Pakfire - The IPFire package management system #
5 # Copyright (C) 2017 Pakfire development team #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 import os
23 import sys
24
25 # Catch ImportError and show a more user-friendly message about what went wrong
26 try:
27 import pakfire.cli
28
29 except ImportError as e:
30 # Try to load at least the i18n support, but when this fails as well we can
31 # go with an English error message.
32 try:
33 from pakfire.i18n import _
34 except ImportError:
35 _ = lambda x: x
36
37 print(_("There has been an error when trying to import one or more of the"
38 " modules, that are required to run Pakfire."))
39 print(_("Please check your installation of Pakfire."))
40 print()
41 print(_("The error that lead to this:"))
42 print(" ", e)
43 print()
44
45 # Exit immediately.
46 sys.exit(1)
47
48 basename2cls = {
49 "pakfire" : pakfire.cli.Cli,
50 "pakfire-builder" : pakfire.cli.CliBuilder,
51 "pakfire-client" : pakfire.cli.CliClient,
52 "pakfire-daemon" : pakfire.cli.CliDaemon,
53 "pakfire-key" : pakfire.cli.CliKey,
54 "pakfire-server" : pakfire.cli.CliServer,
55 "builder" : pakfire.cli.CliBuilderIntern,
56 }
57
58 # Get the basename of the program
59 basename = os.path.basename(sys.argv[0])
60
61 # Check if the program was called with a weird basename.
62 # If so, we exit immediately.
63 if basename not in basename2cls:
64 sys.exit(127)
65
66 cli = basename2cls[basename]()
67 ret = cli.run()
68
69 sys.exit(ret)