~kobe24-lixiang/ihu-server/trunk

« back to all changes in this revision

Viewing changes to src/daemon.py

  • Committer: kobe
  • Date: 2013-06-03 08:28:05 UTC
  • Revision ID: kobe24_lixiang@126.com-20130603082805-46pwgcp6303kl8lr
initial release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
### BEGIN LICENSE
 
4
# Copyright (C) 2013 National University of Defense Technology(NUDT) & Kylin Ltd
 
5
# This program is free software: you can redistribute it and/or modify it
 
6
# under the terms of the GNU General Public License version 3, as published
 
7
# by the Free Software Foundation.
 
8
#
 
9
# This program is distributed in the hope that it will be useful, but
 
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
12
# PURPOSE.  See the GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License along
 
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
### END LICENSE
 
17
 
 
18
import sys
 
19
import os
 
20
import glob
 
21
import fcntl
 
22
import shutil
 
23
import logging
 
24
import tempfile
 
25
import subprocess
 
26
 
 
27
from subprocess import PIPE
 
28
import apt
 
29
import apt_pkg
 
30
import dbus
 
31
import dbus.service
 
32
import dbus.mainloop.glib
 
33
from gi.repository import GObject
 
34
 
 
35
from policykit import PolicyKitService
 
36
from cleanerinfo import CACHE_FLAG, CACHE_PACKAGES, CACHE_SIZE
 
37
from hardwareinfo import CPU, RAM
 
38
from systeminfo import HOSTNAME, PLATFORM, DISTRO, DESKTOP_FULLNAME
 
39
from updateinfo import UPDATE_TIME
 
40
from userinfo import CURRENT_USER, HOME_DIRECTORY, SHELL, LANGUAGE
 
41
 
 
42
log = logging.getLogger('Daemon')
 
43
 
 
44
INTERFACE = "com.ubuntukylin.Ihu"
 
45
PATH = "/"
 
46
#PATH = "/com/ubuntukylin_assistant/daemon"
 
47
 
 
48
class Daemon(PolicyKitService):
 
49
    def __init__ (self, bus, mainloop):
 
50
        bus_name = dbus.service.BusName(INTERFACE, bus=bus)
 
51
        PolicyKitService.__init__(self, bus_name, PATH)
 
52
        self.mainloop = mainloop
 
53
 
 
54
    # provide a dbus signal template by kobe
 
55
    @dbus.service.signal(INTERFACE, signature='s')
 
56
    def test1(self, contents):
 
57
        pass
 
58
 
 
59
    # provide a dbus method template by kobe
 
60
    @dbus.service.method(INTERFACE,
 
61
                        in_signature='ii', out_signature='i')
 
62
    def test_add(self, num1, num2):
 
63
        print("receive:", num1, num2)
 
64
        return num1 + num2
 
65
 
 
66
    # a dbus method which get pc messages by kobe
 
67
    @dbus.service.method(INTERFACE, in_signature='', out_signature='a{sv}')
 
68
    def pc_message(self):
 
69
        CLIPS_DICT = {}
 
70
        CLIPS_DICT['cache_flag'] = CACHE_FLAG
 
71
        CLIPS_DICT['cache_packages'] = CACHE_PACKAGES
 
72
        CLIPS_DICT['cache_size'] = CACHE_SIZE
 
73
        CLIPS_DICT['cpu'] = CPU
 
74
        CLIPS_DICT['ram'] = RAM
 
75
        CLIPS_DICT['hostname'] = HOSTNAME
 
76
        CLIPS_DICT['platform'] = PLATFORM
 
77
        CLIPS_DICT['distribution'] = DISTRO
 
78
        CLIPS_DICT['desktopenvironment'] = DESKTOP_FULLNAME
 
79
        CLIPS_DICT['update_time'] = UPDATE_TIME
 
80
        CLIPS_DICT['currrent_user'] = CURRENT_USER
 
81
        CLIPS_DICT['home_path'] = HOME_DIRECTORY
 
82
        CLIPS_DICT['shell'] = SHELL
 
83
        CLIPS_DICT['language'] = LANGUAGE
 
84
        return CLIPS_DICT