archivos.py
3.76 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
146
147
148
149
150
151
152
153
154
155
156
157
158
from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5 import QtWidgets
import os
import sys
import tempfile
import subprocess
class AppThread(QThread):
signal = pyqtSignal('PyQt_PyObject')
def __init__(self):
QThread.__init__(self)
self.aplicativo = ""
# run method gets called when we start the thread
def run(self):
#tmpdir = tempfile.mkdtemp()
cmd = "python3 {0}".format(self.aplicativo)
subprocess.check_output(cmd.split())
# git clone done, now inform the main thread with the output
#self.signal.emit(tmpdir)
class LanzarThread(QThread):
signal = pyqtSignal('PyQt_PyObject')
def __init__(self):
QThread.__init__(self)
self.comando = ""
def run(self):
#print('ejecutar ' )
cmd = "{0}".format(self.comando)
print('ejecutar ', cmd )
subprocess.check_output(cmd.split())
class LanzarArchivos(QThread):
signal = pyqtSignal('PyQt_PyObject')
def __init__(self):
QThread.__init__(self)
self.comando = ""
def run(self):
#print('ejecutar ' )
cmd = "{0}".format(self.comando)
print(['xdg-open', cmd])
subprocess.check_output(['xdg-open', cmd])
def escrivir_txt(path, texto):
try:
f = open(path, 'w+')
for i in texto:
f.write(i)
f.close()
return(True)
except:
return(False)
def leer_archivo(path):
texto = []
try:
f = open(path, 'r')
f1 = f.readlines()
for x in f1:
texto.append(x)
return(texto)
except:
return(False)
def path():
DEFAULT_PATH = os.path.abspath('./')
return(DEFAULT_PATH)
def buscar_aplicativos(path):
#print(os.listdir(path + '/'))
folder = []
for file in os.listdir(path + '/'):
if file.endswith("_main.py"):
#print(os.path.join(path, file))
folder.append([os.path.join(path, file), file, file[:-3]])
print([os.path.join(path, file), file, file[:-3]])
return(folder)
#print(path('desktop/dier.py'))
def carga_dinamica():
DEFAULT_PATH = path()
modulos = buscar_aplicativos(DEFAULT_PATH)
print(modulos)
devolucion = []
for modulo in modulos:
modulo = modulo[2]
#print(modulo)
retorno = __import__(modulo)
retorno = retorno.nombre()
print(retorno)
devolucion.append(retorno)
return(devolucion)
def lanzar_aplicativo(self, app, item):
DEFAULT_PATH = path()
modulos = buscar_aplicativos(DEFAULT_PATH)
for modulo in modulos:
PY_modulo = modulo[2]
retorno = __import__(PY_modulo)
retorno = retorno.nombre()
#print(retorno)
if retorno[0] == item:
print('lanzar ' + str(item))
self.app_thread = AppThread()
self.app_thread.aplicativo = modulo[0]
self.app_thread.start()
return(True)
print('no se encontro aplicativo')
return(False)
def ejecutar(self, comando):
try:
self.app_thread = LanzarThread()
self.app_thread.comando = comando
self.app_thread.start()
except:
return(False)
def escrivir_tuple(path, TUPLE):
try:
f = open(path, 'w+')
for i in TUPLE:
f.write(i)
f.write('\n')
f.close()
return(True)
except:
return(False)
def leer_tuple(path):
texto = []
try:
f = open(path, 'r')
f1 = f.readlines()
for x in f1:
y = x[:-1]
texto.append(y)
return(texto)
except:
return(False)
def abrir_arch(self, arch):
try:
self.app_thread = LanzarArchivos()
self.app_thread.comando = arch
self.app_thread.start()
except:
return(False)