MCPcopy Create free account
hub / github.com/AstroPrint/AstroBox / AdditionalTasksManager

Class AdditionalTasksManager

src/astroprint/additionaltasks.py:27–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25from octoprint.settings import settings
26
27class AdditionalTasksManager(object):
28 REQUIRED_TASK_KEYS = ['id', 'steps']
29
30 def __init__(self):
31 self._settings = settings()
32 self._logger = logging.getLogger(__name__)
33 self.data = []
34 self.errorOnRemove = None
35
36 self._logger.info("Loading Additional Tasks...")
37
38 tasksDir = self._settings.getBaseFolder('tasks')
39 #tasksDir = "%s/tasks" % self._settings.getConfigFolder()
40
41 if os.path.isdir(tasksDir):
42 taskFiles = glob.glob('%s/*.yaml' % tasksDir)
43 if len(taskFiles):
44 self._logger.info("Found %d tasks to load." % len(taskFiles))
45 for f in taskFiles:
46 try:
47 with open(f, "r") as f:
48 config = yaml.safe_load(f)
49 if config:
50 self.data.append(config)
51
52 except:
53 self._logger.info("There was an error loading %s:" % f, exc_info= True)
54
55 return
56
57 self._logger.info("No additional Tasks present.")
58
59 def getTask(self, id):
60 for task in self.data:
61 if task['id'] == id:
62 return task
63
64 return None
65
66 def checkTaskFile(self, file):
67 filename = file.filename
68
69 if not ('.' in filename and filename.rsplit('.', 1)[1].lower() in ['zip']):
70 return {'error':'invalid_file'}
71
72 savedFile = os.path.join(gettempdir(), secure_filename(file.filename))
73 try:
74 file.save(savedFile)
75 zip_ref = zipfile.ZipFile(savedFile, 'r')
76 taskInfo = zip_ref.open('task.yaml', 'r')
77 definition = yaml.safe_load(taskInfo)
78
79 except KeyError:
80 zip_ref.close()
81 os.unlink(savedFile)
82 return {'error':'invalid_task_file'}
83
84 except:

Callers 1

additionalTasksManagerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected