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

« back to all changes in this revision

Viewing changes to backends/youker-assistant-daemon/src/beautify/utils.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
 
 
5
 
# Copyright (C) 2013 ~ 2014 National University of Defense Technology(NUDT) & Kylin Ltd
6
 
# This program is free software: you can redistribute it and/or modify it
7
 
# under the terms of the GNU General Public License version 3, as published
8
 
# by the Free Software Foundation.
9
 
#
10
 
# This program is distributed in the hope that it will be useful, but
11
 
# WITHOUT ANY WARRANTY; without even the implied warranties of
12
 
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13
 
# PURPOSE.  See the GNU General Public License for more details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License along
16
 
# with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 
### END LICENSE
18
 
 
19
 
import os
20
 
 
21
 
# get ~ dir
22
 
def get_home_dir():
23
 
    return os.path.expanduser('~')
24
 
 
25
 
# check dirs with given filters and filtertype
26
 
def check_dirs(dirs, filters, filtertype):
27
 
    result = []
28
 
    try:
29
 
        for onedir in dirs:
30
 
            if os.path.isdir(onedir):
31
 
                for f in os.listdir(onedir):
32
 
                    if use_filters(os.path.join(onedir, f), filters, filtertype):
33
 
                        result.append(f)
34
 
    except:
35
 
        pass
36
 
    return result
37
 
 
38
 
# check the fpathdir with filters filtertype: True == include, False == exlude
39
 
def use_filters(fpath, filters, filtertype):
40
 
    # not a directory
41
 
    if os.path.isdir(fpath) == False:
42
 
        return False
43
 
 
44
 
    if filtertype:
45
 
        for onefilter in filters:
46
 
            if os.path.exists(os.path.join(fpath, onefilter)):
47
 
                continue
48
 
            else:
49
 
                return False
50
 
        return True
51
 
    else:
52
 
        for onefilter in filters:
53
 
            if os.path.exists(os.path.join(fpath, onefilter)):
54
 
                return False
55
 
            else:
56
 
                continue
57
 
        return True
 
 
b'\\ No newline at end of file'