MCPcopy Create free account
hub / github.com/pyfa-org/Pyfa / importFitFromFiles

Method importFitFromFiles

service/port/port.py:116–190  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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:

Callers 1

Calls 4

importAutoMethod · 0.80
saveMethod · 0.80
getInstanceMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected