コード例 #1
0
ファイル: Metadator.py プロジェクト: Guts/Metadator
    def setpathtarg(self):
        """ ...browse and insert the path of target folder """
        foldername = askdirectory(parent=self,
                                  initialdir=self.def_rep,
                                  mustexist=True,
                                  title=self.blabla.get('gui_cible'))
        # check if a folder has been choosen
        if foldername:
            try:
                self.target.delete(0, END)
                self.target.insert(0, foldername)
            except:
                info(title=self.blabla.get('nofolder'),
                     message=self.blabla.get('nofolder'))
                return

        # count shapefiles and MapInfo files in a separated thread
        proc = threading.Thread(target=self.li_geofiles,
                                args=(foldername, ))
        proc.daemon = True
        proc.start()

        # end of function
        return foldername
コード例 #2
0
##### Création du fichier excel
print "Création et configuration du fichier excel"
book = xlwt.Workbook(encoding = 'Latin-1')
feuy1 = book.add_sheet('Frequences', cell_overwrite_ok=True)

font1 = xlwt.Font()             # création police 1
font1.name = 'Times New Roman'
font1.bold = True
entete = xlwt.XFStyle()         # création style pour les en-têtes
entete.font = font1

# Intitulés
feuy1.write(0,0,chp_cible, entete)
feuy1.write(0,1,'Occurences', entete)

###### Inscription dans un fichier excel
print "Inscription des fréquences dans le fichier excel"
x, y = 0, 0
for clef, valeur in dico_occurences.items():
    feuy1.write(x+1,y, clef)
    feuy1.write(x+1,y+1, valeur)
    x = x+1

##### Sauvegarde du fichier excel
cible = savefic(filetypes=[("Classeurs Excel","*.xls")])
if path.splitext(cible)[1] != ".xls":
    cible = cible + ".xls"
book.save(cible)
info(title="Operation terminee.", message="Calcul termine. Fichier excel sauvegarde . " + cible)
annuler()
コード例 #3
0
ファイル: DicoShapes_fr.py プロジェクト: Pruline/DicoGIS
    # And go to the next line
    lig = lig +1

## Save the Excel file
# Prompt of folder where save the file
saved = savefic(initialdir= cible,
                defaultextension = '.xls',
                initialfile = "DicoShapes_" + today + "_",
                filetypes = [("Classeurs Excel","*.xls")])
if path.splitext(saved)[1] != ".xls":
    saved = saved + ".xls"
book.save(saved)

## Log information to the user
if dico_err.keys() == []:    # s'il n'y a pas d'erreur
    info(title=u"Fin de programme", message=u"Programme terminé.\
                                              \nAucune erreur rencontrée.")
else:    # s'il y a des erreurs, création d'un fichier log
    fic = open(cible + "\\" + today + "_dico-shapes_log.txt", 'w')
    dump("Erreurs rencontrées sur les tables suivantes : \n\n", fic)
    fic.write('/n/n')
    dump(dico_err, fic)
    fic.close()
    info(title=u"Fin de programme", message=u"Programme terminé.\
        \nConsultez le fichier log créé pour les détails : \
        \n" + cible + u"\\" + unicode(today) + u"_dico-shapes_log.txt")

# End of program
startfile(fic.name)
startfile(cible)
del book
コード例 #4
0
        feuy1.write(lig, 8, int(str(count_obj(shape))))    # compte le nombre d'objets
        feuy1.write(lig, 9, desc.hasM)    # indique si le shape possède un
        feuy1.write(lig, 10, desc.hasZ)    # indique si le shape possède des données d'altitude
    except:    # gestion des erreurs
        l_err.append(shape)    # liste des shapes qui renvoient des erreurs
        feuy1.write(lig, 0, desc.basename)
        lien = 'HYPERLINK("' + desc.path + '"; "Atteindre le dossier")'    # chemin du dossier contenant formaté pour être un lien
        feuy1.write(lig, 1, Formula(lien), hyperlien)
        feuy1.write(lig, 2, "ERREUR", entete)
    lig = lig +1


