forked from emilianox/Fragmentos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidar.py
More file actions
executable file
·145 lines (114 loc) · 4.73 KB
/
Copy pathvalidar.py
File metadata and controls
executable file
·145 lines (114 loc) · 4.73 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2011 Informática MEG <contacto@informaticameg.com>
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import os
from pathtools import PathTools
from configurations import Configurations
class Validator:
''' Clase que valida el estado de distintas partes del programa. '''
def __init__(self):
self.pt = PathTools()
self.config = Configurations()
def checkFolders(self):
""" Verifica que existan los directorios de la aplicación """
# obtiene la ruta del directorio /databases
databases_dir = self.pt.getPathDatabasesDir()
# si no existe el directorio, lo crea
if not os.path.exists(databases_dir):
print 'El directorio /catalogs no existia, ha sido creado nuevamente.'
os.mkdir(databases_dir)
# obtiene la ruta del directorio /data
data_dir = self.pt.getPathDataDir()
# si no existe el directorio, lo crea
if not os.path.exists(data_dir):
print 'El directorio /data no existia, ha sido creado nuevamente.'
os.mkdir(data_dir)
def checkExistCfg(self):
""" Verifica la existencia del archivo de configuracion """
existe = False
path_cfg = self.pt.getPathCFGFile()
if not os.path.exists(path_cfg):
self.config.regenerateNewCFG()
existe = True
return existe
def checkIntegrityCfg(self):
""" Verifica la integridad del archivo de configuracion """
pass
def check(self):
# verifica la existencia de los directorios
self.checkFolders()
# verifica la existencia del archivo de configuracion
self.checkExistCfg()
# verifica la integridad del archivo de configuracion
# self.checkIntegrityCfg()
class ValidarShorcuts:
""""""
def __init__(self):
import gconf # @UnresolvedImport
self.__search_key = 'F7'
self.__add_key = 'F9'
self.__client = gconf.client_get_default()
self.__validar_keys()
def __check_search_key(self):
self.__set_key(
'/desktop/gnome/keybindings/fragmentos-search/binding', self.__search_key)
self.__set_key('/desktop/gnome/keybindings/fragmentos-search/action',
'python ' + self.__validar_file() + ' -search')
self.__set_key(
'/desktop/gnome/keybindings/fragmentos-search/name', 'search into fragmentos')
pass
def __check_add_key(self):
self.__set_key(
'/desktop/gnome/keybindings/fragmentos-add/binding', self.__add_key)
self.__set_key('/desktop/gnome/keybindings/fragmentos-add/action',
'python ' + self.__validar_file() + ' -add')
self.__set_key(
'/desktop/gnome/keybindings/fragmentos-add/name', 'add to fragmentos')
pass
def __validar_keys(self):
self.__check_search_key()
self.__check_add_key()
pass
def __validar_file(self):
p = PathTools()
return p.getPathProgramFolder() + 'cliente_dbus.py'
def __set_key(self, key, value):
import gconf # @UnresolvedImport
import types
casts = {types.BooleanType: gconf.Client.set_bool,
types.IntType: gconf.Client.set_int,
types.FloatType: gconf.Client.set_float,
types.StringType: gconf.Client.set_string}
casts[type(value)](self.__client, key, value)
def __get_key(self, key):
import gconf # @UnresolvedImport
try:
casts = {gconf.VALUE_BOOL: gconf.Value.get_bool,
gconf.VALUE_INT: gconf.Value.get_int,
gconf.VALUE_FLOAT: gconf.Value.get_float,
gconf.VALUE_STRING: gconf.Value.get_string}
value = self.__client.get(key)
return casts[value.type](value)
except AttributeError:
raise ValueError
def main():
v = Validator()
v.checkFolders()
if __name__ == '__main__':
main()