]>
Commit | Line | Data |
---|---|---|
47a4cb89 MT |
1 | #!/usr/bin/python |
2 | ||
47a4cb89 MT |
3 | import os |
4 | import sys | |
5 | ||
3eca2587 MT |
6 | import logging |
7 | log = logging.getLogger("pakfire") | |
8 | ||
60845a36 MT |
9 | try: |
10 | from pakfire.cli import * | |
11 | from pakfire.i18n import _ | |
12 | ||
13 | except ImportError, e: | |
14 | # Catch ImportError and show a more user-friendly message about what | |
15 | # went wrong. | |
16 | ||
17 | # Try to load at least the i18n support, but when this fails as well we can | |
18 | # go with an English error message. | |
19 | try: | |
20 | from pakfire.i18n import _ | |
21 | except ImportError: | |
22 | _ = lambda x: x | |
23 | ||
24 | # XXX Maybe we can make a more beautiful message here?! | |
25 | print _("There has been an error when trying to import one or more of the" | |
26 | " modules, that are required to run Pakfire.") | |
1c5de927 | 27 | print _("Please check your installation of Pakfire.") |
60845a36 MT |
28 | |
29 | print _("The error that lead to this:") | |
30 | print " ", e | |
31 | ||
32 | ||
33 | # Exit immediately. | |
34 | sys.exit(1) | |
47a4cb89 MT |
35 | |
36 | basename2cls = { | |
9b875540 MT |
37 | "pakfire" : Cli, |
38 | "pakfire-builder" : CliBuilder, | |
c62d93f1 MT |
39 | "pakfire-client" : CliClient, |
40 | "pakfire-daemon" : CliDaemon, | |
68c0e769 | 41 | "pakfire-key" : CliKey, |
9b875540 MT |
42 | "pakfire-server" : CliServer, |
43 | "builder" : CliBuilderIntern, | |
47a4cb89 MT |
44 | } |
45 | ||
46 | # Get the basename of the program | |
47 | basename = os.path.basename(sys.argv[0]) | |
48 | ||
49 | # Check if the program was called with a weird basename. | |
50 | # If so, we exit immediately. | |
51 | if not basename2cls.has_key(basename): | |
52 | sys.exit(127) | |
53 | ||
47a4cb89 MT |
54 | # Return code for the shell. |
55 | ret = 0 | |
56 | ||
57 | try: | |
936f6b37 MT |
58 | # Creating command line interface |
59 | cli = basename2cls[basename]() | |
60 | ||
47a4cb89 MT |
61 | cli.run() |
62 | ||
63 | except KeyboardInterrupt: | |
3eca2587 | 64 | log.critical("Recieved keyboard interupt (Ctrl-C). Exiting.") |
47a4cb89 MT |
65 | ret = 1 |
66 | ||
60845a36 MT |
67 | # Catch all errors and show a user-friendly error message. |
68 | except Error, e: | |
3eca2587 MT |
69 | log.critical("") |
70 | log.critical(_("An error has occured when running Pakfire.")) | |
71 | log.error("") | |
60845a36 | 72 | |
3eca2587 MT |
73 | log.error(_("Error message:")) |
74 | log.error(" %s: %s" % (e.__class__.__name__, e.message)) | |
75 | log.error("") | |
60845a36 | 76 | |
96bbe95a MT |
77 | # Log the traceback when in debugging mode. |
78 | log.debug("", exc_info=True) | |
79 | ||
3eca2587 | 80 | log.error(_("Further description:")) |
1441456d MT |
81 | msg = "%s" % e |
82 | for line in msg.splitlines(): | |
83 | log.error(" %s" % line) | |
3eca2587 | 84 | log.error("") |
60845a36 MT |
85 | |
86 | ret = e.exit_code | |
87 | ||
47a4cb89 MT |
88 | sys.exit(ret) |
89 |