def run(self):
        """Run method that performs all the real work"""
        # create and show the dialog
        self.dialog = PluginBuilderDialog()

        # connect the ok button to our method
        self.dialog.button_box.accepted.connect(self.validate_entries)
        self.dialog.button_box.helpRequested.connect(self.show_help)

        # show the dialog
        self.dialog.show()
        result = self.dialog.exec_()
        if result == QFileDialog.Rejected:
            return

        specification = PluginSpecification(self.dialog)
        # get the location for the plugin
        # noinspection PyCallByClass,PyTypeChecker
        self.plugin_path = QFileDialog.getExistingDirectory(
            self.dialog, 'Select the Directory for your Plugin', '.')
        if self.plugin_path == '':
            return
        else:
            if not self._get_plugin_path():
                return False

        template_dir = self._create_plugin_directory()
        self._prepare_code(specification, template_dir)
        self._prepare_help(template_dir)
        self._prepare_tests(specification)

        self._prepare_scripts()

        #resource = QFile(os.path.join(template_dir, 'resources.qrc'))
        #resource.copy(os.path.join(self.plugin_path, 'resources.qrc'))

        results_popped, template_module_name = self._prepare_results_html(
            specification)

        self._prepare_readme(specification, template_module_name)
        self._prepare_metadata(specification)
        # show the results
        results_dialog = ResultDialog()
        results_dialog.web_view.setHtml(results_popped)
        results_dialog.show()
        results_dialog.exec_()
