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

Method installFile

src/astroprint/maintenancemenu.py:138–167  ·  view source on GitHub ↗
(self, filename)

Source from the content-addressed store, hash-verified

136 return response
137
138 def installFile(self, filename):
139 if os.path.isfile(filename):
140
141 #extract the contents of the plugin in it's directory
142 zip_ref = zipfile.ZipFile(filename, 'r')
143 menuInfo = zip_ref.open('utilities-menu.yaml', 'r')
144 definition = yaml.safe_load(menuInfo)
145 assetsDir = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)),'static','img','variant','utilities_menu'))
146
147 #remove utilities_menu folder
148 shutil.rmtree(assetsDir, ignore_errors=True)
149
150 #move the image files into utilities_menu folder
151 for file in zip_ref.namelist():
152 if file.startswith('assets/'):
153 fileIcon = file.replace('assets/','')
154 if fileIcon:
155 zip_ref.extract(file, assetsDir)
156 os.rename(os.path.join(assetsDir, file), os.path.join(assetsDir, file.replace('assets/','')))
157
158 if os.path.isdir(os.path.join(assetsDir, 'assets')):
159 os.rmdir(os.path.join(assetsDir, 'assets'))
160
161 zip_ref.extract('utilities-menu.yaml', os.path.dirname(self._maintenanceMenu))
162 zip_ref.close()
163
164 self.data = definition
165 return True
166
167 return False
168
169 def removeMenu(self, tId):
170 #remove definition file

Callers

nothing calls this directly

Calls 4

joinMethod · 0.80
replaceMethod · 0.80
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected