-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
65 lines (52 loc) · 2.04 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
import mailfetch
import time
import config
import logger
import user_tracking as users
import slicer
import converter
#import validator
import printer
"""
Each step of the module should be a function that takes a PrintJob object, and returns a new PrintJob object. See pipeline.py for more info.
"""
def main():
# read the config file. We'll need this later.
# also caches the file for stages
configrc = config.read_config()
udb = users.UserDB()
# set up mailfetch. Just fetches the password for now.
# v option is temporary, and prevents pipeline from flooding console
# should eventually be replaced by proper logging system
plogger = logger.Logger('pipeline')
mailfetch.initialize()
while True:
try:
poll = mailfetch.poll()
# mailfetch.poll gets list of printjobs to work on
for job in poll:
email = job.sender
'''user = udb.find_user(email)
if user != None:
user.jobs_submitted += 1
else:
user = users.User(email, 1)
udb.add_user(user)'''
#pipeline goes here
#each step of the pipeline sets the status and then runs the stage
#the stage should store a new file if one is created, but nothing else.
job.status = 'converting'
converter.convert(job)
#job.status = 'validating'
#validator.validate(job)
job.status = 'slicing'
slicer.slice(job)
job.status = 'printing'
printer.send_job(job)
except TypeError:
return
# wait a while. This lets the computer do something else
delay_time = float(configrc['Pipeline']['poll_frequency'])
time.sleep(delay_time)
if __name__ == '__main__':
main()