コード例 #1
0
            def start_edit(*args):
                index = args[0][0]
                self.contacts[index].wizard()
                self.contacts = Contact.Contact.update_all(self.contacts)
                io_formats.get_format(self.DEFAULT_DB_FORMAT).export_data(
                    self.contacts, self.file_path)

                self.make_menu()
コード例 #2
0
 def convert_file(info):
     # print(info)
     source_format, choosed_format, chosed_path = info
     temp_import = io_formats.get_format_from_ext(
         source_format).import_data(chosed_path)
     # print(temp_import)
     io_formats.get_format(choosed_format).export_data(
         temp_import,
         chosed_path.replace(source_format,
                             io_formats.get_format(choosed_format).EXT))
     print(
         "Le nouveau fichier sera écrit a côté du précédant sous le nom :" +
         chosed_path.replace(source_format,
                             io_formats.get_format(choosed_format).EXT))
コード例 #3
0
    def export_single(self, file_format):
        file_format = file_format[0]
        menu = EasyMenu("Veuillez choisir le/les contacts")
        menu.set_prompt("Votre choix (a,b,c,d): ")
        menu.set_multiple(True)

        for contact in self.contacts:
            menu.add_entry(contact.get_string(), None)

        menu.show_menu()
        chx = menu.wait_for_choise()
        contact_to_write = DataManipulation.get_selected_from_index(
            self.contacts, chx)
        file_path = input("Entrez un chemin pour le fichier: ")
        io_formats.get_format(file_format).export_data(contact_to_write,
                                                       file_path)

        self.make_menu()
コード例 #4
0
 def load_base(self, *args):
     self.file_path = input("Entrez le chemin du fichier de base donnée[" +
                            self.DEFAULT_FILE_PATH + "] :")
     if self.file_path == "":
         self.file_path = self.DEFAULT_FILE_PATH
         self.contacts = io_formats.get_format(
             self.DEFAULT_DB_FORMAT).import_data(self.file_path)
         self.loaded = True
     self.make_menu()
コード例 #5
0
    def save(content, file=DEFAULT_FILE_PATH, zip=False, db=False):
        tmp_folder = "./tmp/" + os.path.splitext(os.path.basename(file))[0]
        if os.path.exists(tmp_folder):
            shutil.rmtree(tmp_folder)

        os.makedirs(tmp_folder)

        from appData import io_formats
        format = io_formats.get_format_from_ext(os.path.splitext(file)[1])
        export = format.export_data(
            content, file if not zip else tmp_folder + os.path.basename(file))

        if zip:
            export = io_formats.get_format("zip").export_data(export, file)

        return export
コード例 #6
0
    def __init__(self, base="", port=80, ip="127.0.0.1"):
        if port is None:
            port = 80

        if ip is None:
            ip="127.0.0.1"

        if os.path.exists(base):
            self.base = os.path.abspath(base)
            self.contacts = io_formats.get_format(WebApp.DEFAULT_DB_FORMAT).import_data(base)
        else:
            self.contacts = []
        self.env = Environment(loader=FileSystemLoader(self.TEMPLATE_FOLDER))

        cherrypy.config.update({
            'server.socket_host': ip,
            'server.socket_port': port,
        })

        conf = {
            '/': {
                'tools.sessions.on': True,
                'tools.staticdir.root': os.path.abspath(os.getcwd())
            },
            '/static': {
                'tools.staticdir.on': True,
                'tools.staticdir.dir': './appData/webData/static'
            }
        }

        if os.path.exists(self.TMP_FOLDER):
            shutil.rmtree(self.TMP_FOLDER)

        os.makedirs(self.TMP_FOLDER)

        cherrypy.tree.mount(View(self), '/view', conf)
        cherrypy.tree.mount(Manager(self), '/manage', conf)
        cherrypy.tree.mount(Convert(self), '/convert', conf)
        cherrypy.quickstart(Index(self), '/', conf)
