Imports fits from file(s). First processes all provided paths and stores assembled fits into a list. This allows us to call back to the GUI as fits are processed as well as when fits are being saved. returns
(paths, progress=None)
| 114 | |
| 115 | @staticmethod |
| 116 | def importFitFromFiles(paths, progress=None): |
| 117 | """ |
| 118 | Imports fits from file(s). First processes all provided paths and stores |
| 119 | assembled fits into a list. This allows us to call back to the GUI as |
| 120 | fits are processed as well as when fits are being saved. |
| 121 | returns |
| 122 | """ |
| 123 | |
| 124 | sFit = svcFit.getInstance() |
| 125 | |
| 126 | fit_list = [] |
| 127 | try: |
| 128 | for path in paths: |
| 129 | if progress: |
| 130 | if progress and progress.userCancelled: |
| 131 | progress.workerWorking = False |
| 132 | return False, "Cancelled by user" |
| 133 | msg = "Processing file:\n%s" % path |
| 134 | progress.message = msg |
| 135 | pyfalog.debug(msg) |
| 136 | |
| 137 | with open(path, "rb") as file_: |
| 138 | srcString = file_.read() |
| 139 | dammit = UnicodeDammit(srcString) |
| 140 | srcString = dammit.unicode_markup |
| 141 | |
| 142 | if len(srcString) == 0: # ignore blank files |
| 143 | pyfalog.debug("File is blank.") |
| 144 | continue |
| 145 | |
| 146 | try: |
| 147 | importType, makesNewFits, fitsImport = Port.importAuto(srcString, path, progress=progress) |
| 148 | fit_list += fitsImport |
| 149 | except xml.parsers.expat.ExpatError: |
| 150 | pyfalog.warning("Malformed XML in:\n{0}", path) |
| 151 | msg = "Malformed XML in %s" % path |
| 152 | if progress: |
| 153 | progress.error = msg |
| 154 | progress.workerWorking = False |
| 155 | return False, msg |
| 156 | |
| 157 | numFits = len(fit_list) |
| 158 | for idx, fit in enumerate(fit_list): |
| 159 | if progress and progress.userCancelled: |
| 160 | progress.workerWorking = False |
| 161 | return False, "Cancelled by user" |
| 162 | # Set some more fit attributes and save |
| 163 | fit.character = sFit.character |
| 164 | fit.damagePattern = sFit.pattern |
| 165 | fit.targetProfile = sFit.targetProfile |
| 166 | if len(fit.implants) > 0: |
| 167 | fit.implantLocation = ImplantLocation.FIT |
| 168 | else: |
| 169 | useCharImplants = sFit.serviceFittingOptions["useCharacterImplantsByDefault"] |
| 170 | fit.implantLocation = ImplantLocation.CHARACTER if useCharImplants else ImplantLocation.FIT |
| 171 | db.save(fit) |
| 172 | # IDs.append(fit.ID) |
| 173 | if progress: |
no test coverage detected