~vincent-vandevyvre/qarte/trunk

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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#! /usr/bin/python
# -*- coding: utf-8 -*-

# qarte
# Version: 2.6.0
# This file is part of Qarte
#    
# Author: Vincent Vande Vyvre <vincent.vandevyvre@oqapy.eu>
# Copyright: 2011-2015 Vincent Vande Vyvre
# Licence: GPL3
# Home page : https://launchpad.net/qarte
#
#
# Qarte 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.
#
# Qarte 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 Qarte.  If not, see <http://www.gnu.org/licenses/>.
#
# Launcher of Qarte

import os
import sys
import logging
import platform
import locale
try:
    import pynotify
    NOTIFY = True
except:
    NOTIFY = False

from PyQt4 import QtCore, QtGui


VERSION_STR = "2.6.0"

def show_infos(arg):
    """Show info and exit."""
    if arg in ["-v", "--version"]:
        print"""\n\tQarte vers: {0}

    Copyright (C) 2011-2015 Vincent Vande Vyvre <vincent.vandevyvre@oqapy.eu>
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
\n""".format(VERSION_STR)

    else:
        print """\n\tQarte is a recorder for the archivs of arte+7 & arteLiveWeb site.

\tUsage: qarte [OPTION]

\tOptions:
\t  -v --version\t Show version and copyright infos
\t  -h --help\t Show this info
\t  -d --debug\t Run Qarte in mode verbose

\tReport bugs to <https://code.launchpad.net/qarte>\n"""
    sys.exit()

def print_infos():
    PY_VERSION = sys.version.split()[0]
    PLATFORM = platform.platform()
    logger.info(u"Qarte-{0}".format(VERSION_STR))
    logger.info(u"Python {0} on {1}".format(PY_VERSION, PLATFORM))
    logger.info(u"File system encoding: {0}".format(sys.getfilesystemencoding()))
    logger.info(u"System encoding: {0}".format(sys.getdefaultencoding()))
    logger.info(u"Locale encoding: {0}".format(locale.getdefaultlocale()))

if __name__ == "__main__":
    logger = logging.getLogger("qarte")
    lvl = logging.WARNING

    if len(sys.argv) > 1:
        if sys.argv[1] in ["-v", "--version", "-h", "--help"]:
            show_infos(sys.argv[1])

        elif sys.argv[1] == '-a':
            os.chdir("/usr/share/qarte")

            if not os.path.isfile("/usr/share/qarte/daemon.py"):
                print "File '/usr/share/qarte/daemon.py' not found."
                print "Please re-install Qarte"
                sys.exit()

            sys.path.append("/usr/share/qarte")
            from daemon import Daemon
            qarte = Daemon(task=sys.argv[2])
            reply = qarte.read_task()
            sys.exit()

        elif sys.argv[1] in ["-d", "--debug"]:
            print_infos()
            lvl = logging.DEBUG

    LOG_FORMAT = "%(asctime)-6s: %(levelname)s - %(name)s %(message)s"
    logging.basicConfig(format=LOG_FORMAT, level=lvl, datefmt='%H:%M:%S')

    os.chdir("/usr/share")
    if not os.path.isdir("qarte"):
        print "Folder '/usr/share/qarte' not found."
        print "Please install Qarte in '/usr/share/'"
        sys.exit()

    os.chdir("/usr/share/qarte")
    if not os.path.isfile("qarte.py"):
        print "File '/usr/share/qarte/qarte.py' not found."
        print "Please re-install Qarte"
        sys.exit()

    sys.path.append("/usr/share/qarte")
    app = QtGui.QApplication(sys.argv)
    
    from qarte import Qarte
    Main = Qarte()
    sys.exit(app.exec_())