示例#1
0
def validateData(folderData, issues_pathname, slot, slotsize, workspaceName):
    status = LoggerTaskStatus("ValidateArena2Files")

    issues_pathname = issues_pathname % slot
    fnames, slots = calculateSlots(folderData, slotsize, slot, status)
    status.logger("validate slot %d/%d" % (slot, slots))

    if not connectToWorkspace(workspaceName, status):
        return

    importManager = getArena2ImportManager()
    report = MyReport(importManager)
    report.setEnabledEvents(False)
    dataManager = DALLocator.getDataManager()
    workspace = dataManager.getDatabaseWorkspace("ARENA2_DB")
    if workspace == None:
        status.logger("Can't access to workspace ARENA2_DB", gvsig.LOGGER_WARN)

    p = ValidatorProcess(importManager, fnames, report, workspace, status)
    p.run()

    if os.path.exists(issues_pathname):
        status.logger("removing file %r" % issues_pathname)
        os.unlink(issues_pathname)
    explorer = dataManager.openServerExplorer("FilesystemExplorer")
    store = report.getStore()
    status.logger("export issues to %r" % issues_pathname)
    store.export(explorer, "CSV",
                 explorer.getAddParameters(File(issues_pathname)))
def importData(issues_pathname, slot, slotsize, workspaceName):
  status = LoggerTaskStatus("ImportArena2Files")

  issues_pathname = issues_pathname % slot
  fnames, slots = calculateSlots(folderData, slotsize, slot, status)
  status.logger("import slot %d/%d" % (slot, slots))

  if not connectToWorkspace(workspaceName, status):
    return
    
  importManager = getArena2ImportManager()
  report = Report(importManager)
  report.setEnabledEvents(False)
  dataManager = DALLocator.getDataManager()
  workspace = dataManager.getDatabaseWorkspace("ARENA2_DB")
  if workspace==None:
    status.logger("Can't access to workspace ARENA2_DB", gvsig.LOGGER_WARN)
    return

  issues = dataManager.openStore("CSV","File", issues_pathname)
  report.addIssues(issues.getFeatureSet())
  if len(report) != issues.getFeatureCount():
    status.logger("Can't load issues in report", gvsig.LOGGER_WARN)
    return
    
  p = ImportProcess(importManager, fnames, workspace, report, status)
  p.run()
def connectToWorkspace(name, status=None):
  if status == None:
    status = LoggerTaskStatus("ImportArena2Files")
    
  dataManager = DALLocator.getDataManager()
  pool = dataManager.getDataServerExplorerPool()
  poolentry = pool.get(name)
  if poolentry==None:
    status.logger("Can't locate connection %r" % name, gvsig.LOGGER_WARN)
    return False
  conn = poolentry.getExplorerParameters()
  workspace = dataManager.createDatabaseWorkspaceManager(conn)
  workspace.connect()
  status.logger("Connected to workspace %r" % name)
  return True
def validateData(issues_pathname, workspaceName):
  status = LoggerTaskStatus("ValidateArena2DB")
    
  #issues_pathname = issues_pathname % slot
  #status.logger("validate slot %d/%d" % (slot, slots))
  print "Printing"
  if not connectToWorkspace(workspaceName, status):
    print "out 1"
    return
  print "Printing 2"
  importManager = getArena2ImportManager()
  report = MyReport(importManager)
  report.setEnabledEvents(False)
  print "Checking access to database work space.."
  dataManager = DALLocator.getDataManager()
  workspace = dataManager.getDatabaseWorkspace('ARENA2_DB')
  
  if workspace==None:
    print "..out"
    status.logger("Can't access to workspace ARENA2_DB", gvsig.LOGGER_WARN)
    return

  print "PostValidating process.."
  p = PostValidatorProcess(importManager, report, workspace, status)
  print ".. preparing.."
  p.run()
  print ".. after run."

  if os.path.exists(issues_pathname):
    status.logger("removing file %r" % issues_pathname)
    os.unlink(issues_pathname)
  explorer = dataManager.openServerExplorer("FilesystemExplorer")
  store = report.getStore()
  status.logger("export issues to %r" % issues_pathname)
  import ntpath
  base = ntpath.basename(issues_pathname)
  #store.export(explorer,"CSV",explorer.getAddParameters(File(issues_pathname)), base)
  print "## DONE EXPORT"
示例#5
0
def calculateSlots(folderData, slotsize, slot=0, status=None):
    if status == None:
        status = LoggerTaskStatus("ImportArena2Files")

    status.logger("Searching files in %r" % folderData)
    factory = Arena2ReaderFactory()
    fnames = list()
    for root, dirs, files in os.walk(folderData, followlinks=True):
        for name in files:
            pathname = os.path.join(root, name)
            if pathname.lower().endswith(".xml"):
                if factory.accept(File(pathname)):
                    fnames.append(pathname)
                else:
                    status.logger("skip file: %r" % pathname,
                                  gvsig.LOGGER_WARN)
    fnames.sort()

    status.logger("Found %d files" % len(fnames))
    for n in range(0, len(fnames)):
        status.logger("File: %r" % fnames[n])

    slots = (len(fnames) / slotsize)
    if (len(fnames) % slotsize) > 0:
        slots += 1
    status.logger("Slots:")
    for n in range(0, slots):
        slide_start = n * slotsize
        slide_end = (n + 1) * slotsize - 1
        if slide_end > len(fnames):
            slide_end = len(fnames)
        status.logger("Slot %3d: [%3d : %3d]" % (n, slide_start, slide_end))

    slide_start = slot * slotsize
    slide_end = (slot + 1) * slotsize - 1
    if slide_end > len(fnames):
        slide_end = len(fnames)
    status.logger("Slot size   : %d" % slotsize)
    status.logger("Total files : %d" % len(fnames))
    status.logger("Total slots : %d" % slots)
    status.logger("Current slot: %d [%3d : %3d]" %
                  (slot, slide_start, slide_end))
    if slot + 1 > slots:
        status.logger("Next slot   : None (process finished)")
    else:
        status.logger("Next slot   : %d" % (slot + 1))

    return fnames[slide_start:slide_end], slots