Exemple #2
0
    def run(self):
        """Run method that performs all the real work"""
        # create and show the dialog
        self.dialog = PluginBuilderDialog()

        # get version
        cfg = ConfigParser.ConfigParser()
        cfg.read(os.path.join(self.plugin_builder_path, 'metadata.txt'))
        version = cfg.get('general', 'version')
        self.dialog.setWindowTitle('QGIS Plugin Builder - {}'.format(version))

        # connect the ok button to our method
        self.dialog.button_box.accepted.connect(self.validate_entries)
        self.dialog.button_box.helpRequested.connect(self.show_help)

        # show the dialog
        self.dialog.show()
        result = self.dialog.exec_()
        if result == QFileDialog.Rejected:
            return

        specification = PluginSpecification(self.dialog)
        # get the location for the plugin
        # noinspection PyCallByClass,PyTypeChecker
        self.plugin_path = QFileDialog.getExistingDirectory(
            self.dialog, 'Select the Directory for your Plugin', self._last_used_path())
        if self.plugin_path == '':
            return
        else:
            if not self._get_plugin_path():
                return False

        self._set_last_used_path(self.plugin_path)
        template_dir = self._create_plugin_directory()
        self._prepare_code(specification, template_dir)
        self._prepare_help(template_dir)
        self._prepare_tests(specification)

        self._prepare_scripts()

        #resource = QFile(os.path.join(template_dir, 'resources.qrc'))
        #resource.copy(os.path.join(self.plugin_path, 'resources.qrc'))

        results_popped, template_module_name = self._prepare_results_html(
            specification)

        self._prepare_readme(specification, template_module_name)
        self._prepare_metadata(specification)
        # show the results
        results_dialog = ResultDialog()
        results_dialog.web_view.setHtml(results_popped)
        results_dialog.show()
        results_dialog.exec_()
    def run(self):
        """Run method that performs all the real work"""
        # create and show the dialog
        self.dialog = PluginBuilderDialog(
            stored_output_path=self._last_used_path())

        # get version
        cfg = ConfigParser.ConfigParser()
        cfg.read(os.path.join(self.plugin_builder_path, 'metadata.txt'))
        version = cfg.get('general', 'version')
        self.dialog.setWindowTitle('QGIS Plugin Builder - {}'.format(version))

        # connect the ok button to our method
        self.dialog.button_box.helpRequested.connect(self.show_help)
        self.dialog.select_tags.clicked.connect(self._select_tags)

        # show the dialog
        self.dialog.show()
        self.dialog.adjustSize()
        result = self.dialog.exec_()
        if result == QFileDialog.Rejected:
            return

        specification = PluginSpecification(self.dialog)
        # get the location for the plugin
        # noinspection PyCallByClass,PyTypeChecker
        self.plugin_path = self.dialog.output_directory.text()

        self._set_last_used_path(self.plugin_path)
        self._create_plugin_directory()
        self.template = self.dialog.template()
        self.template_dir = os.path.join(self.template.subdir(), 'template')
        self.shared_dir = os.path.join(str(self.plugin_builder_path),
                                       'plugin_templates', 'shared')

        template_map = self.template.template_map(specification, self.dialog)
        specification.template_map.update(template_map)

        self._prepare_code(specification)
        if specification.gen_help:
            self._prepare_help()
        if specification.gen_tests:
            self._prepare_tests(specification)

        if specification.gen_scripts:
            self._prepare_scripts()

        if specification.gen_i18n:
            self._prepare_i18n()

        #resource = QFile(os.path.join(self.template_dir, 'resources.qrc'))
        #resource.copy(os.path.join(self.plugin_path, 'resources.qrc'))

        self._prepare_specific_files(specification)

        results_popped, template_module_name = self._prepare_results_html(
            specification)

        self._prepare_readme(specification, template_module_name)
        self._prepare_metadata(specification)
        # show the results
        results_dialog = ResultDialog()
        results_dialog.textBrowser.setOpenExternalLinks(True)
        results_dialog.textBrowser.setHtml(results_popped)
        results_dialog.show()
        results_dialog.exec_()
    def run(self):
        # create and show the dialog
        self.dlg = PluginBuilderDialog()
        #QMessageBox.warning(self.dlg, "Plugin Dir", self.plugin_builder_dir)
        # connect the ok button to our method
        QObject.connect(self.dlg.ui.buttonBox, SIGNAL("accepted()"), self.validate_entries)

        QObject.connect(self.dlg.ui.buttonBox, SIGNAL("helpRequested()"), self.show_help)

        # populate the left panel
        self.dlg.ui.webView.setUrl(QUrl("file:///%s/help.html" % self.plugin_builder_dir))

        # show the dialog
        self.dlg.show()
        result = self.dlg.exec_()
        # See if OK was pressed
        if result == 1:
            spec = PluginSpec(self.dlg.ui)
            # Add the date stuff to the template map
            now = datetime.date.today()
            spec.template_map['TemplateYear'] = now.year
            spec.template_map['TemplateBuildDate'] = "%i-%02i-%02i" % (now.year, now.month, now.day)

            # get the location for the plugin
            self.plugin_dir = QFileDialog.getExistingDirectory(self.dlg, "Select the Directory for your Plugin", ".")
            if self.plugin_dir == '':
                return
            else:
                while not QFileInfo(self.plugin_dir).isWritable():
                    QMessageBox.critical(None, "Error", "Directory is not writeable")
                    self.plugin_dir = QFileDialog.getExistingDirectory(self.dlg, "Select the Directory for your Plugin", ".")
                    if self.plugin_dir == '':
                        return

            # remove spaces from the plugin name
            
            # create the plugin directory using the class name

            self.plugin_dir = os.path.join(str(self.plugin_dir), str(self.dlg.ui.lineEdit_class_name.text()))
            QDir().mkdir(self.plugin_dir)
            # process the user entries
            self.populate_template(spec, 'Makefile.tmpl', 'Makefile')
            self.populate_template(spec, '__init__.tmpl', '__init__.py')
            self.populate_template(spec, 'TemplateClass.tmpl', "%s.py" % spec.class_name.lower())
            self.populate_template(spec, 'TemplateClassDialog.tmpl', "%sdialog.py" % spec.class_name.lower())
            self.populate_template(spec, 'Ui_TemplateClass.tmpl', "ui_%s.ui" % spec.class_name.lower())
            self.populate_template(spec, 'resources.tmpl', "resources.qrc")
            # copy the non-generated files to the new plugin dir
            template_dir = os.path.join(str(self.plugin_builder_dir), 'templateclass')
            icon = QFile(os.path.join(template_dir, 'icon.png'))
            icon.copy(os.path.join(self.plugin_dir, 'icon.png'))
            release_script = QFile(os.path.join(template_dir, 'release.sh'))
            release_script.copy(os.path.join(self.plugin_dir, 'release.sh'))
            plugin_upload = QFile(os.path.join(template_dir, 'plugin_upload.py'))
            plugin_upload.copy(os.path.join(self.plugin_dir, 'plugin_upload.py'))
            QFile.setPermissions(os.path.join(
                self.plugin_dir, 'plugin_upload.py'),
                QFile.ReadOwner | QFile.WriteOwner | QFile.ExeOwner | QFile.ReadUser |
                QFile.WriteUser | QFile.ExeUser | QFile.ReadGroup | QFile.ExeGroup |
                QFile.ReadOther | QFile.ExeOther)
            # create a i18n directory
            QDir().mkdir(self.plugin_dir + "/i18n")
            # Create sphinx default project for help
            QDir().mkdir(self.plugin_dir + "/help")
            QDir().mkdir(self.plugin_dir + "/help/build")
            QDir().mkdir(self.plugin_dir + "/help/source")
            QDir().mkdir(self.plugin_dir + "/help/source/_static")
            QDir().mkdir(self.plugin_dir + "/help/source/_templates")
            # copy doc makefiles
            QFile.copy(os.path.join(template_dir, "help/make.bat"),
                    os.path.join(self.plugin_dir, "help/make.bat"))
            QFile.copy(os.path.join(template_dir, "help/Makefile"),
                    os.path.join(self.plugin_dir, "help/Makefile"))
            # populate and write help files
            self.populate_template(spec, 'help/source/conf.py.tmpl', "help/source/conf.py")
            self.populate_template(spec, 'help/source/index.rst.tmpl', "help/source/index.rst")

            #resource = QFile(os.path.join(template_dir, 'resources.qrc'))
            #resource.copy(os.path.join(self.plugin_dir, 'resources.qrc'))

            # populate the results html template
            template_file = open(os.path.join(str(self.plugin_builder_dir), 'templateclass', 'results.tmpl'))
            s = template_file.read()
            template_file.close()
            template = Template(s)
            result_map = {'PluginDir': self.plugin_dir,
                    'TemplateClass': spec.template_map['TemplateClass'],
                    'templateclass': spec.template_map['templateclass'],
                    'UserPluginDir': self.user_plugin_dir}
            results_popped = template.substitute(result_map)

            # write the results info to the README HTML file
            readme = codecs.open(os.path.join(str(self.plugin_dir), 'README.html'), 'w', "utf-8")
            readme.write(results_popped)
            readme.close()

            # populate the results readme text template
            template_file = open(os.path.join(str(self.plugin_builder_dir), 'templateclass', 'readme.tmpl'))
            s = template_file.read()
            template_file.close()
            template = Template(s)
            result_map = {'PluginDir': self.plugin_dir,
                    'TemplateClass': spec.template_map['TemplateClass'],
                    'templateclass': spec.template_map['templateclass'],
                    'UserPluginDir': self.user_plugin_dir}
            popped = template.substitute(result_map)

            # write the results info to the README txt file
            readme_txt = codecs.open(os.path.join(str(self.plugin_dir), 'README.txt'), 'w', "utf-8")
            readme_txt.write(popped)
            readme_txt.close()

            # create the metadata file
            md = codecs.open(os.path.join(str(self.plugin_dir), 'metadata.txt'), 'w', "utf-8")
            metadata_comment = """# This file contains metadata for your plugin. Beginning
# with version 1.8 this is the preferred way to supply information about a
# plugin. The current method of embedding metadata in __init__.py will
# be supported until version 2.0

# This file should be included when you package your plugin.

# Mandatory items:
\n\n"""

            md.write(metadata_comment)
            md.write("[general]\n")
            md.write("name=%s\n" % spec.title)
            md.write("qgisMinimumVersion=%s\n" % spec.min_version_no)
            md.write("description=%s\n" % spec.description)
            md.write("version=%s\n" % spec.version_no)
            md.write("author=%s\n" % spec.author)
            md.write("email=%s\n\n" % spec.email_address)
            md.write("# end of mandatory metadata\n\n")
            md.write("# Optional items:\n\n")
            md.write("# Uncomment the following line and add your changelog entries:\n")
            md.write("# changelog=\n\n")
            md.write("# tags are comma separated with spaces allowed\n")
            md.write("tags=%s\n\n" % spec.tags)

            md.write("homepage=%s\n" % spec.homepage)
            md.write("tracker=%s\n" % spec.tracker)
            md.write("repository=%s\n" % spec.repository)
            md.write("icon=%s\n" % spec.icon)

            md.write("# experimental flag\n")
            md.write("experimental=%s\n\n" % spec.experimental)

            md.write("# deprecated flag (applies to the whole plugin, not just a single version\n")
            md.write("deprecated=%s\n\n" % spec.deprecated)

            md.close()


            # show the results
            res_dlg = ResultDialog()
            res_dlg.ui.webView.setHtml(results_popped)
            res_dlg.show()
            res_dlg.exec_()
    def run(self):
        """Run method that performs all the real work"""
        # create and show the dialog
        self.dialog = PluginBuilderDialog()

        # get version
        cfg = ConfigParser.ConfigParser()
        cfg.read(os.path.join(self.plugin_builder_path, 'metadata.txt'))
        version = cfg.get('general', 'version')
        self.dialog.setWindowTitle('QGIS Plugin Builder - {}'.format(version))

        # connect the ok button to our method
        self.dialog.button_box.helpRequested.connect(self.show_help)
        self.dialog.select_tags.clicked.connect(self._select_tags)

        # show the dialog
        self.dialog.show()
        self.dialog.adjustSize()
        result = self.dialog.exec_()
        if result == QFileDialog.Rejected:
            return

        specification = PluginSpecification(self.dialog)
        # get the location for the plugin
        # noinspection PyCallByClass,PyTypeChecker
        self.plugin_path = QFileDialog.getExistingDirectory(
            self.dialog, 'Select the Directory for your Plugin', self._last_used_path())
        if self.plugin_path == '':
            return
        else:
            if not self._get_plugin_path():
                return False

        self._set_last_used_path(self.plugin_path)
        self._create_plugin_directory()
        self.template = self.dialog.template()
        self.template_dir = os.path.join(
            self.template.subdir(), 'template')
        self.shared_dir = os.path.join(
            str(self.plugin_builder_path), 'plugin_templates', 'shared')

        template_map = self.template.template_map(specification, self.dialog)
        specification.template_map.update(template_map)

        self._prepare_code(specification)
        if specification.gen_help:
            self._prepare_help()
        if specification.gen_tests:
            self._prepare_tests(specification)

        if specification.gen_scripts:
            self._prepare_scripts()

        if specification.gen_i18n:
            self._prepare_i18n()

        #resource = QFile(os.path.join(self.template_dir, 'resources.qrc'))
        #resource.copy(os.path.join(self.plugin_path, 'resources.qrc'))

        self._prepare_specific_files(specification)

        results_popped, template_module_name = self._prepare_results_html(
            specification)

        self._prepare_readme(specification, template_module_name)
        self._prepare_metadata(specification)
        # show the results
        results_dialog = ResultDialog()
        results_dialog.textBrowser.setOpenExternalLinks(True)
        results_dialog.textBrowser.setHtml(results_popped)
        results_dialog.show()
        results_dialog.exec_()