def _open_db(self): # If there's no CC db in moneyGuru's appdata folder, copy a model from CC's appdata. if not self.has_db(): if not io.exists(self._mgccdbpath[:-1]): io.makedirs(self._mgccdbpath[:-1]) io.copy(self._ccdbpath, self._mgccdbpath) self._db = CashculatorDB(str(self._mgccdbpath))
def __ProcessNormalList(self, name_list, copy=False, job=nulljob): name_list = [ paths for paths in name_list if (paths[0] != paths[1]) and io.exists(paths[0]) ] conflicts = [] tmpdir = None job.start_job(len(name_list)) for source, dest in name_list: try: if io.exists(dest): if not tmpdir: tmpdir = Path(tempfile.mkdtemp()) newdest = tmpdir + dest[self.destination:] conflicts.append((newdest, dest, source)) dest = newdest if not io.exists(dest[:-1]): io.makedirs(dest[:-1]) if copy: io.copy(source, dest) else: io.move(source, dest) except (OSError, IOError) as e: print("Warning: Error %r occured while processing %r to %r."\ % (e, str(source), str(dest))) job.add_progress() for source, dest, old_source in conflicts: if not io.exists(dest): io.rename(source, dest) elif not io.exists(old_source): io.rename(source, old_source)
def __ProcessCDList(self, name_list, cd_path, cd_location, job=nulljob): job.start_job(len(name_list)) for source, dest in name_list: if not io.exists(dest[:-1]): io.makedirs(dest[:-1]) if not io.exists(dest): processed = False while cd_path and (not processed): try: io.copy((cd_path + source), dest) processed = True except (OSError, IOError): if io.exists(cd_path + source): processed = True #This is a very special case. It happens when the path on the #CD is too long to be copied. It very seldom happens. Just skip the file. else: cd_path = self.OnNeedCD(cd_location) if cd_path: cd_path = Path(cd_path) else: return False job.add_progress() return True
def _do_copy(self, src, dest): io.copy(src, dest)