~feng-kylin/youker-assistant/youker-assistant

« back to all changes in this revision

Viewing changes to backends/youker-assistant-daemon/src/cleaner/dashhistory.py

  • Committer: lixiang
  • Date: 2018-03-06 03:13:06 UTC
  • Revision ID: lixiang@kylinos.cn-20180306031306-fd7qnru3vm4a1xjd
Rewrite with Qt5, and add system monitor

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 ~ 2014 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 os
19
 
import commands
20
 
import sqlite3
21
 
 
22
 
 
23
 
class DashHistory():
24
 
    def __init__(self, homedir):
25
 
        self.full_path = ''
26
 
        if homedir:
27
 
            path = '%s/.local/share/zeitgeist/' % homedir 
28
 
        else:
29
 
            path = os.path.expanduser('~/.local/share/zeitgeist/')
30
 
        self.full_path = path + 'activity.sqlite'
31
 
        if not os.path.exists(self.full_path):
32
 
            raise Exception("Dashhistory: path did not exist")
33
 
 
34
 
    def scan_the_records(self):
35
 
        self.browser_conn = sqlite3.connect(self.full_path)
36
 
        self.browser_cur = self.browser_conn.cursor()
37
 
 
38
 
        sql_select = "SELECT COUNT(*) FROM event_view"
39
 
        self.browser_cur.execute(sql_select)
40
 
        number = self.browser_cur.fetchone()[0]
41
 
 
42
 
        self.browser_cur.close()
43
 
        self.browser_conn.close()
44
 
        return number
45
 
 
46
 
    def clean_the_records(self):
47
 
        tmp_path = self.full_path
48
 
        user = tmp_path.split('/')[2]
49
 
        os.remove(tmp_path)
50
 
        cmd = "su - %s -c 'zeitgeist-daemon --replace & >& /dev/null'" % user
51
 
        (status, output) = commands.getstatusoutput(cmd)
52
 
        return
53
 
 
54