-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderpdf.py
More file actions
89 lines (64 loc) · 2.15 KB
/
renderpdf.py
File metadata and controls
89 lines (64 loc) · 2.15 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
import os
import sys
#clase principal
class Renderizador(object):
convertidor=""
pathoriginal=""
pathconvertido=""
#donde se almacenara todo el shell
lote="cd / "
#constructor
def __init__(self,pathconvertidor,original,convertido):
self.convertidor=pathconvertidor
self.pathoriginal=original
self.pathconvertido=convertido
pass
def iniciarrender(self):
dir=os.listdir(self.pathoriginal)
for archivo in dir:
if (".pdf" in archivo):self.renderizarelemnto(archivo)
print "lote:"+self.lote
self. ejecutarlote()
pass
#rederinza cada pdf
def renderizarelemnto(self,archivo):
self.lote=self.lote+"\n"+"."+self.convertidor+" "+self.pathoriginal+"/"+archivo+" "+self.pathconvertido+"/"+archivo
def ejecutarlote(self):
os.system(self.lote)
pass
#comprueba si existe ruta de destino y si no la crea
def existe_convertido(self):
if not os.path.exists(self.pathconvertido):
os.mkdir(self.pathconvertido,0o777)
if(os.path.exists(self.pathconvertido)):
return 1
else:
return 1
return 0
#comprueba si existen pdfs que renderizar
def existen_orginales(self):
dir=os.listdir(self.pathoriginal)
for archivo in dir:
if (".pdf" in archivo):
return 1
pass
return 0
pass
#verficamos que exista ruta origien y archivo rederizador
originales="originales"
convertidos="convertidos"
convertidor="shrinkpdf.sh"
try:
ruta=sys.argv[1]
except IndexError:
print "No se encontraron argumentos"
ruta = "/home/daniel/Escritorio/pdfs"
if(os.path.exists(ruta+"/"+convertidor) & os.path.exists(ruta+"/"+originales)) :
#instanciamos objeto
render=Renderizador(ruta+"/"+convertidor,ruta+"/"+originales,ruta+"/"+convertidos)
if(render.existen_orginales()>=1):
if(render.existe_convertido()>=1): render.iniciarrender()
else:print("IMPOSIBLE CREAR RUTA DESTINO , TIENE PERMISOS?")
else: print "NO hay archivos que listas"
else:
print "No existe convertidor"