コード例 #7
0
    def exports(self, iden="", **kwargs):
        values = cherrypy.request.params

        print(values)
        if values != {}:
            try:
                format_chosen = values['format']
                filename = values['filename']
                choise = values['chk']
            except:
                return self.get_page_content("exports",
                                             formats=io_formats.get_formats(),
                                             contacts=self.app.contacts,
                                             emptyquery=True)

            original_dest = "./webData/tmp/" + filename

            chosen_contacts = DataManipulation.get_selected_from_index(
                self.app.contacts, DataManipulation.string_list_to_int(choise))
            dest = io_formats.get_format(format_chosen).export_data(
                chosen_contacts, original_dest)

            if type(dest) is list:
                zipfilename = os.path.splitext(original_dest)[0] + ".zip"
                with ZipFile(zipfilename, 'w') as myzip:
                    for d in dest:
                        myzip.write(os.path.abspath(d), os.path.normcase(d))
                return serve_file(os.path.abspath(zipfilename),
                                  "application/x-download",
                                  os.path.basename(zipfilename))
            else:
                return serve_file(os.path.abspath(dest),
                                  "application/x-download", filename)

        return self.get_page_content("exports",
                                     formats=io_formats.get_formats(),
                                     contacts=self.app.contacts,
                                     iden=iden)
コード例 #8
0
 def export_all(self, args):
     file_format = args[0]
     file_path = input("Entrez un chemin pour le fichier: ")
     io_formats.get_format(file_format).export_data(self.contacts,
                                                    file_path)
     self.make_menu()
コード例 #9
0
 def quit(self, *args):
     print("Save and quit")
     if self.loaded:
         io_formats.get_format(self.DEFAULT_DB_FORMAT).export_data(
             self.contacts, self.file_path)
     exit(0)
コード例 #10
0
 def add_contact(self, *args):
     self.contacts.append(Contact.Contact().wizard())
     self.contacts = Contact.Contact.update_all(self.contacts)
     io_formats.get_format(self.DEFAULT_DB_FORMAT).export_data(
         self.contacts, self.file_path)
     self.make_menu()
コード例 #11
0
    def index(self, **kwargs):
        values = cherrypy.request.params
        print(values)
        if values != {}:
            try:
                format_chosen = values['format']
                filename = values['filename']

                if filename == "":
                    return self.get_page_content(
                        "index",
                        formats=io_formats.get_formats(),
                        complete=False)

                files = values['importfile']
                if type(files) is not list:
                    files = [files]

                for file in files:
                    import_format = io_formats.get_format_from_ext(
                        os.path.splitext(file.filename)[1])

                    upload_path = os.path.normpath(self.app.TMP_FOLDER)
                    upload_file = os.path.join(upload_path, file.filename)
                    with open(upload_file, 'wb') as out:
                        while True:
                            data = file.file.read(8192)
                            if not data:
                                break
                            out.write(data)

                    i = import_format.import_data(upload_file)
                    print(i)

                    original_dest = self.app.TMP_FOLDER + filename

                    dest = io_formats.get_format(format_chosen).export_data(
                        i, original_dest)

                    if type(dest) is list:
                        zipfilename = os.path.splitext(
                            original_dest)[0] + ".zip"
                        with ZipFile(zipfilename, 'w') as myzip:
                            for d in dest:
                                myzip.write(os.path.abspath(d),
                                            os.path.normcase(d))
                        return serve_file(os.path.abspath(zipfilename),
                                          "application/x-download",
                                          os.path.basename(zipfilename))
                    else:
                        return serve_file(os.path.abspath(dest),
                                          "application/x-download", filename)
            except KeyError:
                return self.get_page_content("index",
                                             formats=io_formats.get_formats(),
                                             complete=False)
            except NotImplementedError:
                return self.get_page_content("index",
                                             wrongtype=True,
                                             formats=io_formats.get_formats())

        return self.get_page_content('index',
                                     formats=io_formats.get_formats(),
                                     complete=True)