Exemple #1
0
    def __download_package (self, item_attrs):
        r"""
             tries to download zip archive and install it locally;
        """

        # inits

        _src = item_attrs["src"]

        # got remote zip archive?

        if tools.is_pstr(_src):

            # ask user for downloading zip archive

            _response = MB.askquestion(

                _("Download"),

                _(
                    "Package is missing locally.\n"
                    "Download it from the web?"
                ),

                parent=self,
            )

            # user is OK to download package

            if _response == MB.YES:

                # show download box component

                self._show_download_box()

                # download in temporary file

                return self.mainframe.debbie.download(url=_src)

            else:

                MB.showinfo(

                    _("Info"),

                    _("Package download aborted."),

                    parent=self,
                )

            # end if - MB.response

        else:

            # error

            raise ValueError(

                _("no remote ZIP archive to download")
            )
    def go_parent (self, *args, **kw):
        r"""
            shows parent section;
        """

        if tools.is_pstr(self._parent_section_id):

            self._open_section(section_id = self._parent_section_id)

        else:

            self.go_home()
 def do_open_project (self, fpath):
     """
         effective procedure for opening project;
     """
     # param controls
     if self.is_good_file_format(fpath):
         # notify application
         self.notify(_("Opening project, please wait."))
         # reset to new
         self.do_reset_project()
         # open zip archive
         with zipfile.ZipFile(fpath, 'r') as _archive:
             # browse archive files
             for tab_id, fname in self.ARCHIVE_FILES.items():
                 # simple file contents
                 if tools.is_pstr(fname):
                     # set contents instead
                     fname = _archive.read(fname).decode(ENCODING)
                     # strip unwanted
                     fname = fname.strip()
                 # end if
                 # setup notebook tab
                 self.setup_tab(tab_id, fname, _archive)
             # end for
         # end with
         # we can update project's filepath by now
         self.set_project_path(fpath)
         # notify application
         self.notify(_("Project opened OK."))
         # succeeded
         return self.YES
     # could not open file
     else:
         # show error
         MB.showerror(
             title=_("Error"),
             message=_(
                 "Could not open project. "
                 "Incorrect file path or file format."
             ),
             parent=self.mainwindow,
         )
         # failed
         return self.NO
 def do_save_project (self, fpath):
     """
         effective procedure for saving project;
     """
     # param inits
     fpath = P.normalize(fpath)
     # param controls
     if tools.is_pstr(fpath):
         # notify application
         self.notify(_("Saving project, please wait."))
         # open zip archive
         with zipfile.ZipFile(fpath, 'w') as _archive:
             # browse archive files
             for tab_id, fname in self.ARCHIVE_FILES.items():
                 # get multiple files and contents
                 _contents = self.get_fc_tab(tab_id, fname)
                 # browse contents
                 for _fname, _fcontents in _contents.items():
                     # put files and contents into zip archive
                     _archive.writestr(
                         _fname, bytes(_fcontents, ENCODING)
                     )
                 # end for
             # end for
         # end with
         # we can update project's filepath by now
         self.set_project_path(fpath)
         # notify application
         self.notify(_("Project saved OK."))
         # succeeded
         return self.YES
     # could not save file
     else:
         # show error
         MB.showerror(
             title=_("Error"),
             message=_(
                 "Could not save project. Incorrect file path."
             ),
             parent=self.mainwindow,
         )
         # failed
         return self.NO
 def get_files_from_dict (self, dict_object):
     """
         extracts filenames from an archive dictionnary;
     """
     # inits
     _flist = list()
     # browse dict items
     for _fname in dict_object.values():
         # got another dict?
         if tools.is_pdict(_fname):
             # extend list with other list
             _flist.extend(self.get_files_from_dict(_fname))
         # must be plain string
         elif tools.is_pstr(_fname):
             # append item
             _flist.append(_fname)
         # end if
     # end for
     # return list of filenames
     return _flist
 def import_character_name (self, **fields):
     """
         imports a new character name into database;
     """
     # param inits
     self.parse_gender(fields)
     # all mandatory fields *DO* exist by now (and *ONLY* them)
     _row = self.clean_up(fields, self.FIELD_NAMES)
     # value *MUST* be a plain string of chars
     if tools.is_pstr(_row["name"]):
         # inits
         _row["origin"] = _row["origin"].lower()
         _row["description"] = _row["description"].capitalize()
         # do SQL query
         self.sql_query(self.SQL_IMPORT, **_row)
     # no name to import
     else:
         # error
         raise ValueError(
             "cannot import character name without a given name. "
             "Expected plain string of chars for field 'name'."
         )