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

Method installFile

src/astroprint/additionaltasks.py:114–146  ·  view source on GitHub ↗
(self, filename)

Source from the content-addressed store, hash-verified

112 return response
113
114 def installFile(self, filename):
115 if os.path.isfile(filename):
116 tasksDir = settings().getBaseFolder('tasks')
117
118 #extract the contents of the plugin in it's directory
119 zip_ref = zipfile.ZipFile(filename, 'r')
120 taskInfo = zip_ref.open('task.yaml', 'r')
121 definition = yaml.safe_load(taskInfo)
122
123 taskId = definition.get('id')
124 if taskId:
125 assetsDir = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)),'static','img','variant', taskId))
126 for file in zip_ref.namelist():
127 if file.startswith('assets/'):
128 filename = file.replace('assets/','')
129 if filename:
130 zip_ref.extract(file, assetsDir)
131 os.rename(os.path.join(assetsDir, file), os.path.join(assetsDir, file.replace('assets/','')))
132
133 if os.path.isdir(os.path.join(assetsDir, 'assets')):
134 os.rmdir(os.path.join(assetsDir, 'assets'))
135
136 zip_ref.extract('task.yaml',tasksDir)
137 #rename the yaml file
138 os.rename(os.path.join(tasksDir,'task.yaml'), os.path.join(tasksDir, "%s.yaml" % taskId))
139 zip_ref.close()
140
141 self.data.append(definition)
142 return True
143
144 zip_ref.close()
145
146 return False
147
148 def removeTask(self, tId):
149 task = self.getTask(tId)

Callers

nothing calls this directly

Calls 8

settingsFunction · 0.90
joinMethod · 0.80
replaceMethod · 0.80
appendMethod · 0.80
getBaseFolderMethod · 0.45
openMethod · 0.45
getMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected