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

Method checkTaskFile

src/astroprint/additionaltasks.py:66–112  ·  view source on GitHub ↗
(self, file)

Source from the content-addressed store, hash-verified

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:
85 zip_ref.close()
86 os.unlink(savedFile)
87 self._logger.error('Error checking uploaded Zip file', exc_info=True)
88 return {'error':'error_checking_file'}
89
90 zip_ref.close()
91
92 if not all(key in definition for key in self.REQUIRED_TASK_KEYS):
93 os.unlink(savedFile)
94 return {'error':'invalid_task_definition'}
95
96 #Check if the min_api_version is valid
97 #min_api_version = int(definition['min_api_version'])
98 #if TASK_API_VERSION < min_api_version:
99 # os.unlink(savedFile)
100 # return {'error':'incompatible_task', 'api_version': min_api_version}
101
102 task = self.getTask(definition['id'])
103 if task:
104 os.unlink(savedFile)
105 return {'error':'already_installed'}
106
107 response = {
108 'tmp_file': savedFile,
109 'definition': definition
110 }
111
112 return response
113
114 def installFile(self, filename):
115 if os.path.isfile(filename):

Callers 1

additionalTasksCreateFunction · 0.80

Calls 7

getTaskMethod · 0.95
joinMethod · 0.80
unlinkMethod · 0.80
saveMethod · 0.45
openMethod · 0.45
closeMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected