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

Method checkMenuFile

src/astroprint/maintenancemenu.py:101–136  ·  view source on GitHub ↗
(self, file)

Source from the content-addressed store, hash-verified

99 yaml.safe_dump(self.data, maintenanceMenu, default_flow_style=False, indent=" ", allow_unicode=True)
100
101 def checkMenuFile(self, file):
102 filename = file.filename
103
104 if not ('.' in filename and filename.rsplit('.', 1)[1].lower() in ['zip']):
105 return {'error':'invalid_file'}
106
107 savedFile = os.path.join(gettempdir(), secure_filename(file.filename))
108 try:
109 file.save(savedFile)
110 zip_ref = zipfile.ZipFile(savedFile, 'r')
111 menuInfo = zip_ref.open('utilities-menu.yaml', 'r')
112 definition = yaml.safe_load(menuInfo)
113
114 except KeyError:
115 zip_ref.close()
116 os.unlink(savedFile)
117 return {'error':'invalid_menu_file'}
118
119 except:
120 zip_ref.close()
121 os.unlink(savedFile)
122
123 self._logger.error('Error checking uploaded Zip file', exc_info=True)
124 return {'error':'error_checking_file'}
125
126 #Check if the min_api_version is valid
127 #min_api_version = int(definition['min_api_version'])
128 #if TASK_API_VERSION < min_api_version:
129 # os.unlink(savedFile)
130 # return {'error':'incompatible_task', 'api_version': min_api_version}
131 response = {
132 'tmp_file': savedFile,
133 'definition': definition
134 }
135
136 return response
137
138 def installFile(self, filename):
139 if os.path.isfile(filename):

Callers 1

maintenanceMenuCreateFunction · 0.80

Calls 6

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

Tested by

no test coverage detected