## Sauvegarde du fichier excel
saved = savefic(initialdir= cible, filetypes=[("Classeurs Excel","*.xls")])
if path.splitext(saved)[1] != ".xls":
    saved = saved + ".xls"
book.save(saved)

## Bilan programme
if l_err == []:    # s'il n'y a pas d'erreur
    info(title=u"Fin de programme", message=u"Programme terminé.\nAucune erreur rencontrée.")
else:    # s'il y a des erreurs, création d'un fichier log
    from datetime import date
    fic = open(cible + "\\" + str(date.today()) + "_dico-shapes_log.txt", 'w')
    fic.write("Erreurs rencontrées sur les shapes suivants : \n\n")
    for i in l_err:
        fic.write(i.encode("utf-8"))
        fic.write("\n-------------------------\n")
    fic.close()
    info(title=u"Fin de programme", message=u"Programme terminé.\n" + unicode(len(l_err)) + u" erreur(s) rencontrée(s).\n Consultez le fichier log créé pour les détails : \n" + cible + "\\" + unicode(date.today()) + u"_dico-shapes_log.txt")
コード例 #5
0
ファイル: Metadator.py プロジェクト: Guts/Metadator
    def process(self):
        u""" launch the different processes """
        # display the main tab
        self.nb.select(0)
        # check option selected: process or create a new profile
        if self.ddl_profil.get() == self.blabla.get('tab1_new'):
            # launching the profile form
            self.logger.info('Creation of a new profile')
            tr_profile = threading.Thread(target=NewProfile,
                                          args=(self.blabla,
                                                self.ddl_lang.get(),
                                                self.dico_help,
                                                self.li_pro))
            tr_profile.daemon = True
            tr_profile.run()
            # NewProfile(self.blabla, self.ddl_lang.get(), self.li_pro)
            self.li_profiles(self.ddl_lang.get())   # updating the dropdow list
            self.ddl_profil['values'] = self.li_pro
            return
        # check if the target folder has been selected
        if self.target.get() == "":
            info(title=self.blabla.get('info_blanktarget1'),
                 message=self.blabla.get('info_blanktarget2'))
            return
        # check if a profile has been selected
        if self.ddl_profil.get() == "":
            info(title=self.blabla.get('info_blankprofile1'),
                 message=self.blabla.get('info_blankprofile2'))
            return
        # disabling others GUI parts
        self.tab_globals.focus_force()
        self.alter_state(self.FrPath, DISABLED)

        # check if there are some layers into the folder structure
        if len(self.li_shp) + len(self.li_tab) == 0:
            self.logger.warning("No geofiles found in the folder structure")
            self.status.set(self.blabla.get('log_nodata'))
            return
        # specific variables
        dest = path.join(self.target.get(), 'metadator')
        if not path.isdir(dest):    # test if folder already exists
            mkdir(dest, 0777)       # if not, we create it
        # getting profile informations
        self.recup_profil(self.ddl_lang.get())
        # saving options in a separated thread
        tr_options = threading.Thread(target=self.save_settings)
        tr_options.daemon = True
        tr_options.start()
        self.logger.info('Current options saved')
        # saving recurring fiels in a separated thread
        tr_rekurs = threading.Thread(target=self.saveas_rekurs,
                                     args=(self.ddl_lang.get(), ))
        tr_rekurs.daemon = True
        tr_rekurs.start()
        # configuring the progression bar
        self.prog_layers["maximum"] = len(self.li_shp) + len(self.li_tab)
        self.prog_layers["value"]
        # Processing the shapefiles
        self.logger.info('\tStart processing the files')
        for shp in self.li_shp:
            """ looping on shapefiles list """
            self.logger.info('Processing: %s' % path.basename(shp))
            self.status.set(path.basename(shp))
            # reset recipient data
            self.dico_layer.clear()
            self.dico_fields.clear()
            # getting separated process threads
            Read_SHP(shp,
                     self.dico_layer,
                     self.dico_fields,
                     'shape',
                     self.blabla)
            # checking layer error
            if self.dico_layer.get('error'):
                # increment the progress bar
                self.prog_layers["value"] = self.prog_layers["value"] + 1
                self.update()
                self.logger.warning('This shape has an issue: %s' % shp)
                continue
            # getting fields statistics only if needed
            if self.def_doc.get() == 1 or self.def_xls.get() == 1 or self.def_odt.get() == 1:
                StatsFields(shp, self.dico_fields, self.dico_rekur, self.blabla)
            # export according to options selected
            if self.def_doc.get() == 1:
                ExportToHTML(dest,
                             self.dico_layer,
                             self.dico_fields,
                             self.dico_profil,
                             self.dico_rekur,
                             self.blabla)
                html_path = path.join(dest,
                                      "{0}_MD.html".format(self.dico_layer['name'][:-4]))
                ExportToDocX(html_path, dest)
            if self.def_xls.get() == 1:
                ExportToXLS(dest,
                            self.dico_layer,
                            self.dico_fields,
                            self.dico_profil,
                            self.dico_rekur,
                            self.blabla)
            if self.def_xml.get() == 1:
                ExportToXML(dest,
                            self.dico_layer,
                            self.dico_profil,
                            '',
                            self.blabla,
                            1,
                            0)
            if self.def_odt.get() == 1:
                ExportToODT(dest,
                            self.dico_layer,
                            self.dico_fields,
                            self.dico_profil,
                            self.dico_rekur,
                            self.blabla)
            # increment the progress bar
            self.prog_layers["value"] = self.prog_layers["value"] + 1
            self.update()

        # Processing the MapInfo tables
        for tab in self.li_tab:
            """ looping on MapInfo tables list """
            self.logger.info('Processing: %s' % path.basename(tab))
            self.status.set(path.basename(tab))
            # reset recipient data
            self.dico_layer.clear()
            self.dico_fields.clear()
            # getting the informations
            Read_TAB(tab,
                     self.dico_layer,
                     self.dico_fields,
                     'table',
                     self.blabla)
            # checking layer error
            if self.dico_layer.get('error'):
                self.logger.warning('This MapInfo table has an issue: %s' % tab)
                # increment the progress bar
                self.prog_layers["value"] = self.prog_layers["value"] +1
                self.update()
                continue
            # getting fields statistics only if needed
            if self.def_doc.get() == 1 \
               or self.def_xls.get() == 1 \
               or self.def_odt.get() == 1:
                StatsFields(tab, self.dico_fields, self.dico_rekur, self.blabla)
            # export according to options selected
            if self.def_doc.get() == 1:
                ExportToHTML(dest,
                             self.dico_layer,
                             self.dico_fields,
                             self.dico_profil,
                             self.dico_rekur,
                             self.blabla)
                html_path = path.join(dest,
                                      "{0}_MD.html".format(self.dico_layer['name'][:-4]))
                ExportToDocX(html_path, dest)
            if self.def_xls.get() == 1:
                ExportToXLS(dest,
                            self.dico_layer,
                            self.dico_fields,
                            self.dico_profil,
                            self.dico_rekur,
                            self.blabla)
            if self.def_xml.get() == 1:
                ExportToXML(dest,
                            self.dico_layer,
                            self.dico_profil,
                            '',
                            self.blabla,
                            1,
                            0)
            if self.def_odt.get() == 1:
                ExportToODT(dest,
                            self.dico_layer,
                            self.dico_fields,
                            self.dico_profil,
                            self.dico_rekur,
                            self.blabla)
            # increment the progress bar
            self.prog_layers["value"] = self.prog_layers["value"] + 1
            self.update()

        # Word catalog export
        if self.def_doc.get() == 1 and self.def_cat.get() == 1:
            self.status.set(self.blabla.get('info_cat'))
            self.update()
            DocxMerger(dest, '00_Metadator_Catalog', 'metadator_')
        else:
            pass

        # final message
        # msg = self.blabla.get('info_end2') + self.blabla.get('info_end3')
        # info(title=self.blabla.get('info_end'), message=msg)
        # opening the destination folder
        self.open_dir_file(dest)
        # cleaning up
        logging.info('Hurray! It worked! All seem to have been fine!')
        self.destroy()
        # end of function
        return