-
Notifications
You must be signed in to change notification settings - Fork 0
/
deletion.py
54 lines (48 loc) · 1.09 KB
/
deletion.py
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
import os
import random
import dircache
import serial
import time
import win32api
import win32print
import tempfile
rootdir = 'C:\Users\iharrison\publicprint'
def readSignal():
ser = serial.Serial('COM11', 9600)
while True:
value = ser.readline()
print value
if value:
print 'inside'
print chooseFile(rootdir)
time.sleep(1)
def chooseFile(dir):
dircache.reset()
list = dircache.listdir(dir)
dircache.annotate(dir, list )
if list == []:
print 'restarting'
return chooseFile('C:\Users\iharrison\publicprint')
else:
filename = random.choice(list)
path = os.path.join(dir, filename)
if path[-1] == '/':
path = path[:-1]
return chooseFile(path)
else:
return path
def printFile(path):
# open (path, "w").write ("This is a test")
# http://timgolden.me.uk/pywin32-docs/win32api__ShellExecute_meth.html
win32api.ShellExecute (
0,
"print",
path,
#
# If this is None, the default printer will
# be used anyway.
#
'/d:"\\17NHT32\%s"' % "HP ENVY 5660 series (copy 1)",
".",
0
)