| 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) |