root / py / scenic / runner.py @ 8c2ed4f7
History | View | Annotate | Download (4.8 kB)
| 1 | 682744da | Alexandre Quessy | #!/usr/bin/env python
|
|---|---|---|---|
| 2 | 682744da | Alexandre Quessy | # -*- coding: utf-8 -*-
|
| 3 | 682744da | Alexandre Quessy | #
|
| 4 | 682744da | Alexandre Quessy | # Scenic
|
| 5 | 682744da | Alexandre Quessy | # Copyright (C) 2008 Société des arts technologiques (SAT)
|
| 6 | 682744da | Alexandre Quessy | # http://www.sat.qc.ca
|
| 7 | 682744da | Alexandre Quessy | # All rights reserved.
|
| 8 | 682744da | Alexandre Quessy | #
|
| 9 | 682744da | Alexandre Quessy | # This file is free software: you can redistribute it and/or modify
|
| 10 | 682744da | Alexandre Quessy | # it under the terms of the GNU General Public License as published by
|
| 11 | 682744da | Alexandre Quessy | # the Free Software Foundation, either version 2 of the License, or
|
| 12 | 682744da | Alexandre Quessy | # (at your option) any later version.
|
| 13 | 682744da | Alexandre Quessy | #
|
| 14 | 682744da | Alexandre Quessy | # Scenic is distributed in the hope that it will be useful,
|
| 15 | 682744da | Alexandre Quessy | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | 682744da | Alexandre Quessy | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | 682744da | Alexandre Quessy | # GNU General Public License for more details.
|
| 18 | 682744da | Alexandre Quessy | #
|
| 19 | 682744da | Alexandre Quessy | # You should have received a copy of the GNU General Public License
|
| 20 | 682744da | Alexandre Quessy | # along with Scenic. If not, see <http://www.gnu.org/licenses/>.
|
| 21 | 682744da | Alexandre Quessy | |
| 22 | 682744da | Alexandre Quessy | """
|
| 23 | 682744da | Alexandre Quessy | Main of the application. |
| 24 | 97e354c5 | Alexandre Quessy | Some imports are in run(). |
| 25 | 682744da | Alexandre Quessy | """
|
| 26 | 5161411f | Alexandre Quessy | import sys |
| 27 | bceef57a | Alexandre Quessy | import os |
| 28 | 5161411f | Alexandre Quessy | from twisted.python import log |
| 29 | bceef57a | Alexandre Quessy | from twisted.python import logfile |
| 30 | e21a6d08 | Alexandre Quessy | |
| 31 | 5161411f | Alexandre Quessy | def start_logging_to_stdout(): |
| 32 | 5161411f | Alexandre Quessy | log.startLogging(sys.stdout) |
| 33 | 5161411f | Alexandre Quessy | |
| 34 | bceef57a | Alexandre Quessy | def start_file_logging(full_path="/var/tmp/scenic/scenic.log"): |
| 35 | bceef57a | Alexandre Quessy | """
|
| 36 | bceef57a | Alexandre Quessy | Starts logging the Master infos to a file. |
| 37 | 7f978b06 | Alexandre Quessy | @rtype: str path to the log file |
| 38 | bceef57a | Alexandre Quessy | """ |
| 39 | bceef57a | Alexandre Quessy | file_name = os.path.basename(full_path) |
| 40 | bceef57a | Alexandre Quessy | directory = os.path.dirname(full_path) |
| 41 | bceef57a | Alexandre Quessy | if not os.path.exists(directory): |
| 42 | bceef57a | Alexandre Quessy | os.makedirs(directory) |
| 43 | bceef57a | Alexandre Quessy | f = open(full_path, 'w') # erases previous file |
| 44 | bceef57a | Alexandre Quessy | f.close() |
| 45 | bceef57a | Alexandre Quessy | _log_file = logfile.DailyLogFile(file_name, directory) |
| 46 | bceef57a | Alexandre Quessy | log.startLogging(_log_file) |
| 47 | bceef57a | Alexandre Quessy | return _log_file.path
|
| 48 | bceef57a | Alexandre Quessy | |
| 49 | bceef57a | Alexandre Quessy | LOG_FILE_NAME = "~/.scenic/scenic.log"
|
| 50 | bceef57a | Alexandre Quessy | |
| 51 | d4f31a1d | Alexandre Quessy | def moo(): |
| 52 | d4f31a1d | Alexandre Quessy | """
|
| 53 | d4f31a1d | Alexandre Quessy | This image is: |
| 54 | d4f31a1d | Alexandre Quessy | Copyright (C) 2003, Vijay Kumar |
| 55 | d4f31a1d | Alexandre Quessy | Permission is granted to copy, distribute and/or modify this image under the terms either: |
| 56 | d4f31a1d | Alexandre Quessy | |
| 57 | d4f31a1d | Alexandre Quessy | * the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version, or |
| 58 | d4f31a1d | Alexandre Quessy | * the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the no Invariant Sections, with no Front-Cover Texts and with no Back-Cover Texts. |
| 59 | d4f31a1d | Alexandre Quessy | """ |
| 60 | d4f31a1d | Alexandre Quessy | print("""
|
| 61 | d4f31a1d | Alexandre Quessy | _-`````-, ,- '- . |
| 62 | d4f31a1d | Alexandre Quessy | .' .- - | | - . `. |
| 63 | d4f31a1d | Alexandre Quessy | /.' / `. \ |
| 64 | d4f31a1d | Alexandre Quessy | :/ : _... ..._ `` : |
| 65 | d4f31a1d | Alexandre Quessy | :: : /._ .`:'_.._\. || : |
| 66 | d4f31a1d | Alexandre Quessy | :: `._ ./ ,` : \ . _.'' . |
| 67 | d4f31a1d | Alexandre Quessy | `:. | | -. \-. \|_ / |
| 68 | d4f31a1d | Alexandre Quessy | \:._ _/ ..' .@) \@) ` `\ ,.' |
| 69 | d4f31a1d | Alexandre Quessy | _/,--' .- .\,-.`--`. |
| 70 | d4f31a1d | Alexandre Quessy | ,'/'' (( \ ` ) |
| 71 | d4f31a1d | Alexandre Quessy | /'/' \ `-' ( |
| 72 | d4f31a1d | Alexandre Quessy | '/'' `._,-----' |
| 73 | d4f31a1d | Alexandre Quessy | ''/' .,---' |
| 74 | d4f31a1d | Alexandre Quessy | ''/' ;: |
| 75 | d4f31a1d | Alexandre Quessy | ''/'' ''/ |
| 76 | d4f31a1d | Alexandre Quessy | ''/''/'' |
| 77 | d4f31a1d | Alexandre Quessy | '/'/' |
| 78 | d4f31a1d | Alexandre Quessy | `; |
| 79 | d4f31a1d | Alexandre Quessy | """) |
| 80 | d4f31a1d | Alexandre Quessy | |
| 81 | 682744da | Alexandre Quessy | def run(): |
| 82 | 97e354c5 | Alexandre Quessy | """
|
| 83 | 97e354c5 | Alexandre Quessy | Main function of the application |
| 84 | 97e354c5 | Alexandre Quessy | """ |
| 85 | 97e354c5 | Alexandre Quessy | from scenic import configure |
| 86 | 97e354c5 | Alexandre Quessy | |
| 87 | 97e354c5 | Alexandre Quessy | if not os.environ.has_key('GTK2_RC_FILES'): |
| 88 | 97e354c5 | Alexandre Quessy | name = "Darklooks"
|
| 89 | 97e354c5 | Alexandre Quessy | file_name = os.path.join(os.path.join(configure.THEMES_DIR, name, "gtkrc"))
|
| 90 | 97e354c5 | Alexandre Quessy | os.environ["GTK2_RC_FILES"] = file_name # has to be done before gtk2reactor.install() |
| 91 | 97e354c5 | Alexandre Quessy | configure.custom_environment_variables["GTK2_RC_FILES"] = file_name
|
| 92 | 3b81e4bb | Alexandre Quessy | if "/sbin" not in os.environ["PATH"]: # for ifconfig |
| 93 | 3b81e4bb | Alexandre Quessy | os.environ["PATH"] += ":/sbin" |
| 94 | 97e354c5 | Alexandre Quessy | |
| 95 | 97e354c5 | Alexandre Quessy | from optparse import OptionParser |
| 96 | 97e354c5 | Alexandre Quessy | from twisted.internet import gtk2reactor |
| 97 | 97e354c5 | Alexandre Quessy | gtk2reactor.install() # has to be done before importing reactor
|
| 98 | 97e354c5 | Alexandre Quessy | from twisted.internet import reactor |
| 99 | 97e354c5 | Alexandre Quessy | from twisted.internet import error |
| 100 | 97e354c5 | Alexandre Quessy | from scenic import application |
| 101 | 97e354c5 | Alexandre Quessy | |
| 102 | 682744da | Alexandre Quessy | # command line parsing
|
| 103 | 87fd0cba | Alexandre Quessy | parser = OptionParser(usage="%prog", version=str(configure.VERSION)) |
| 104 | ad875b3a | Alexandre Quessy | parser.add_option("-k", "--kiosk", action="store_true", help="Run in kiosk mode") |
| 105 | bceef57a | Alexandre Quessy | parser.add_option("-l", "--enable-logging", action="store_true", help="Enables logging to file.") |
| 106 | bceef57a | Alexandre Quessy | parser.add_option("-L", "--log-file-name", type="string", help="Specifies the path to the log file. Default is %s" % (LOG_FILE_NAME), default=LOG_FILE_NAME) |
| 107 | ad875b3a | Alexandre Quessy | parser.add_option("-f", "--fullscreen", action="store_true", help="Run in fullscreen mode") |
| 108 | d4f31a1d | Alexandre Quessy | parser.add_option("-M", "--moo", action="store_true", \ |
| 109 | d4f31a1d | Alexandre Quessy | help="There is no easter egg in this program.")
|
| 110 | 682744da | Alexandre Quessy | (options, args) = parser.parse_args() |
| 111 | bceef57a | Alexandre Quessy | kwargs = {}
|
| 112 | d4f31a1d | Alexandre Quessy | if options.moo:
|
| 113 | d4f31a1d | Alexandre Quessy | moo() |
| 114 | d4f31a1d | Alexandre Quessy | sys.exit(0)
|
| 115 | bceef57a | Alexandre Quessy | if options.enable_logging:
|
| 116 | bceef57a | Alexandre Quessy | start_file_logging(os.path.expanduser(options.log_file_name)) |
| 117 | bceef57a | Alexandre Quessy | kwargs["log_file_name"] = options.log_file_name
|
| 118 | bceef57a | Alexandre Quessy | else:
|
| 119 | bceef57a | Alexandre Quessy | start_logging_to_stdout() |
| 120 | 18027841 | Alexandre Quessy | try:
|
| 121 | bceef57a | Alexandre Quessy | app = application.Application(kiosk_mode=options.kiosk, fullscreen=options.fullscreen, **kwargs) |
| 122 | 9972cf83 | Alexandre Quessy | except error.CannotListenError, e:
|
| 123 | 18027841 | Alexandre Quessy | print("There must be an other Scenic running.")
|
| 124 | 18027841 | Alexandre Quessy | print(str(e))
|
| 125 | 18027841 | Alexandre Quessy | else:
|
| 126 | 18027841 | Alexandre Quessy | try:
|
| 127 | 18027841 | Alexandre Quessy | reactor.run() |
| 128 | 18027841 | Alexandre Quessy | except KeyboardInterrupt: |
| 129 | 18027841 | Alexandre Quessy | pass
|
| 130 | d4f31a1d | Alexandre Quessy | sys.exit(0) |
