├── LICENSE ├── README.md ├── pb_tool ├── MANIFEST.in ├── README.txt ├── pb_tool.py └── templates │ ├── basic.tmpl │ ├── dialog.tmpl │ ├── dialog │ ├── __init__.tmpl │ ├── module_name.tmpl │ ├── module_name_dialog.tmpl │ ├── module_name_dialog_base.ui.tmpl │ ├── readme.tmpl │ ├── resources.tmpl │ └── results.tmpl │ ├── icon.png │ └── pb_tool.tmpl ├── setup.py ├── test_pb_tool.py └── test_plugin ├── Makefile ├── README.html ├── README.txt ├── __init__.py ├── help ├── Makefile ├── make.bat └── source │ ├── conf.py │ └── index.rst ├── i18n └── af.ts ├── icon.png ├── metadata.txt ├── pb_tool.cfg ├── plugin_upload.py ├── pylintrc ├── resources.qrc ├── scripts ├── compile-strings.sh ├── run-env-linux.sh └── update-strings.sh ├── test ├── __init__.py ├── qgis_interface.py ├── tenbytenraster.asc ├── tenbytenraster.asc.aux.xml ├── tenbytenraster.keywords ├── tenbytenraster.lic ├── tenbytenraster.prj ├── tenbytenraster.qml ├── test_init.py ├── test_qgis_environment.py ├── test_resources.py ├── test_test_plugin_dialog.py ├── test_translations.py └── utilities.py ├── test_plugin.py ├── test_plugin_dialog.py └── test_plugin_dialog_base.ui /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Plugin Build Tool - pb_tool 2 | 3 | [![Homepage badge](https://img.shields.io/badge/Website-Plugin%20Builder%20Homepage-blue.svg)](https://g-sherman.github.io/plugin_build_tool/) 4 | [![PyPI version](https://badge.fury.io/py/pb_tool.svg)](https://badge.fury.io/py/pb_tool) 5 | 6 | Python command line tool for compiling and deploying QGIS plugins on all OS platforms. 7 | 8 | ## Features 9 | 10 | *pb_tool* provides commands to aid in developing, testing, and deploying 11 | a QGIS Python Plugin: 12 | 13 | * Compile resource and UI files 14 | * Deploy to your plugins directory for testing in QGIS 15 | * Create a zip file for upload to a repository 16 | * Clean both compiled and deployed files 17 | * Build and clean documentation 18 | * Build translation files 19 | * Works on Windows, OS X, and Linux 20 | 21 | ## Installation 22 | 23 | You can install the tool using pip: 24 | 25 | ```cmd 26 | python -m pip install pb_tool 27 | ``` 28 | 29 | To upgrade to the latest version, use: 30 | 31 | ```cmd 32 | python -m pip install --upgrade pb_tool 33 | ``` 34 | 35 | You can also install using easy_install: 36 | 37 | ```cmd 38 | easy_install pb_tool 39 | ``` 40 | 41 | ## Troubleshooting 42 | 43 | If you get an error about Pygments (see [#11](https://github.com/g-sherman/plugin_build_tool/issues/11)): 44 | 45 | ```python 46 | *Cannot uninstall 'Pygments'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall."* 47 | ``` 48 | 49 | Try installing using: 50 | 51 | ```cmd 52 | python -m pip install --ignore-installed Pygments pb_tool 53 | ``` 54 | 55 | For information on getting setup to develop on Windows, see: 56 | [A Quick Guide to Getting Started with PyQGIS on Windows](http://spatialgalaxy.net/2014/10/09/a-quick-guide-to-getting-started-with-pyqgis-on-windows/) 57 | 58 | ## Usage 59 | 60 | *pb_tool* requires a configuration file in order to do anything. By default, 61 | *pb_tool* assumes a file name of pb_tool.cfg, although you can specify a 62 | different one using the ``--config`` options in most commands. 63 | 64 | To display the available commands, just enter `pb_tool` on the command line: 65 | 66 | ```shell 67 | $ pb_tool 68 | Usage: pb_tool [OPTIONS] COMMAND [ARGS]... 69 | 70 | Simple Python tool to compile and deploy a QGIS plugin. For help on a 71 | command use --help after the command: pb_tool deploy --help. 72 | 73 | pb_tool requires a configuration file (default: pb_tool.cfg) that declares 74 | the files and resources used in your plugin. Plugin Builder 2.6.0 creates 75 | a config file when you generate a new plugin template. 76 | 77 | See http://g-sherman.github.io/plugin_build_tool for an example config 78 | file. You can also use the create command to generate a best-guess config 79 | file for an existing project, then tweak as needed. 80 | 81 | Bugs and enhancement requests, see: 82 | https://github.com/g-sherman/plugin_build_tool 83 | 84 | Options: 85 | --help Show this message and exit. 86 | 87 | Commands: 88 | clean Remove compiled resource and ui files 89 | clean-docs Remove the built HTML help files from the build directory 90 | compile Compile the resource and ui files 91 | config Create a config file based on source files in the current... 92 | dclean Remove the deployed plugin from the .qgis2/python/plugins... 93 | deploy Deploy the plugin to QGIS plugin directory using parameters 94 | in... 95 | doc Build HTML version of the help files using sphinx 96 | list List the contents of the configuration file 97 | translate Build translations using lrelease. 98 | update Check for update to pb_tool 99 | validate Check the pb_tool.cfg file for mandatory sections/files 100 | version Return the version of pb_tool and exit 101 | zip Package the plugin into a zip file suitable for uploading to... 102 | ``` 103 | 104 | ### Aliases 105 | 106 | Every command can be referred to by an unique alias. For example: 107 | 108 | `pb_tool de` is the same as `pb_tool deploy` 109 | 110 | Include just enough characters to make it unique. 111 | 112 | ---- 113 | 114 | ## Command Help 115 | 116 | Here is the help for a few of the commands, as reported using the --help option: 117 | 118 | ### Compile 119 | 120 | ```shell 121 | $ pb_tool compile --help 122 | Usage: pb_tool compile [OPTIONS] 123 | 124 | Compile the resource and ui files 125 | 126 | Options: 127 | --config TEXT Name of the config file to use if other than pb_tool.cfg 128 | --help Show this message and exit. 129 | ``` 130 | 131 | ### Clean Deployment 132 | 133 | ```shell 134 | $ pb_tool dclean --help 135 | Usage: pb_tool dclean [OPTIONS] 136 | 137 | Remove the deployed plugin from the .qgis2/python/plugins directory 138 | 139 | Options: 140 | --config TEXT Name of the config file to use if other than pb_tool.cfg 141 | --help Show this message and exit. 142 | ``` 143 | 144 | **Note**: Confirmation is required to remove the plugin 145 | 146 | ### Clean Compiled Files 147 | 148 | ```shell 149 | $ pb_tool clean --help 150 | Usage: pb_tool clean [OPTIONS] 151 | 152 | Remove compiled resource and ui files 153 | 154 | Options: 155 | --config TEXT Name of the config file to use if other than pb_tool.cfg 156 | --help Show this message and exit. 157 | ``` 158 | 159 | ### Deploy 160 | 161 | ```shell 162 | $ pb_tool deploy --help 163 | Usage: pb_tool deploy [OPTIONS] 164 | 165 | Deploy the plugin to QGIS plugin directory using parameters in pb_tool.cfg 166 | 167 | Options: 168 | --config TEXT Name of the config file to use if other than pb_tool.cfg 169 | -q, --quick Do a quick install without compiling ui, resource, docs, 170 | and translation files 171 | --help Show this message and exit. 172 | ``` 173 | 174 | **Note**: Confirmation is required before deploying as it removes the current version. 175 | 176 | ### Zip 177 | 178 | ```shell 179 | $ pb_tool zip --help 180 | Usage: pb_tool zip [OPTIONS] 181 | 182 | Package the plugin into a zip file suitable for uploading to the QGIS 183 | plugin repository 184 | 185 | Options: 186 | --config TEXT Name of the config file to use if other than pb_tool.cfg 187 | --help Show this message and exit. 188 | ``` 189 | 190 | **Note**: To get a clean package for upload to a repository, the zip command 191 | suggests doing a `dclean` and `deploy` first. 192 | 193 | ### Creating a Config File for an Existing Project 194 | 195 | You can create a config file for an existing plugin project by changing to the 196 | directory containing the plugin source and using `pb_tool config`: 197 | 198 | ```shell 199 | $ pb_tool config --help 200 | Usage: pb_tool config [OPTIONS] 201 | 202 | Create a config file based on source files in the current directory 203 | 204 | Options: 205 | --name TEXT Name of the config file to create if other than pb_tool.cfg 206 | --help Show this message and exit. 207 | ``` 208 | 209 | Once the config file is created you can try `deploy` to see if it 210 | picked up everything needed for your plugin---or open it in your 211 | favorite text editor to tweak it as needed. The config file is annotated 212 | and should be self-explanatory. 213 | 214 | #### Sample Config 215 | 216 | ```yaml 217 | # Sane defaults for your plugin generated by the Plugin Builder are 218 | # already set below. 219 | # 220 | # As you add Python source files and UI files to your plugin, add 221 | # them to the appropriate [files] section below. 222 | 223 | [plugin] 224 | # Name of the plugin. This is the name of the directory that will 225 | # be created in .qgis2/python/plugins 226 | name: TestPlugin 227 | 228 | [files] 229 | # Python files that should be deployed with the plugin 230 | python_files: __init__.py test_plugin.py test_plugin_dialog.py 231 | 232 | # The main dialog file that is loaded (not compiled) 233 | main_dialog: test_plugin_dialog_base.ui 234 | 235 | # Other ui files for dialogs you create (these will be compiled) 236 | compiled_ui_files: foo.ui 237 | 238 | # Resource file(s) that will be compiled 239 | resource_files: resources.qrc 240 | 241 | # Other files required for the plugin 242 | extras: icon.png metadata.txt 243 | 244 | # Other directories to be deployed with the plugin. 245 | # These must be subdirectories under the plugin directory 246 | extra_dirs: i18n 247 | 248 | # ISO code(s) for any locales (translations), separated by spaces. 249 | # Corresponding .ts files must exist in the i18n directory 250 | locales: af 251 | 252 | [help] 253 | # the built help directory that should be deployed with the plugin 254 | dir: help/build/html 255 | # the name of the directory to target in the deployed plugin 256 | target: help 257 | ``` 258 | 259 | ## Deploying 260 | 261 | ```shell 262 | Use ``pb_tool deploy`` to build your plugin and copy it 263 | to qgis2/python/plugins`` in your HOME directory: 264 | 265 | 266 | pb_tool deploy 267 | Deploying will: 268 | * Remove your currently deployed version 269 | * Compile the ui and resource files 270 | * Build the help docs 271 | * Copy everything to your .qgis2/python/plugins directory 272 | 273 | Proceed? [y/N]: y 274 | Removing plugin from /Users/gsherman/.qgis2/python/plugins/TestPlugin 275 | Deploying to /Users/gsherman/.qgis2/python/plugins/TestPlugin 276 | Compiling to make sure install is clean 277 | Skipping foo.ui (unchanged) 278 | Compiled 0 UI files 279 | Skipping resources.qrc (unchanged) 280 | Compiled 0 resource files 281 | Building the help documentation 282 | sphinx-build -b html -d build/doctrees source build/html 283 | Running Sphinx v1.2b1 284 | loading pickled environment... done 285 | building [html]: targets for 0 source files that are out of date 286 | updating environment: 0 added, 0 changed, 0 removed 287 | looking for now-outdated files... none found 288 | no targets are out of date. 289 | 290 | Build finished. The HTML pages are in build/html. 291 | Copying __init__.py 292 | Copying test_plugin.py 293 | Copying test_plugin_dialog.py 294 | Copying test_plugin_dialog_base.ui 295 | Copying foo.py 296 | Copying resources_rc.py 297 | Copying icon.png 298 | Copying metadata.txt 299 | Copying help/build/html to /Users/gsherman/.qgis2/python/plugins/TestPlugin/help 300 | ``` 301 | 302 | ## What's Missing 303 | 304 | * `pb_tool` currently doesn't support running tests for your plugin. 305 | * Probably other things we haven't thought of... 306 | 307 | ## Why 308 | 309 | Why create a build tool when `make` using the Makefile generated by the 310 | Plugin Builder plugin generally works? Here are some reasons: 311 | 312 | * `pb_tool` lets you create configs for plugins that were not created using the Plugin Builder plugin 313 | * The Makefile doesn't work completely on Windows in all cases 314 | * Writing a command line tool is fun. 315 | 316 | ## Contributing 317 | 318 | Issues and pull requests can be submitted here: 319 | 320 | * https://github.com/g-sherman/plugin_build_tool 321 | -------------------------------------------------------------------------------- /pb_tool/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include templates/basic.tmpl 2 | include templates/dialog.tmpl -------------------------------------------------------------------------------- /pb_tool/README.txt: -------------------------------------------------------------------------------- 1 | pb_tool - A Tool to Aid in QGIS Plugin Development 2 | 3 | pb_tool provides commands to deploy and publish a QGIS Python plugin. 4 | -------------------------------------------------------------------------------- /pb_tool/pb_tool.py: -------------------------------------------------------------------------------- 1 | """ 2 | /*************************************************************************** 3 | pb_tool 4 | A tool for building and deploying QGIS plugins 5 | ------------------- 6 | begin : 2014-09-24 7 | copyright : (C) 2014 by GeoApt LLC 8 | email : gsherman@geoapt.com 9 | ***************************************************************************/ 10 | 11 | /*************************************************************************** 12 | * * 13 | * This program is free software; you can redistribute it and/or modify * 14 | * it under the terms of the GNU General Public License as published by * 15 | * the Free Software Foundation; either version 2 of the License, or * 16 | * (at your option) any later version. * 17 | * * 18 | ***************************************************************************/ 19 | """ 20 | __author__ = 'gsherman' 21 | 22 | import os 23 | import sys 24 | import subprocess 25 | import shutil 26 | import errno 27 | import glob 28 | import urllib2 29 | import ConfigParser 30 | from string import Template 31 | from distutils.dir_util import copy_tree 32 | 33 | import click 34 | 35 | 36 | class AliasedGroup(click.Group): 37 | def get_command(self, ctx, cmd_name): 38 | rv = click.Group.get_command(self, ctx, cmd_name) 39 | if rv is not None: 40 | return rv 41 | matches = [x for x in self.list_commands(ctx) 42 | if x.startswith(cmd_name)] 43 | if not matches: 44 | return None 45 | elif len(matches) == 1: 46 | return click.Group.get_command(self, ctx, matches[0]) 47 | ctx.fail('Too many matches: %s' % ', '.join(sorted(matches))) 48 | 49 | 50 | # @click.group() 51 | @click.command(cls=AliasedGroup) 52 | def cli(): 53 | """Simple Python tool to compile and deploy a QGIS plugin. 54 | For help on a command use --help after the command: 55 | pb_tool deploy --help. 56 | 57 | pb_tool requires a configuration file (default: pb_tool.cfg) that 58 | declares the files and resources used in your plugin. Plugin Builder 59 | 2.6.0 creates a config file when you generate a new plugin template. 60 | 61 | See http://g-sherman.github.io/plugin_build_tool for for an example config 62 | file. You can also use the create command to generate a best-guess config 63 | file for an existing project, then tweak as needed. 64 | 65 | Bugs and enhancement requests, see: 66 | https://github.com/g-sherman/plugin_build_tool 67 | """ 68 | pass 69 | 70 | 71 | def __version(): 72 | """ return the current version and date """ 73 | # TODO update this with each release 74 | return ("2.0.2", "2018-12-26") 75 | 76 | 77 | def get_install_files(cfg): 78 | python_files = cfg.get('files', 'python_files').split() 79 | main_dialog = cfg.get('files', 'main_dialog').split() 80 | extras = cfg.get('files', 'extras').split() 81 | # merge the file lists 82 | install_files = python_files + main_dialog + compiled_ui( 83 | cfg) + compiled_resource(cfg) + extras 84 | # click.echo(install_files) 85 | return install_files 86 | 87 | 88 | @cli.command() 89 | def version(): 90 | """Return the version of pb_tool and exit""" 91 | click.echo("{} {}".format(__version()[0], __version()[1])) 92 | 93 | 94 | @cli.command() 95 | @click.option('--config_file', 96 | default='pb_tool.cfg', 97 | help='Name of the config file to use if other than pb_tool.cfg') 98 | @click.option('--plugin_path', '-p', 99 | default=None, 100 | help='Specify the directory where to deploy your plugin if not using the standard location') 101 | @click.option('--quick', '-q', 102 | is_flag=True, 103 | help='Do a quick install without compiling ui, resource, docs, \ 104 | and translation files') 105 | @click.option('--no-confirm', '-y', 106 | is_flag=True, 107 | help='Don\'t ask for confirmation to overwrite existing files') 108 | def deploy(config_file, plugin_path, quick, no_confirm): 109 | """Deploy the plugin to QGIS plugin directory using parameters in pb_tool.cfg""" 110 | deploy_files(config_file, plugin_path, quick=quick, confirm=not no_confirm) 111 | 112 | 113 | def deploy_files(config_file, plugin_path, confirm=True, quick=False): 114 | """Deploy the plugin using parameters in pb_tool.cfg""" 115 | # check for the config file 116 | if not os.path.exists(config_file): 117 | click.secho("Configuration file {0} is missing.".format(config_file), 118 | fg='red') 119 | else: 120 | cfg = get_config(config_file) 121 | if not plugin_path: 122 | plugin_path = get_plugin_directory() 123 | if not plugin_path: 124 | click.secho("Unable to determine where to deploy your plugin", fg='red') 125 | return 126 | 127 | plugin_dir = os.path.join(plugin_path, cfg.get('plugin', 'name')) 128 | 129 | if quick: 130 | click.secho("Doing quick deployment", fg='green') 131 | install_files(plugin_dir, cfg) 132 | click.secho( 133 | "Quick deployment complete---if you have problems with your" 134 | " plugin, try doing a full deploy.", fg='green') 135 | 136 | else: 137 | if confirm: 138 | print """Deploying will: 139 | * Remove your currently deployed version 140 | * Compile the ui and resource files 141 | * Build the help docs 142 | * Copy everything to your {} directory 143 | """.format(plugin_dir) 144 | 145 | proceed = click.confirm("Proceed?") 146 | else: 147 | proceed = True 148 | 149 | if proceed: 150 | # clean the deployment 151 | clean_deployment(False, config_file, plugin_dir) 152 | click.secho("Deploying to {0}".format(plugin_dir), fg='green') 153 | # compile to make sure everything is fresh 154 | click.secho('Compiling to make sure install is clean', 155 | fg='green') 156 | compile_files(cfg) 157 | build_docs() 158 | install_files(plugin_dir, cfg) 159 | 160 | 161 | def install_files(plugin_dir, cfg): 162 | errors = [] 163 | install_files = get_install_files(cfg) 164 | # make the plugin directory if it doesn't exist 165 | if not os.path.exists(plugin_dir): 166 | os.makedirs(plugin_dir) 167 | 168 | fail = False 169 | for file in install_files: 170 | click.secho("Copying {0}".format(file), fg='magenta', nl=False) 171 | try: 172 | shutil.copy(file, os.path.join(plugin_dir, file)) 173 | print "" 174 | except Exception as oops: 175 | errors.append( 176 | "Error copying files: {0}, {1}".format(file, oops.strerror)) 177 | click.echo(click.style(' ----> ERROR', fg='red')) 178 | fail = True 179 | extra_dirs = cfg.get('files', 'extra_dirs').split() 180 | # print "EXTRA DIRS: {}".format(extra_dirs) 181 | for xdir in extra_dirs: 182 | click.secho("Copying contents of {0} to {1}".format(xdir, plugin_dir), 183 | fg='magenta', 184 | nl=False) 185 | try: 186 | copy_tree(xdir, "{0}/{1}".format(plugin_dir, xdir)) 187 | print "" 188 | except Exception as oops: 189 | errors.append( 190 | "Error copying directory: {0}, {1}".format(xdir, oops.message)) 191 | click.echo(click.style(' ----> ERROR', fg='red')) 192 | fail = True 193 | help_src = cfg.get('help', 'dir') 194 | help_target = os.path.join(plugin_dir, 195 | cfg.get('help', 'target')) 196 | click.secho("Copying {0} to {1}".format(help_src, help_target), 197 | fg='magenta', 198 | nl=False) 199 | # shutil.copytree(help_src, help_target) 200 | try: 201 | copy_tree(help_src, help_target) 202 | print "" 203 | except Exception as oops: 204 | errors.append("Error copying help files: {0}, {1}".format( 205 | help_src, oops.message)) 206 | click.echo(click.style(' ----> ERROR', fg='red')) 207 | fail = True 208 | if fail: 209 | print "\nERRORS:" 210 | for error in errors: 211 | print error 212 | print "" 213 | print( 214 | "One or more files/directories specified in your config file\n" 215 | "failed to deploy---make sure they exist or if not needed remove\n" 216 | "them from the config. To ensure proper deployment, make sure your\n" 217 | "UI and resource files are compiled. Using dclean to delete the\n" 218 | "plugin before deploying may also help.") 219 | 220 | 221 | def clean_deployment(ask_first=True, config='pb_tool.cfg', plugin_dir=None): 222 | """ Remove the deployed plugin from the .qgis2/python/plugins directory 223 | """ 224 | if not plugin_dir: 225 | name = get_config(config).get('plugin', 'name') 226 | plugin_dir = os.path.join(get_plugin_directory(), name) 227 | if ask_first: 228 | proceed = click.confirm( 229 | 'Delete the deployed plugin from {0}?'.format(plugin_dir)) 230 | else: 231 | proceed = True 232 | 233 | if proceed: 234 | click.echo('Removing plugin from {0}'.format(plugin_dir)) 235 | try: 236 | shutil.rmtree(plugin_dir) 237 | return True 238 | except OSError as oops: 239 | print 'Plugin was not deleted: {0}'.format(oops.strerror) 240 | else: 241 | click.echo('Plugin was not deleted') 242 | return False 243 | 244 | 245 | @cli.command() 246 | def clean_docs(): 247 | """ 248 | Remove the built HTML help files from the build directory 249 | """ 250 | if os.path.exists('help'): 251 | click.echo('Removing built HTML from the help documentation') 252 | if sys.platform == 'win32': 253 | makeprg = 'make.bat' 254 | else: 255 | makeprg = 'make' 256 | cwd = os.getcwd() 257 | os.chdir('help') 258 | subprocess.check_call([makeprg, 'clean']) 259 | os.chdir(cwd) 260 | else: 261 | print "No help directory exists in the current directory" 262 | 263 | 264 | @cli.command() 265 | @click.option('--config', 266 | default='pb_tool.cfg', 267 | help='Name of the config file to use if other than pb_tool.cfg') 268 | def dclean(config): 269 | """ Remove the deployed plugin from the .qgis2/python/plugins directory 270 | """ 271 | clean_deployment(True, config) 272 | 273 | 274 | @cli.command() 275 | @click.option('--config', 276 | default='pb_tool.cfg', 277 | help='Name of the config file to use if other than pb_tool.cfg') 278 | def clean(config): 279 | """ Remove compiled resource and ui files 280 | """ 281 | cfg = get_config(config) 282 | files = compiled_ui(cfg) + compiled_resource(cfg) 283 | click.echo('Cleaning resource and ui files') 284 | for file in files: 285 | try: 286 | os.unlink(file) 287 | print "Deleted: {0}".format(file) 288 | except OSError as oops: 289 | print "Couldn't delete {0}: {1}".format(file, oops.strerror) 290 | 291 | 292 | @cli.command() 293 | @click.option('--config', 294 | default='pb_tool.cfg', 295 | help='Name of the config file to use if other than pb_tool.cfg') 296 | def compile(config): 297 | """ 298 | Compile the resource and ui files 299 | """ 300 | compile_files(get_config(config)) 301 | 302 | 303 | @cli.command() 304 | def doc(): 305 | """ Build HTML version of the help files using sphinx""" 306 | build_docs() 307 | 308 | 309 | def build_docs(): 310 | """ Build the docs using sphinx""" 311 | if os.path.exists('help'): 312 | click.echo('Building the help documentation') 313 | if sys.platform == 'win32': 314 | makeprg = 'make.bat' 315 | else: 316 | makeprg = 'make' 317 | cwd = os.getcwd() 318 | os.chdir('help') 319 | subprocess.check_call([makeprg, 'html']) 320 | os.chdir(cwd) 321 | else: 322 | print "No help directory exists in the current directory" 323 | 324 | 325 | @cli.command() 326 | @click.option('--config', 327 | default='pb_tool.cfg', 328 | help='Name of the config file to use if other than pb_tool.cfg') 329 | def translate(config): 330 | """ Build translations using lrelease. Locales must be specified 331 | in the config file and the corresponding .ts file must exist in 332 | the i18n directory of your plugin.""" 333 | possibles = ['lrelease', 'lrelease-qt4'] 334 | for binary in possibles: 335 | cmd = check_path(binary) 336 | if cmd: 337 | break 338 | if not cmd: 339 | print("Unable to find the lrelease command. Make sure it is installed" 340 | " and in your path.") 341 | if sys.platform == 'win32': 342 | print('You can get lrelease by installing' 343 | ' the qt4-devel package in the Libs' 344 | '\nsection of the OSGeo4W Advanced Install.') 345 | else: 346 | cfg = get_config(config) 347 | if check_cfg(cfg, 'files', 'locales'): 348 | locales = cfg.get('files', 'locales').split() 349 | if locales: 350 | for locale in locales: 351 | (name, ext) = os.path.splitext(locale) 352 | if ext != '.ts': 353 | print 'no ts extension' 354 | locale = name + '.ts' 355 | print cmd, locale 356 | subprocess.check_call([cmd, os.path.join('i18n', locale)]) 357 | else: 358 | print "No translations are specified in {0}".format(config) 359 | 360 | 361 | @cli.command() 362 | @click.option('--config', 363 | default='pb_tool.cfg', 364 | help='Name of the config file to use if other than pb_tool.cfg') 365 | @click.option( 366 | '--quick', '-q', 367 | is_flag=True, 368 | help='Do a quick packaging without dclean and deploy (plugin must have been previously deployed)' 369 | ) 370 | def zip(config_file, quick): 371 | """ Package the plugin into a zip file 372 | suitable for uploading to the QGIS 373 | plugin repository""" 374 | 375 | # check to see if we can find zip or 7z 376 | use_7z = False 377 | zip = check_path('zip') 378 | if not zip: 379 | # check for 7z 380 | zip = check_path('7z') 381 | if not zip: 382 | click.secho('zip or 7z not found. Unable to package the plugin', 383 | fg='red') 384 | click.secho('Check your path or install a zip program', fg='red') 385 | return 386 | else: 387 | use_7z = True 388 | click.secho('Found zip: %s' % zip, fg='green') 389 | 390 | name = get_config(config_file).get('plugin', 'name', fallback=None) 391 | if not quick: 392 | proceed = click.confirm('This requires a dclean and deploy first. Proceed?') 393 | if proceed: 394 | # clean_deployment(False, config) 395 | deploy_files(config_file, plugin_path=None, confirm=False) 396 | else: 397 | # Check to see if the plugin directory exists, otherwise we can't 398 | # do a quick zip 399 | if not os.path.exists(os.path.join(get_plugin_directory(), name)): 400 | # click.secho( 401 | # "You must deploy the plugin before you can package it using -q", 402 | # fg='red') 403 | # proceed = click.confirm( 404 | # 'Do you want to deploy and proceed with packaging?') 405 | # if proceed: 406 | deploy_files(config_file, plugin_path=None, confirm=False) 407 | proceed = True 408 | 409 | # confirm = click.confirm( 410 | # 'Create a packaged plugin ({0}.zip) from the deployed files?'.format(name)) 411 | # confirm = True 412 | if proceed: 413 | # delete the zip if it exists 414 | if os.path.exists('{0}.zip'.format(name)): 415 | os.unlink('{0}.zip'.format(name)) 416 | if name: 417 | cwd = os.getcwd() 418 | os.chdir(get_plugin_directory()) 419 | # click.secho("Current directory is {}".format(os.getcwd()), fg='magenta') 420 | if use_7z: 421 | subprocess.check_call( 422 | [zip, 'a', '-r', os.path.join(cwd, '{0}.zip'.format(name)), 423 | name]) 424 | else: 425 | subprocess.check_call([ 426 | zip, '-r', os.path.join(cwd, '{0}.zip'.format(name)), name 427 | ]) 428 | 429 | print( 430 | 'The {0}.zip archive has been created in the current directory'.format( 431 | name)) 432 | else: 433 | click.echo( 434 | "Your config file is missing the plugin name (name=parameter)") 435 | 436 | 437 | @cli.command() 438 | @click.option('--config_file', 439 | default='pb_tool.cfg', 440 | help='Name of the config file to use if other than pb_tool.cfg') 441 | def validate(config_file): 442 | """ 443 | Check the pb_tool.cfg file for mandatory sections/files 444 | """ 445 | valid = True 446 | cfg = get_config(config_file) 447 | if not check_cfg(cfg, 'plugin', 'name'): 448 | valid = False 449 | if not check_cfg(cfg, 'files', 'python_files'): 450 | valid = False 451 | if not check_cfg(cfg, 'files', 'main_dialog'): 452 | valid = False 453 | if not check_cfg(cfg, 'files', 'resource_files'): 454 | valid = False 455 | if not check_cfg(cfg, 'files', 'extras'): 456 | valid = False 457 | if not check_cfg(cfg, 'help', 'dir'): 458 | valid = False 459 | if not check_cfg(cfg, 'help', 'target'): 460 | valid = False 461 | 462 | click.secho("Using Python {}".format(sys.version), fg='green') 463 | if valid: 464 | click.secho( 465 | "Your {0} file is valid and contains all mandatory items".format( 466 | config_file), 467 | fg='green') 468 | else: 469 | click.secho("Your {0} file is invalid".format(config_file), fg='red') 470 | try: 471 | from PyQt5.QtCore import QStandardPaths, QDir 472 | path = QStandardPaths.standardLocations(QStandardPaths.AppDataLocation)[0] 473 | plugin_path = os.path.join(QDir.homePath(), path, 'QGIS/QGIS3/profiles/default/python/plugins') 474 | click.secho("Plugin path: {}".format(plugin_path), fg='green') 475 | except: 476 | click.secho("""Unable to determine location of your QGIS Plugin directory. 477 | Make sure your QGIS environment is setup properly for development and Python 478 | has access to the PyQt4.QtCore module.""", fg='red') 479 | 480 | zipbin = find_zip() 481 | a7z = find_7z() 482 | if zipbin: 483 | zip_utility = zipbin 484 | elif a7z: 485 | zip_utility = a7z 486 | else: 487 | zip_utility = None 488 | if not zip_utility: 489 | click.secho('zip or 7z not found. Unable to package the plugin', 490 | fg='red') 491 | click.secho('Check your path or install a zip program', fg='red') 492 | else: 493 | click.secho('Found suitable zip utility: {}'.format(zip_utility), fg='green') 494 | # check for templates - uncomment next 4 after create function is done 495 | # print(__file__) 496 | # print("Module: {}".format (sys.modules['pb_tool'])) 497 | # basic_tmpl = pkgutil.get_data('pb_tool', 'templates/basic.tmpl') 498 | # print("Read basic template: {}".format(str(basic_tmpl, 'utf-8'))) 499 | 500 | # f = open('pb_tool/templates/basic.tmpl') 501 | # if f: 502 | # print("opened basic.tmpl") 503 | # else: 504 | # print("unable to find basic.tmpl") 505 | 506 | 507 | @cli.command() 508 | @click.option('--config_file', 509 | default='pb_tool.cfg', 510 | help='Name of the config file to use if other than pb_tool.cfg') 511 | def list(config_file): 512 | """ List the contents of the configuration file """ 513 | if os.path.exists(config_file): 514 | with open(config_file) as cfg: 515 | for line in cfg: 516 | print line[:-1] 517 | else: 518 | click.secho( 519 | "There is no {0} file in the current directory".format(config_file), 520 | fg='red') 521 | click.secho("We can't do anything without it", fg='red') 522 | 523 | 524 | @cli.command() 525 | @click.option( 526 | '--name', 527 | default='pb_tool.cfg', 528 | help='Name of the config file to create if other than pb_tool.cfg') 529 | @click.option( 530 | '--package', 531 | default=None, 532 | help='Name of package (lower case). This will be used as the directory name for deployment') 533 | def xxconfig(name, package): 534 | """ 535 | Create a config file based on source files in the current directory 536 | """ 537 | click.secho("Create a config file based on source files in the current directory", fg="green") 538 | if name == 'pb_tool.cfg': 539 | click.secho("This will overwrite any existing pb_tool.cfg in the current directory", fg="red") 540 | proceed = click.confirm('Proceed?') 541 | if not proceed: 542 | return 543 | template = Template(config_template()) 544 | 545 | # get the plugin package name 546 | if not package: 547 | cfg_name = click.prompt('Name of package (lower case). This will be used as the directory name for deployment') 548 | 549 | # get the list of python files 550 | py_files = glob.glob('*.py') 551 | 552 | # guess the main dialog ui file 553 | main_dlg = glob.glob('*_dialog_base.ui') 554 | 555 | # get the other ui files 556 | other_ui = glob.glob('*.ui') 557 | # remove the main dialog file 558 | try: 559 | for ui in main_dlg: 560 | other_ui.remove(ui) 561 | except: 562 | # don't care if we didn't find it 563 | pass 564 | 565 | # get the resource files (.qrc) 566 | resources = glob.glob("*.qrc") 567 | 568 | extras = glob.glob('*.png') + glob.glob('metadata.txt') 569 | 570 | locale_list = glob.glob('i18n/*.ts') 571 | locales = [] 572 | for locale in locale_list: 573 | locales.append(os.path.basename(locale)) 574 | 575 | cfg = template.substitute(Name=cfg_name, 576 | PythonFiles=' '.join(py_files), 577 | MainDialog=' '.join(main_dlg), 578 | CompiledUiFiles=' '.join(other_ui), 579 | Resources=' '.join(resources), 580 | Extras=' '.join(extras), 581 | Locales=' '.join(locales)) 582 | 583 | fname = name 584 | if os.path.exists(fname): 585 | confirm = click.confirm('{0} exists. Overwrite?'.format(name)) 586 | if not confirm: 587 | fname = click.prompt('Enter a name for the config file:') 588 | 589 | with open(fname, 'w') as f: 590 | f.write(cfg) 591 | 592 | print "Created new config file in {0}".format(fname) 593 | 594 | 595 | @cli.command() 596 | def update(): 597 | """ Check for update to pb_tool """ 598 | try: 599 | u = urllib2.urlopen('http://geoapt.net/pb_tool/current_version.txt') 600 | version = u.read()[:-1] 601 | click.secho("Latest version is %s" % version, fg='green') 602 | # convert version numbers to int 603 | this_version = int(__version()[0].replace('.', '')) 604 | current_version = int(version.replace('.','')) 605 | 606 | if this_version == current_version: 607 | click.secho("Your version is up to date", fg='green') 608 | elif current_version > this_version: 609 | click.secho("You have Version %s" % __version()[0], fg='green') 610 | click.secho("You can upgrade by running this command:") 611 | cmd = 'pip install --upgrade pb_tool' 612 | print " %s" % cmd 613 | elif this_version > current_version: 614 | click.secho("You have development Version %s" % __version()[0], fg='green') 615 | 616 | except urllib2.URLError as uoops: 617 | click.secho("Unable to check for update.") 618 | click.secho("%s" % uoops.reason) 619 | 620 | 621 | def check_cfg(cfg, section, name): 622 | try: 623 | cfg.get(section, name) 624 | return True 625 | except ConfigParser.NoOptionError as oops: 626 | print oops.message 627 | except ConfigParser.NoSectionError: 628 | print "Missing section '{0}' when looking for option '{1}'".format( 629 | section, name) 630 | return False 631 | 632 | 633 | def get_config(config='pb_tool.cfg'): 634 | """ 635 | Read the config file pb_tools.cfg and return it 636 | """ 637 | if os.path.exists(config): 638 | cfg = ConfigParser.ConfigParser() 639 | cfg.read(config) 640 | #click.echo(cfg.sections()) 641 | return cfg 642 | else: 643 | print "There is no {0} file in the current directory".format(config) 644 | print "We can't do anything without it" 645 | sys.exit(1) 646 | 647 | 648 | def compiled_ui(cfg): 649 | #cfg = get_config(config) 650 | try: 651 | uis = cfg.get('files', 'compiled_ui_files').split() 652 | compiled = [] 653 | for ui in uis: 654 | (base, ext) = os.path.splitext(ui) 655 | compiled.append('{0}.py'.format(base)) 656 | #print "Compiled UI files: {}".format(compiled) 657 | return compiled 658 | except ConfigParser.NoSectionError as oops: 659 | print oops.message 660 | sys.exit(1) 661 | 662 | 663 | def compiled_resource(cfg): 664 | #cfg = get_config(config) 665 | try: 666 | res_files = cfg.get('files', 'resource_files').split() 667 | compiled = [] 668 | for res in res_files: 669 | (base, ext) = os.path.splitext(res) 670 | compiled.append('{0}.py'.format(base)) 671 | #print "Compiled resource files: {}".format(compiled) 672 | return compiled 673 | except ConfigParser.NoSectionError as oops: 674 | print oops.message 675 | sys.exit(1) 676 | 677 | 678 | def compile_files(cfg): 679 | # Compile all ui and resource files 680 | # TODO add changed detection 681 | #cfg = get_config(config) 682 | 683 | # check to see if we have pyuic4 684 | pyuic4 = check_path('pyuic4') 685 | 686 | if not pyuic4: 687 | print "pyuic4 is not in your path---unable to compile your ui files" 688 | else: 689 | ui_files = cfg.get('files', 'compiled_ui_files').split() 690 | ui_count = 0 691 | for ui in ui_files: 692 | if os.path.exists(ui): 693 | (base, ext) = os.path.splitext(ui) 694 | output = "{0}.py".format(base) 695 | if file_changed(ui, output): 696 | print "Compiling {0} to {1}".format(ui, output) 697 | subprocess.check_call([pyuic4, '-o', output, ui]) 698 | ui_count += 1 699 | else: 700 | print "Skipping {0} (unchanged)".format(ui) 701 | else: 702 | print "{0} does not exist---skipped".format(ui) 703 | print "Compiled {0} UI files".format(ui_count) 704 | 705 | # check to see if we have pyrcc4 706 | pyrcc4 = check_path('pyrcc4') 707 | 708 | if not pyrcc4: 709 | click.secho( 710 | "pyrcc4 is not in your path---unable to compile your resource file(s)", 711 | fg='red') 712 | else: 713 | res_files = cfg.get('files', 'resource_files').split() 714 | res_count = 0 715 | for res in res_files: 716 | if os.path.exists(res): 717 | (base, ext) = os.path.splitext(res) 718 | output = "{0}.py".format(base) 719 | if file_changed(res, output): 720 | print "Compiling {0} to {1}".format(res, output) 721 | subprocess.check_call([pyrcc4, '-o', output, res]) 722 | res_count += 1 723 | else: 724 | print "Skipping {0} (unchanged)".format(res) 725 | else: 726 | print "{0} does not exist---skipped".format(res) 727 | print "Compiled {0} resource files".format(res_count) 728 | 729 | 730 | def copy(source, destination): 731 | """Copy files recursively. 732 | 733 | Taken from: http://www.pythoncentral.io/ 734 | how-to-recursively-copy-a-directory-folder-in-python/ 735 | 736 | :param source: Source directory. 737 | :type source: str 738 | 739 | :param destination: Destination directory. 740 | :type destination: str 741 | 742 | """ 743 | try: 744 | #shutil.copytree(source, destination) 745 | copy_tree(source, destination) 746 | except OSError as e: 747 | # If the error was caused because the source wasn't a directory 748 | if e.errno == errno.ENOTDIR: 749 | shutil.copy(source, destination) 750 | else: 751 | print('Directory not copied. Error: %s' % e) 752 | 753 | 754 | def get_plugin_directory(): 755 | home = os.path.expanduser('~') 756 | qgis2 = os.path.join('.qgis2', 'python', 'plugins') 757 | return os.path.join(home, qgis2) 758 | 759 | 760 | def config_template(): 761 | """ 762 | :return: the template for a pb_tool.cfg file 763 | """ 764 | template = """# Configuration file for plugin builder tool 765 | # Sane defaults for your plugin generated by the Plugin Builder are 766 | # already set below. 767 | # 768 | # As you add Python source files and UI files to your plugin, add 769 | # them to the appropriate [files] section below. 770 | 771 | [plugin] 772 | # Name of the plugin. This is the name of the directory that will 773 | # be created in .qgis2/python/plugins 774 | name: $Name 775 | 776 | # Full path to where you want your plugin directory copied. If empty, 777 | # the QGIS default path will be used. Don't include the plugin name in 778 | # the path. 779 | plugin_path: 780 | 781 | [files] 782 | # Python files that should be deployed with the plugin 783 | python_files: $PythonFiles 784 | 785 | # The main dialog file that is loaded (not compiled) 786 | main_dialog: $MainDialog 787 | 788 | # Other ui files for your dialogs (these will be compiled) 789 | compiled_ui_files: $CompiledUiFiles 790 | 791 | # Resource file(s) that will be compiled 792 | resource_files: $Resources 793 | 794 | # Other files required for the plugin 795 | extras: $Extras 796 | 797 | # Other directories to be deployed with the plugin. 798 | # These must be subdirectories under the plugin directory 799 | extra_dirs: 800 | 801 | # ISO code(s) for any locales (translations), separated by spaces. 802 | # Corresponding .ts files must exist in the i18n directory 803 | locales: $Locales 804 | 805 | [help] 806 | # the built help directory that should be deployed with the plugin 807 | dir: help/build/html 808 | # the name of the directory to target in the deployed plugin 809 | target: help 810 | """ 811 | 812 | return template 813 | 814 | 815 | def check_path(app): 816 | """ Adapted from StackExchange: 817 | http://stackoverflow.com/questions/377017 818 | """ 819 | import os 820 | 821 | def is_exe(fpath): 822 | return os.path.exists(fpath) and os.access(fpath, os.X_OK) 823 | 824 | def ext_candidates(fpath): 825 | yield fpath 826 | for ext in os.environ.get("PATHEXT", "").split(os.pathsep): 827 | yield fpath + ext 828 | 829 | fpath, fname = os.path.split(app) 830 | if fpath: 831 | if is_exe(app): 832 | return app 833 | else: 834 | for path in os.environ["PATH"].split(os.pathsep): 835 | exe_file = os.path.join(path, app) 836 | for candidate in ext_candidates(exe_file): 837 | if is_exe(candidate): 838 | return candidate 839 | 840 | return None 841 | 842 | 843 | def file_changed(infile, outfile): 844 | try: 845 | infile_s = os.stat(infile) 846 | outfile_s = os.stat(outfile) 847 | return infile_s.st_mtime > outfile_s.st_mtime 848 | except: 849 | return True 850 | 851 | 852 | def find_zip(): 853 | # check to see if we can find zip 854 | zip = check_path('zip') 855 | return zip 856 | 857 | 858 | def find_7z(): 859 | # check for 7z 860 | zip = check_path('7z') 861 | return zip 862 | -------------------------------------------------------------------------------- /pb_tool/templates/basic.tmpl: -------------------------------------------------------------------------------- 1 | FOO 2 | -------------------------------------------------------------------------------- /pb_tool/templates/dialog.tmpl: -------------------------------------------------------------------------------- 1 | FOO 2 | -------------------------------------------------------------------------------- /pb_tool/templates/dialog/__init__.tmpl: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | ${TemplateClass} 5 | A QGIS plugin 6 | $TemplateDescription 7 | ------------------- 8 | begin : $TemplateBuildDate 9 | copyright : (C) $TemplateYear by $TemplateAuthor 10 | email : $TemplateEmail 11 | git sha : $TemplateVCSFormat 12 | ***************************************************************************/ 13 | 14 | /*************************************************************************** 15 | * * 16 | * This program is free software; you can redistribute it and/or modify * 17 | * it under the terms of the GNU General Public License as published by * 18 | * the Free Software Foundation; either version 2 of the License, or * 19 | * (at your option) any later version. * 20 | * * 21 | ***************************************************************************/ 22 | This script initializes the plugin, making it known to QGIS. 23 | """ 24 | 25 | 26 | # noinspection PyPep8Naming 27 | def classFactory(iface): # pylint: disable=invalid-name 28 | """Load ${TemplateClass} class from file ${TemplateClass}. 29 | 30 | :param iface: A QGIS interface instance. 31 | :type iface: QgsInterface 32 | """ 33 | # 34 | from .${TemplateModuleName} import ${TemplateClass} 35 | return ${TemplateClass}(iface) 36 | -------------------------------------------------------------------------------- /pb_tool/templates/dialog/module_name.tmpl: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | $TemplateClass 5 | A QGIS plugin 6 | $TemplateDescription 7 | ------------------- 8 | begin : $TemplateBuildDate 9 | git sha : $TemplateVCSFormat 10 | copyright : (C) $TemplateYear by $TemplateAuthor 11 | email : $TemplateEmail 12 | ***************************************************************************/ 13 | 14 | /*************************************************************************** 15 | * * 16 | * This program is free software; you can redistribute it and/or modify * 17 | * it under the terms of the GNU General Public License as published by * 18 | * the Free Software Foundation; either version 2 of the License, or * 19 | * (at your option) any later version. * 20 | * * 21 | ***************************************************************************/ 22 | """ 23 | from PyQt5.QtCore import QSettings, QTranslator, qVersion, QCoreApplication 24 | from PyQt5.QtGui import QIcon 25 | from PyQt5.QtWidgets import QAction 26 | 27 | # Initialize Qt resources from file resources.py 28 | from .resources import * 29 | # Import the code for the dialog 30 | from .${TemplateModuleName}_dialog import ${TemplateClass}Dialog 31 | import os.path 32 | 33 | 34 | class ${TemplateClass}: 35 | """QGIS Plugin Implementation.""" 36 | 37 | def __init__(self, iface): 38 | """Constructor. 39 | 40 | :param iface: An interface instance that will be passed to this class 41 | which provides the hook by which you can manipulate the QGIS 42 | application at run time. 43 | :type iface: QgsInterface 44 | """ 45 | # Save reference to the QGIS interface 46 | self.iface = iface 47 | # initialize plugin directory 48 | self.plugin_dir = os.path.dirname(__file__) 49 | # initialize locale 50 | locale = QSettings().value('locale/userLocale')[0:2] 51 | locale_path = os.path.join( 52 | self.plugin_dir, 53 | 'i18n', 54 | '${TemplateClass}_{}.qm'.format(locale)) 55 | 56 | if os.path.exists(locale_path): 57 | self.translator = QTranslator() 58 | self.translator.load(locale_path) 59 | 60 | if qVersion() > '4.3.3': 61 | QCoreApplication.installTranslator(self.translator) 62 | 63 | # Create the dialog (after translation) and keep reference 64 | self.dlg = ${TemplateClass}Dialog() 65 | 66 | # Declare instance attributes 67 | self.actions = [] 68 | self.menu = self.tr(u'&${TemplateTitle}') 69 | # TODO: We are going to let the user set this up in a future iteration 70 | self.toolbar = self.iface.addToolBar(u'${TemplateClass}') 71 | self.toolbar.setObjectName(u'${TemplateClass}') 72 | 73 | # noinspection PyMethodMayBeStatic 74 | def tr(self, message): 75 | """Get the translation for a string using Qt translation API. 76 | 77 | We implement this ourselves since we do not inherit QObject. 78 | 79 | :param message: String for translation. 80 | :type message: str, QString 81 | 82 | :returns: Translated version of message. 83 | :rtype: QString 84 | """ 85 | # noinspection PyTypeChecker,PyArgumentList,PyCallByClass 86 | return QCoreApplication.translate('${TemplateClass}', message) 87 | 88 | 89 | def add_action( 90 | self, 91 | icon_path, 92 | text, 93 | callback, 94 | enabled_flag=True, 95 | add_to_menu=True, 96 | add_to_toolbar=True, 97 | status_tip=None, 98 | whats_this=None, 99 | parent=None): 100 | """Add a toolbar icon to the toolbar. 101 | 102 | :param icon_path: Path to the icon for this action. Can be a resource 103 | path (e.g. ':/plugins/foo/bar.png') or a normal file system path. 104 | :type icon_path: str 105 | 106 | :param text: Text that should be shown in menu items for this action. 107 | :type text: str 108 | 109 | :param callback: Function to be called when the action is triggered. 110 | :type callback: function 111 | 112 | :param enabled_flag: A flag indicating if the action should be enabled 113 | by default. Defaults to True. 114 | :type enabled_flag: bool 115 | 116 | :param add_to_menu: Flag indicating whether the action should also 117 | be added to the menu. Defaults to True. 118 | :type add_to_menu: bool 119 | 120 | :param add_to_toolbar: Flag indicating whether the action should also 121 | be added to the toolbar. Defaults to True. 122 | :type add_to_toolbar: bool 123 | 124 | :param status_tip: Optional text to show in a popup when mouse pointer 125 | hovers over the action. 126 | :type status_tip: str 127 | 128 | :param parent: Parent widget for the new action. Defaults None. 129 | :type parent: QWidget 130 | 131 | :param whats_this: Optional text to show in the status bar when the 132 | mouse pointer hovers over the action. 133 | 134 | :returns: The action that was created. Note that the action is also 135 | added to self.actions list. 136 | :rtype: QAction 137 | """ 138 | 139 | icon = QIcon(icon_path) 140 | action = QAction(icon, text, parent) 141 | action.triggered.connect(callback) 142 | action.setEnabled(enabled_flag) 143 | 144 | if status_tip is not None: 145 | action.setStatusTip(status_tip) 146 | 147 | if whats_this is not None: 148 | action.setWhatsThis(whats_this) 149 | 150 | if add_to_toolbar: 151 | self.toolbar.addAction(action) 152 | 153 | if add_to_menu: 154 | self.iface.${TemplateMenuAddMethod}( 155 | self.menu, 156 | action) 157 | 158 | self.actions.append(action) 159 | 160 | return action 161 | 162 | def initGui(self): 163 | """Create the menu entries and toolbar icons inside the QGIS GUI.""" 164 | 165 | icon_path = ':/plugins/${TemplateModuleName}/icon.png' 166 | self.add_action( 167 | icon_path, 168 | text=self.tr(u'$TemplateMenuText'), 169 | callback=self.run, 170 | parent=self.iface.mainWindow()) 171 | 172 | 173 | def unload(self): 174 | """Removes the plugin menu item and icon from QGIS GUI.""" 175 | for action in self.actions: 176 | self.iface.${TemplateMenuRemoveMethod}( 177 | self.tr(u'&${TemplateTitle}'), 178 | action) 179 | self.iface.removeToolBarIcon(action) 180 | # remove the toolbar 181 | del self.toolbar 182 | 183 | 184 | def run(self): 185 | """Run method that performs all the real work""" 186 | # show the dialog 187 | self.dlg.show() 188 | # Run the dialog event loop 189 | result = self.dlg.exec_() 190 | # See if OK was pressed 191 | if result: 192 | # Do something useful here - delete the line containing pass and 193 | # substitute with your code. 194 | pass 195 | -------------------------------------------------------------------------------- /pb_tool/templates/dialog/module_name_dialog.tmpl: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | ${TemplateClass}Dialog 5 | A QGIS plugin 6 | $TemplateDescription 7 | ------------------- 8 | begin : $TemplateBuildDate 9 | git sha : $TemplateVCSFormat 10 | copyright : (C) $TemplateYear by $TemplateAuthor 11 | email : $TemplateEmail 12 | ***************************************************************************/ 13 | 14 | /*************************************************************************** 15 | * * 16 | * This program is free software; you can redistribute it and/or modify * 17 | * it under the terms of the GNU General Public License as published by * 18 | * the Free Software Foundation; either version 2 of the License, or * 19 | * (at your option) any later version. * 20 | * * 21 | ***************************************************************************/ 22 | """ 23 | 24 | import os 25 | 26 | from PyQt5 import uic 27 | from PyQt5 import QtWidgets 28 | 29 | FORM_CLASS, _ = uic.loadUiType(os.path.join( 30 | os.path.dirname(__file__), '${TemplateModuleName}_dialog_base.ui')) 31 | 32 | 33 | class ${TemplateClass}Dialog(QtWidgets.QDialog, FORM_CLASS): 34 | def __init__(self, parent=None): 35 | """Constructor.""" 36 | super(${TemplateClass}Dialog, self).__init__(parent) 37 | # Set up the user interface from Designer. 38 | # After setupUI you can access any designer object by doing 39 | # self., and you can use autoconnect slots - see 40 | # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html 41 | # #widgets-and-dialogs-with-auto-connect 42 | self.setupUi(self) 43 | -------------------------------------------------------------------------------- /pb_tool/templates/dialog/module_name_dialog_base.ui.tmpl: -------------------------------------------------------------------------------- 1 | 2 | ${TemplateClass}DialogBase 3 | 4 | 5 | 6 | 0 7 | 0 8 | 400 9 | 300 10 | 11 | 12 | 13 | ${TemplateTitle} 14 | 15 | 16 | 17 | 18 | 30 19 | 240 20 | 341 21 | 32 22 | 23 | 24 | 25 | Qt::Horizontal 26 | 27 | 28 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 29 | 30 | 31 | 32 | 33 | 34 | 35 | button_box 36 | accepted() 37 | ${TemplateClass}DialogBase 38 | accept() 39 | 40 | 41 | 248 42 | 254 43 | 44 | 45 | 157 46 | 274 47 | 48 | 49 | 50 | 51 | button_box 52 | rejected() 53 | ${TemplateClass}DialogBase 54 | reject() 55 | 56 | 57 | 316 58 | 260 59 | 60 | 61 | 286 62 | 274 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /pb_tool/templates/dialog/readme.tmpl: -------------------------------------------------------------------------------- 1 | Plugin Builder Results 2 | 3 | Your plugin ${TemplateClass} was created in: 4 | ${PluginDir} 5 | 6 | Your QGIS plugin directory is located at: 7 | ${UserPluginDir} 8 | 9 | What's Next: 10 | 11 | * Copy the entire directory containing your new plugin to the QGIS plugin 12 | directory 13 | 14 | * Compile the resources file using pyrcc4 15 | 16 | * Run the tests (``make test``) 17 | 18 | * Test the plugin by enabling it in the QGIS plugin manager 19 | 20 | * Customize it by editing the implementation file: ``${TemplateModuleName}.py`` 21 | 22 | * Create your own custom icon, replacing the default icon.png 23 | 24 | * Modify your user interface by opening ${TemplateClass}.ui in Qt Designer 25 | 26 | * You can use the Makefile to compile your Ui and resource files when 27 | you make changes. This requires GNU make (gmake) 28 | 29 | For more information, see the PyQGIS Developer Cookbook at: 30 | http://www.qgis.org/pyqgis-cookbook/index.html 31 | 32 | (C) 2011-2014 GeoApt LLC - geoapt.com 33 | Git revision : $TemplateVCSFormat 34 | -------------------------------------------------------------------------------- /pb_tool/templates/dialog/resources.tmpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | icon.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /pb_tool/templates/dialog/results.tmpl: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Plugin Builder Results

4 | 5 | Congratulations! You just built a plugin for QGIS!

6 | 7 |
8 | Your plugin ${TemplateClass} was created in:
9 |   ${PluginDir} 10 |

11 | Your QGIS plugin directory is located at:
12 |   ${UserPluginDir} 13 |

14 |

What's Next

15 |
    16 |
  1. In your plugin directory, compile the resources file using pyrcc5 (simply run make if you have automake or use pb_tool) 17 |
  2. Test the generated sources using make test (or run tests from your IDE) 18 |
  3. Copy the entire directory containing your new plugin to the QGIS plugin directory (see Notes below) 19 |
  4. Test the plugin by enabling it in the QGIS plugin manager 20 |
  5. Customize it by editing the implementation file ${TemplateModuleName}.py 21 |
  6. Create your own custom icon, replacing the default icon.png 22 |
  7. Modify your user interface by opening ${TemplateModuleName}_dialog_base.ui in Qt Designer 23 |
24 | Notes: 25 |
    26 |
  • You can use the Makefile to compile and deploy when you 27 | make changes. This requires GNU make (gmake). The Makefile is ready to use, however you 28 | will have to edit it to add addional Python source files, dialogs, and translations. 29 |
  • You can also use pb_tool to compile and deploy your plugin. Tweak the pb_tool.cfg file included with your plugin as you add files. Install pb_tool using 30 | pip or easy_install. See http://loc8.cc/pb_tool for more information. 31 |
32 |
33 |
34 |

35 | For information on writing PyQGIS code, see http://loc8.cc/pyqgis_resources for a list of resources. 36 |

37 |
38 |

39 | ©2011-2017 GeoApt LLC - geoapt.com 40 |

41 | 42 | 43 | -------------------------------------------------------------------------------- /pb_tool/templates/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-sherman/plugin_build_tool/b3a6fef19d64d37b4d8040fe2bb4d8bf55c57d2d/pb_tool/templates/icon.png -------------------------------------------------------------------------------- /pb_tool/templates/pb_tool.tmpl: -------------------------------------------------------------------------------- 1 | #/*************************************************************************** 2 | # ${TemplateClass} 3 | # 4 | # Configuration file for plugin builder tool (pb_tool) 5 | # ------------------- 6 | # begin : $TemplateBuildDate 7 | # copyright : (C) $TemplateYear by $TemplateAuthor 8 | # email : $TemplateEmail 9 | # ***************************************************************************/ 10 | # 11 | #/*************************************************************************** 12 | # * * 13 | # * This program is free software; you can redistribute it and/or modify * 14 | # * it under the terms of the GNU General Public License as published by * 15 | # * the Free Software Foundation; either version 2 of the License, or * 16 | # * (at your option) any later version. * 17 | # * * 18 | # ***************************************************************************/ 19 | # 20 | # 21 | # You can install pb_tool using: 22 | # pip install http://geoapt.net/files/pb_tool.zip 23 | # 24 | # Consider doing your development (and install of pb_tool) in a virtualenv. 25 | # 26 | # For details on setting up and using pb_tool, see: 27 | # http://g-sherman.github.io/plugin_build_tool/ 28 | # 29 | # Issues and pull requests here: 30 | # https://github.com/g-sherman/plugin_build_tool: 31 | # 32 | # Sane defaults for your plugin generated by the Plugin Builder are 33 | # already set below. 34 | # 35 | # As you add Python source files and UI files to your plugin, add 36 | # them to the appropriate [files] section below. 37 | 38 | [plugin] 39 | # Name of the plugin. This is the name of the directory that will 40 | # be created in .qgis2/python/plugins 41 | name: ${TemplateModuleName} 42 | 43 | [files] 44 | # Python files that should be deployed with the plugin 45 | python_files: __init__.py ${TemplateModuleName}.py ${TemplatePyFiles} 46 | 47 | # The main dialog file that is loaded (not compiled) 48 | main_dialog: ${TemplateUiFiles} 49 | 50 | # Other ui files for dialogs you create (these will be compiled) 51 | compiled_ui_files: 52 | 53 | # Resource file(s) that will be compiled 54 | resource_files: ${TemplateQrcFiles} 55 | 56 | # Other files required for the plugin 57 | extras: metadata.txt ${TemplateExtraFiles} 58 | 59 | # Other directories to be deployed with the plugin. 60 | # These must be subdirectories under the plugin directory 61 | extra_dirs: 62 | 63 | # ISO code(s) for any locales (translations), separated by spaces. 64 | # Corresponding .ts files must exist in the i18n directory 65 | locales: 66 | 67 | [help] 68 | # the built help directory that should be deployed with the plugin 69 | dir: help/build/html 70 | # the name of the directory to target in the deployed plugin 71 | target: help 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """ 2 | /*************************************************************************** 3 | setup.py for pb_tool 4 | A tool for building and deploying QGIS plugins 5 | ------------------- 6 | begin : 2014-09-24 7 | copyright : (C) 2014 by GeoApt LLC 8 | email : gsherman@geoapt.com 9 | ***************************************************************************/ 10 | 11 | /*************************************************************************** 12 | * * 13 | * This program is free software; you can redistribute it and/or modify * 14 | * it under the terms of the GNU General Public License as published by * 15 | * the Free Software Foundation; either version 2 of the License, or * 16 | * (at your option) any later version. * 17 | * * 18 | ***************************************************************************/ 19 | """ 20 | 21 | from setuptools import * 22 | 23 | setup( 24 | name='pb_tool', 25 | version='2.0.2', 26 | description='A tool to aid in QGIS Python plugin development', 27 | long_description='pb_tool provides commands to deploy and publish a QGIS Python plugin.', 28 | url='http://g-sherman.github.io/plugin_build_tool', 29 | author='Gary Sherman', 30 | author_email='gsherman@geoapt.com', 31 | maintainer='Gary Sherman', 32 | maintainer_email='gsherman@geoapt.com', 33 | license='GPL2', 34 | classifiers=[ 35 | 'Development Status :: 5 - Production/Stable', 36 | 'Operating System :: OS Independent', 37 | 'Intended Audience :: Developers', 38 | 'Topic :: Software Development :: Build Tools', 39 | 'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)', 40 | 'Topic :: Scientific/Engineering :: GIS'], 41 | keywords='QGIS PyQGIS', 42 | platforms=['Linux', 'Windows', 'OS X'], 43 | packages=find_packages(), 44 | package_data={'pb_tool': ['templates/*.tmpl']}, 45 | include_package_data=True, 46 | py_modules=['pb_tool'], 47 | install_requires=[ 48 | 'Click', 49 | 'Sphinx', 50 | 'colorama' 51 | ], 52 | entry_points=''' 53 | [console_scripts] 54 | pb_tool=pb_tool.pb_tool:cli 55 | pbt=pb_tool.pb_tool:cli 56 | ''', 57 | ) 58 | -------------------------------------------------------------------------------- /test_pb_tool.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import click 4 | from click.testing import CliRunner 5 | from pb_tool import pb_tool 6 | 7 | runner = CliRunner() 8 | 9 | 10 | def test_validate(): 11 | result = runner.invoke(pb_tool.cli, ['validate']) 12 | assert result.exit_code == 0 13 | 14 | 15 | 16 | def test_clean(): 17 | result = runner.invoke(pb_tool.cli, ['clean']) 18 | assert result.exit_code == 0 19 | 20 | 21 | def test_cleandocs(): 22 | result = runner.invoke(pb_tool.cli, ['clean_docs']) 23 | assert result.exit_code == 0 24 | 25 | 26 | def test_config(): 27 | result = runner.invoke(pb_tool.cli, 28 | ['config', '--name', 'test_from_pytest.cfg', 29 | '--package', 'testname'], input='y\n') 30 | assert result.exit_code == 0 31 | assert os.path.exists('test_from_pytest.cfg') == 1 32 | 33 | 34 | def test_create(): 35 | result = runner.invoke(pb_tool.cli, ['create']) 36 | assert result.exit_code == 0 37 | 38 | 39 | def test_doc(): 40 | result = runner.invoke(pb_tool.cli, ['doc']) 41 | assert result.exit_code == 0 42 | 43 | 44 | def test_deploy(): 45 | result = runner.invoke(pb_tool.cli, ['deploy'], input='y\n') 46 | assert result.exit_code == 0 47 | 48 | def test_zip(): 49 | result = runner.invoke(pb_tool.cli, ['zip'], input='y\n') 50 | assert result.exit_code == 0 51 | #assert os.path.exists(os.path.join(os.getcwd(), 'whereami.zip')) 52 | 53 | 54 | def test_dclean(): 55 | result = runner.invoke(pb_tool.cli, ['dclean'], input='y\n') 56 | assert result.exit_code == 0 57 | 58 | 59 | # def test_help(): 60 | # result = runner.invoke(pb_tool.cli, ['help']) 61 | # assert result.exit_code == 0 62 | 63 | 64 | def test_list(): 65 | result = runner.invoke(pb_tool.cli, ['list']) 66 | assert result.exit_code == 0 67 | 68 | 69 | def test_validate(): 70 | result = runner.invoke(pb_tool.cli, ['validate']) 71 | assert result.exit_code == 0 72 | 73 | def test_update(): 74 | result = runner.invoke(pb_tool.cli, ['update']) 75 | assert result.exit_code == 0 76 | 77 | def test_version(): 78 | result = runner.invoke(pb_tool.cli, ['version']) 79 | assert result.exit_code == 0 80 | 81 | def test_compile(): 82 | result = runner.invoke(pb_tool.cli, ['compile']) 83 | assert result.exit_code == 0 84 | 85 | # results.append("Command validate failed: {}".format(result.output)) 86 | #print("testing validate: {}".format(result)) 87 | #result = runner.invoke(pb_tool.cli, ['zip', '-q']) 88 | #print("testing zip: {}".format(result)) 89 | #print results 90 | -------------------------------------------------------------------------------- /test_plugin/Makefile: -------------------------------------------------------------------------------- 1 | #/*************************************************************************** 2 | # TestPlugin 3 | # 4 | # Test Plugin 5 | # ------------------- 6 | # begin : 2014-10-06 7 | # git sha : $Format:%H$ 8 | # copyright : (C) 2014 by GeoApt LLC 9 | # email : gsherman@geoapt.com 10 | # ***************************************************************************/ 11 | # 12 | #/*************************************************************************** 13 | # * * 14 | # * This program is free software; you can redistribute it and/or modify * 15 | # * it under the terms of the GNU General Public License as published by * 16 | # * the Free Software Foundation; either version 2 of the License, or * 17 | # * (at your option) any later version. * 18 | # * * 19 | # ***************************************************************************/ 20 | 21 | ################################################# 22 | # Edit the following to match your sources lists 23 | ################################################# 24 | 25 | 26 | #Add iso code for any locales you want to support here (space separated) 27 | # default is no locales 28 | # LOCALES = af 29 | LOCALES = 30 | 31 | # If locales are enabled, set the name of the lrelease binary on your system. If 32 | # you have trouble compiling the translations, you may have to specify the full path to 33 | # lrelease 34 | #LRELEASE = lrelease 35 | #LRELEASE = lrelease-qt4 36 | 37 | 38 | # translation 39 | SOURCES = \ 40 | __init__.py \ 41 | test_plugin.py \ 42 | test_plugin_dialog.py 43 | 44 | PLUGINNAME = TestPlugin 45 | 46 | PY_FILES = \ 47 | test_plugin.py \ 48 | test_plugin_dialog.py \ 49 | __init__.py 50 | 51 | UI_FILES = test_plugin_dialog_base.ui 52 | 53 | EXTRAS = icon.png metadata.txt 54 | 55 | COMPILED_RESOURCE_FILES = resources_rc.py 56 | 57 | PEP8EXCLUDE=pydev,resources_rc.py,conf.py,third_party,ui 58 | 59 | 60 | ################################################# 61 | # Normally you would not need to edit below here 62 | ################################################# 63 | 64 | HELP = help/build/html 65 | 66 | PLUGIN_UPLOAD = $(c)/plugin_upload.py 67 | 68 | RESOURCE_SRC=$(shell grep '^ *@@g;s/.*>//g' | tr '\n' ' ') 69 | 70 | QGISDIR=.qgis2 71 | 72 | default: compile 73 | 74 | compile: $(COMPILED_RESOURCE_FILES) 75 | 76 | %_rc.py : %.qrc $(RESOURCES_SRC) 77 | pyrcc4 -o $*_rc.py $< 78 | 79 | %.qm : %.ts 80 | $(LRELEASE) $< 81 | 82 | test: compile transcompile 83 | @echo 84 | @echo "----------------------" 85 | @echo "Regression Test Suite" 86 | @echo "----------------------" 87 | 88 | @# Preceding dash means that make will continue in case of errors 89 | @-export PYTHONPATH=`pwd`:$(PYTHONPATH); \ 90 | export QGIS_DEBUG=0; \ 91 | export QGIS_LOG_FILE=/dev/null; \ 92 | nosetests -v --with-id --with-coverage --cover-package=. \ 93 | 3>&1 1>&2 2>&3 3>&- || true 94 | @echo "----------------------" 95 | @echo "If you get a 'no module named qgis.core error, try sourcing" 96 | @echo "the helper script we have provided first then run make test." 97 | @echo "e.g. source run-env-linux.sh ; make test" 98 | @echo "----------------------" 99 | 100 | deploy: compile doc transcompile 101 | @echo 102 | @echo "------------------------------------------" 103 | @echo "Deploying plugin to your .qgis2 directory." 104 | @echo "------------------------------------------" 105 | # The deploy target only works on unix like operating system where 106 | # the Python plugin directory is located at: 107 | # $HOME/$(QGISDIR)/python/plugins 108 | mkdir -p $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 109 | cp -vf $(PY_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 110 | cp -vf $(UI_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 111 | cp -vf $(COMPILED_RESOURCE_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 112 | cp -vf $(EXTRAS) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 113 | cp -vfr i18n $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 114 | cp -vfr $(HELP) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)/help 115 | 116 | # The dclean target removes compiled python files from plugin directory 117 | # also deletes any .git entry 118 | dclean: 119 | @echo 120 | @echo "-----------------------------------" 121 | @echo "Removing any compiled python files." 122 | @echo "-----------------------------------" 123 | find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname "*.pyc" -delete 124 | find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname ".git" -prune -exec rm -Rf {} \; 125 | 126 | 127 | derase: 128 | @echo 129 | @echo "-------------------------" 130 | @echo "Removing deployed plugin." 131 | @echo "-------------------------" 132 | rm -Rf $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 133 | 134 | zip: deploy dclean 135 | @echo 136 | @echo "---------------------------" 137 | @echo "Creating plugin zip bundle." 138 | @echo "---------------------------" 139 | # The zip target deploys the plugin and creates a zip file with the deployed 140 | # content. You can then upload the zip file on http://plugins.qgis.org 141 | rm -f $(PLUGINNAME).zip 142 | cd $(HOME)/$(QGISDIR)/python/plugins; zip -9r $(CURDIR)/$(PLUGINNAME).zip $(PLUGINNAME) 143 | 144 | package: compile 145 | # Create a zip package of the plugin named $(PLUGINNAME).zip. 146 | # This requires use of git (your plugin development directory must be a 147 | # git repository). 148 | # To use, pass a valid commit or tag as follows: 149 | # make package VERSION=Version_0.3.2 150 | @echo 151 | @echo "------------------------------------" 152 | @echo "Exporting plugin to zip package. " 153 | @echo "------------------------------------" 154 | rm -f $(PLUGINNAME).zip 155 | git archive --prefix=$(PLUGINNAME)/ -o $(PLUGINNAME).zip $(VERSION) 156 | echo "Created package: $(PLUGINNAME).zip" 157 | 158 | upload: zip 159 | @echo 160 | @echo "-------------------------------------" 161 | @echo "Uploading plugin to QGIS Plugin repo." 162 | @echo "-------------------------------------" 163 | $(PLUGIN_UPLOAD) $(PLUGINNAME).zip 164 | 165 | transup: 166 | @echo 167 | @echo "------------------------------------------------" 168 | @echo "Updating translation files with any new strings." 169 | @echo "------------------------------------------------" 170 | @chmod +x scripts/update-strings.sh 171 | @scripts/update-strings.sh $(LOCALES) 172 | 173 | transcompile: 174 | @echo 175 | @echo "----------------------------------------" 176 | @echo "Compiled translation files to .qm files." 177 | @echo "----------------------------------------" 178 | @chmod +x scripts/compile-strings.sh 179 | @scripts/compile-strings.sh $(LRELEASE) $(LOCALES) 180 | 181 | transclean: 182 | @echo 183 | @echo "------------------------------------" 184 | @echo "Removing compiled translation files." 185 | @echo "------------------------------------" 186 | rm -f i18n/*.qm 187 | 188 | clean: 189 | @echo 190 | @echo "------------------------------------" 191 | @echo "Removing uic and rcc generated files" 192 | @echo "------------------------------------" 193 | rm $(COMPILED_UI_FILES) $(COMPILED_RESOURCE_FILES) 194 | 195 | doc: 196 | @echo 197 | @echo "------------------------------------" 198 | @echo "Building documentation using sphinx." 199 | @echo "------------------------------------" 200 | cd help; make html 201 | 202 | pylint: 203 | @echo 204 | @echo "-----------------" 205 | @echo "Pylint violations" 206 | @echo "-----------------" 207 | @pylint --reports=n --rcfile=pylintrc . || true 208 | @echo 209 | @echo "----------------------" 210 | @echo "If you get a 'no module named qgis.core' error, try sourcing" 211 | @echo "the helper script we have provided first then run make pylint." 212 | @echo "e.g. source run-env-linux.sh ; make pylint" 213 | @echo "----------------------" 214 | 215 | 216 | # Run pep8 style checking 217 | #http://pypi.python.org/pypi/pep8 218 | pep8: 219 | @echo 220 | @echo "-----------" 221 | @echo "PEP8 issues" 222 | @echo "-----------" 223 | @pep8 --repeat --ignore=E203,E121,E122,E123,E124,E125,E126,E127,E128 --exclude $(PEP8EXCLUDE) . || true 224 | @echo "-----------" 225 | @echo "Ignored in PEP8 check:" 226 | @echo $(PEP8EXCLUDE) 227 | -------------------------------------------------------------------------------- /test_plugin/README.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Plugin Builder Results

4 | 5 | Congratulations! You just built a plugin for QGIS! Easy eh?

6 | 7 |
8 | Your plugin TestPlugin was created in:
9 |   /Users/gsherman/development/qgis_plugins/TestPlugin 10 |

11 | Your QGIS plugin directory is located at:
12 |   /Users/gsherman/.qgis2/python/plugins 13 |

14 |

What's Next

15 |
    16 |
  1. Copy the entire directory containing your new plugin to the QGIS plugin directory 17 |
  2. Compile the resources file using pyrcc4 (simply run make if you have automake) 18 |
  3. Test the generated sources using make test (or run tests from your IDE) 19 |
  4. Test the plugin by enabling it in the QGIS plugin manager 20 |
  5. Customize it by editing the implementation file test_plugin.py 21 |
  6. Create your own custom icon, replacing the default icon.png 22 |
  7. Modify your user interface by opening test_plugin_dialog_base.ui in Qt Designer 23 |
  8. You can use the Makefile to compile and deploy when you 24 | make changes. This requires GNU make (gmake). The Makefile is ready to use, however you 25 | will have to edit it to add addional Python source files, dialogs, and translations. 26 | 27 |
28 |
29 |

30 | For more information, see the PyQGIS Developer Cookbook at: 31 | http://www.qgis.org/pyqgis-cookbook/index.html. 32 |

33 |
34 | GeoApt LLC 35 | ©2011-2014 GeoApt LLC - geoapt.com 36 | 37 | 38 | -------------------------------------------------------------------------------- /test_plugin/README.txt: -------------------------------------------------------------------------------- 1 | Plugin Builder Results 2 | 3 | Your plugin TestPlugin was created in: 4 | /Users/gsherman/development/qgis_plugins/TestPlugin 5 | 6 | Your QGIS plugin directory is located at: 7 | /Users/gsherman/.qgis2/python/plugins 8 | 9 | What's Next: 10 | 11 | * Copy the entire directory containing your new plugin to the QGIS plugin 12 | directory 13 | 14 | * Compile the resources file using pyrcc4 15 | 16 | * Run the tests (``make test``) 17 | 18 | * Test the plugin by enabling it in the QGIS plugin manager 19 | 20 | * Customize it by editing the implementation file: ``test_plugin.py`` 21 | 22 | * Create your own custom icon, replacing the default icon.png 23 | 24 | * Modify your user interface by opening TestPlugin.ui in Qt Designer 25 | 26 | * You can use the Makefile to compile your Ui and resource files when 27 | you make changes. This requires GNU make (gmake) 28 | 29 | For more information, see the PyQGIS Developer Cookbook at: 30 | http://www.qgis.org/pyqgis-cookbook/index.html 31 | 32 | (C) 2011-2014 GeoApt LLC - geoapt.com 33 | Git revision : $Format:%H$ 34 | -------------------------------------------------------------------------------- /test_plugin/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | TestPlugin 5 | A QGIS plugin 6 | Test Plugin 7 | ------------------- 8 | begin : 2014-10-06 9 | copyright : (C) 2014 by GeoApt LLC 10 | email : gsherman@geoapt.com 11 | git sha : $Format:%H$ 12 | ***************************************************************************/ 13 | 14 | /*************************************************************************** 15 | * * 16 | * This program is free software; you can redistribute it and/or modify * 17 | * it under the terms of the GNU General Public License as published by * 18 | * the Free Software Foundation; either version 2 of the License, or * 19 | * (at your option) any later version. * 20 | * * 21 | ***************************************************************************/ 22 | This script initializes the plugin, making it known to QGIS. 23 | """ 24 | 25 | 26 | # noinspection PyPep8Naming 27 | def classFactory(iface): # pylint: disable=invalid-name 28 | """Load TestPlugin class from file TestPlugin. 29 | 30 | :param iface: A QGIS interface instance. 31 | :type iface: QgsInterface 32 | """ 33 | # 34 | from .test_plugin import TestPlugin 35 | return TestPlugin(iface) 36 | -------------------------------------------------------------------------------- /test_plugin/help/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 14 | 15 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest 16 | 17 | help: 18 | @echo "Please use \`make ' where is one of" 19 | @echo " html to make standalone HTML files" 20 | @echo " dirhtml to make HTML files named index.html in directories" 21 | @echo " singlehtml to make a single large HTML file" 22 | @echo " pickle to make pickle files" 23 | @echo " json to make JSON files" 24 | @echo " htmlhelp to make HTML files and a HTML help project" 25 | @echo " qthelp to make HTML files and a qthelp project" 26 | @echo " devhelp to make HTML files and a Devhelp project" 27 | @echo " epub to make an epub" 28 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 29 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 30 | @echo " text to make text files" 31 | @echo " man to make manual pages" 32 | @echo " changes to make an overview of all changed/added/deprecated items" 33 | @echo " linkcheck to check all external links for integrity" 34 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 35 | 36 | clean: 37 | -rm -rf $(BUILDDIR)/* 38 | 39 | html: 40 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 41 | @echo 42 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 43 | 44 | dirhtml: 45 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 48 | 49 | singlehtml: 50 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 51 | @echo 52 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 53 | 54 | pickle: 55 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 56 | @echo 57 | @echo "Build finished; now you can process the pickle files." 58 | 59 | json: 60 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 61 | @echo 62 | @echo "Build finished; now you can process the JSON files." 63 | 64 | htmlhelp: 65 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 66 | @echo 67 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 68 | ".hhp project file in $(BUILDDIR)/htmlhelp." 69 | 70 | qthelp: 71 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 72 | @echo 73 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 74 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 75 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/template_class.qhcp" 76 | @echo "To view the help file:" 77 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/template_class.qhc" 78 | 79 | devhelp: 80 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 81 | @echo 82 | @echo "Build finished." 83 | @echo "To view the help file:" 84 | @echo "# mkdir -p $$HOME/.local/share/devhelp/template_class" 85 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/template_class" 86 | @echo "# devhelp" 87 | 88 | epub: 89 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 90 | @echo 91 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 92 | 93 | latex: 94 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 95 | @echo 96 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 97 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 98 | "(use \`make latexpdf' here to do that automatically)." 99 | 100 | latexpdf: 101 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 102 | @echo "Running LaTeX files through pdflatex..." 103 | make -C $(BUILDDIR)/latex all-pdf 104 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 105 | 106 | text: 107 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 108 | @echo 109 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 110 | 111 | man: 112 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 113 | @echo 114 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 115 | 116 | changes: 117 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 118 | @echo 119 | @echo "The overview file is in $(BUILDDIR)/changes." 120 | 121 | linkcheck: 122 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 123 | @echo 124 | @echo "Link check complete; look for any errors in the above output " \ 125 | "or in $(BUILDDIR)/linkcheck/output.txt." 126 | 127 | doctest: 128 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 129 | @echo "Testing of doctests in the sources finished, look at the " \ 130 | "results in $(BUILDDIR)/doctest/output.txt." 131 | -------------------------------------------------------------------------------- /test_plugin/help/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source 10 | if NOT "%PAPER%" == "" ( 11 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 12 | ) 13 | 14 | if "%1" == "" goto help 15 | 16 | if "%1" == "help" ( 17 | :help 18 | echo.Please use `make ^` where ^ is one of 19 | echo. html to make standalone HTML files 20 | echo. dirhtml to make HTML files named index.html in directories 21 | echo. singlehtml to make a single large HTML file 22 | echo. pickle to make pickle files 23 | echo. json to make JSON files 24 | echo. htmlhelp to make HTML files and a HTML help project 25 | echo. qthelp to make HTML files and a qthelp project 26 | echo. devhelp to make HTML files and a Devhelp project 27 | echo. epub to make an epub 28 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 29 | echo. text to make text files 30 | echo. man to make manual pages 31 | echo. changes to make an overview over all changed/added/deprecated items 32 | echo. linkcheck to check all external links for integrity 33 | echo. doctest to run all doctests embedded in the documentation if enabled 34 | goto end 35 | ) 36 | 37 | if "%1" == "clean" ( 38 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 39 | del /q /s %BUILDDIR%\* 40 | goto end 41 | ) 42 | 43 | if "%1" == "html" ( 44 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 45 | echo. 46 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 47 | goto end 48 | ) 49 | 50 | if "%1" == "dirhtml" ( 51 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 52 | echo. 53 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 54 | goto end 55 | ) 56 | 57 | if "%1" == "singlehtml" ( 58 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 59 | echo. 60 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 61 | goto end 62 | ) 63 | 64 | if "%1" == "pickle" ( 65 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 66 | echo. 67 | echo.Build finished; now you can process the pickle files. 68 | goto end 69 | ) 70 | 71 | if "%1" == "json" ( 72 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 73 | echo. 74 | echo.Build finished; now you can process the JSON files. 75 | goto end 76 | ) 77 | 78 | if "%1" == "htmlhelp" ( 79 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 80 | echo. 81 | echo.Build finished; now you can run HTML Help Workshop with the ^ 82 | .hhp project file in %BUILDDIR%/htmlhelp. 83 | goto end 84 | ) 85 | 86 | if "%1" == "qthelp" ( 87 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 88 | echo. 89 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 90 | .qhcp project file in %BUILDDIR%/qthelp, like this: 91 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\template_class.qhcp 92 | echo.To view the help file: 93 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\template_class.ghc 94 | goto end 95 | ) 96 | 97 | if "%1" == "devhelp" ( 98 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 99 | echo. 100 | echo.Build finished. 101 | goto end 102 | ) 103 | 104 | if "%1" == "epub" ( 105 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 106 | echo. 107 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 108 | goto end 109 | ) 110 | 111 | if "%1" == "latex" ( 112 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 113 | echo. 114 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 115 | goto end 116 | ) 117 | 118 | if "%1" == "text" ( 119 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 120 | echo. 121 | echo.Build finished. The text files are in %BUILDDIR%/text. 122 | goto end 123 | ) 124 | 125 | if "%1" == "man" ( 126 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 127 | echo. 128 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 129 | goto end 130 | ) 131 | 132 | if "%1" == "changes" ( 133 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 134 | echo. 135 | echo.The overview file is in %BUILDDIR%/changes. 136 | goto end 137 | ) 138 | 139 | if "%1" == "linkcheck" ( 140 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 141 | echo. 142 | echo.Link check complete; look for any errors in the above output ^ 143 | or in %BUILDDIR%/linkcheck/output.txt. 144 | goto end 145 | ) 146 | 147 | if "%1" == "doctest" ( 148 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 149 | echo. 150 | echo.Testing of doctests in the sources finished, look at the ^ 151 | results in %BUILDDIR%/doctest/output.txt. 152 | goto end 153 | ) 154 | 155 | :end 156 | -------------------------------------------------------------------------------- /test_plugin/help/source/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # TestPlugin documentation build configuration file, created by 4 | # sphinx-quickstart on Sun Feb 12 17:11:03 2012. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | #sys.path.insert(0, os.path.abspath('.')) 20 | 21 | # -- General configuration ----------------------------------------------------- 22 | 23 | # If your documentation needs a minimal Sphinx version, state it here. 24 | #needs_sphinx = '1.0' 25 | 26 | # Add any Sphinx extension module names here, as strings. They can be extensions 27 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 28 | extensions = ['sphinx.ext.todo', 'sphinx.ext.pngmath', 'sphinx.ext.viewcode'] 29 | 30 | # Add any paths that contain templates here, relative to this directory. 31 | templates_path = ['_templates'] 32 | 33 | # The suffix of source filenames. 34 | source_suffix = '.rst' 35 | 36 | # The encoding of source files. 37 | #source_encoding = 'utf-8-sig' 38 | 39 | # The master toctree document. 40 | master_doc = 'index' 41 | 42 | # General information about the project. 43 | project = u'TestPlugin' 44 | copyright = u'2013, GeoApt LLC' 45 | 46 | # The version info for the project you're documenting, acts as replacement for 47 | # |version| and |release|, also used in various other places throughout the 48 | # built documents. 49 | # 50 | # The short X.Y version. 51 | version = '0.1' 52 | # The full version, including alpha/beta/rc tags. 53 | release = '0.1' 54 | 55 | # The language for content autogenerated by Sphinx. Refer to documentation 56 | # for a list of supported languages. 57 | #language = None 58 | 59 | # There are two options for replacing |today|: either, you set today to some 60 | # non-false value, then it is used: 61 | #today = '' 62 | # Else, today_fmt is used as the format for a strftime call. 63 | #today_fmt = '%B %d, %Y' 64 | 65 | # List of patterns, relative to source directory, that match files and 66 | # directories to ignore when looking for source files. 67 | exclude_patterns = [] 68 | 69 | # The reST default role (used for this markup: `text`) to use for all documents. 70 | #default_role = None 71 | 72 | # If true, '()' will be appended to :func: etc. cross-reference text. 73 | #add_function_parentheses = True 74 | 75 | # If true, the current module name will be prepended to all description 76 | # unit titles (such as .. function::). 77 | #add_TemplateModuleNames = True 78 | 79 | # If true, sectionauthor and moduleauthor directives will be shown in the 80 | # output. They are ignored by default. 81 | #show_authors = False 82 | 83 | # The name of the Pygments (syntax highlighting) style to use. 84 | pygments_style = 'sphinx' 85 | 86 | # A list of ignored prefixes for module index sorting. 87 | #modindex_common_prefix = [] 88 | 89 | 90 | # -- Options for HTML output --------------------------------------------------- 91 | 92 | # The theme to use for HTML and HTML Help pages. See the documentation for 93 | # a list of builtin themes. 94 | html_theme = 'default' 95 | 96 | # Theme options are theme-specific and customize the look and feel of a theme 97 | # further. For a list of options available for each theme, see the 98 | # documentation. 99 | #html_theme_options = {} 100 | 101 | # Add any paths that contain custom themes here, relative to this directory. 102 | #html_theme_path = [] 103 | 104 | # The name for this set of Sphinx documents. If None, it defaults to 105 | # " v documentation". 106 | #html_title = None 107 | 108 | # A shorter title for the navigation bar. Default is the same as html_title. 109 | #html_short_title = None 110 | 111 | # The name of an image file (relative to this directory) to place at the top 112 | # of the sidebar. 113 | #html_logo = None 114 | 115 | # The name of an image file (within the static path) to use as favicon of the 116 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 117 | # pixels large. 118 | #html_favicon = None 119 | 120 | # Add any paths that contain custom static files (such as style sheets) here, 121 | # relative to this directory. They are copied after the builtin static files, 122 | # so a file named "default.css" will overwrite the builtin "default.css". 123 | html_static_path = ['_static'] 124 | 125 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 126 | # using the given strftime format. 127 | #html_last_updated_fmt = '%b %d, %Y' 128 | 129 | # If true, SmartyPants will be used to convert quotes and dashes to 130 | # typographically correct entities. 131 | #html_use_smartypants = True 132 | 133 | # Custom sidebar templates, maps document names to template names. 134 | #html_sidebars = {} 135 | 136 | # Additional templates that should be rendered to pages, maps page names to 137 | # template names. 138 | #html_additional_pages = {} 139 | 140 | # If false, no module index is generated. 141 | #html_domain_indices = True 142 | 143 | # If false, no index is generated. 144 | #html_use_index = True 145 | 146 | # If true, the index is split into individual pages for each letter. 147 | #html_split_index = False 148 | 149 | # If true, links to the reST sources are added to the pages. 150 | #html_show_sourcelink = True 151 | 152 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 153 | #html_show_sphinx = True 154 | 155 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 156 | #html_show_copyright = True 157 | 158 | # If true, an OpenSearch description file will be output, and all pages will 159 | # contain a tag referring to it. The value of this option must be the 160 | # base URL from which the finished HTML is served. 161 | #html_use_opensearch = '' 162 | 163 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 164 | #html_file_suffix = None 165 | 166 | # Output file base name for HTML help builder. 167 | htmlhelp_basename = 'TemplateClassdoc' 168 | 169 | 170 | # -- Options for LaTeX output -------------------------------------------------- 171 | 172 | # The paper size ('letter' or 'a4'). 173 | #latex_paper_size = 'letter' 174 | 175 | # The font size ('10pt', '11pt' or '12pt'). 176 | #latex_font_size = '10pt' 177 | 178 | # Grouping the document tree into LaTeX files. List of tuples 179 | # (source start file, target name, title, author, documentclass [howto/manual]). 180 | latex_documents = [ 181 | ('index', 'TestPlugin.tex', u'TestPlugin Documentation', 182 | u'GeoApt LLC', 'manual'), 183 | ] 184 | 185 | # The name of an image file (relative to this directory) to place at the top of 186 | # the title page. 187 | #latex_logo = None 188 | 189 | # For "manual" documents, if this is true, then toplevel headings are parts, 190 | # not chapters. 191 | #latex_use_parts = False 192 | 193 | # If true, show page references after internal links. 194 | #latex_show_pagerefs = False 195 | 196 | # If true, show URL addresses after external links. 197 | #latex_show_urls = False 198 | 199 | # Additional stuff for the LaTeX preamble. 200 | #latex_preamble = '' 201 | 202 | # Documents to append as an appendix to all manuals. 203 | #latex_appendices = [] 204 | 205 | # If false, no module index is generated. 206 | #latex_domain_indices = True 207 | 208 | 209 | # -- Options for manual page output -------------------------------------------- 210 | 211 | # One entry per manual page. List of tuples 212 | # (source start file, name, description, authors, manual section). 213 | man_pages = [ 214 | ('index', 'TemplateClass', u'TestPlugin Documentation', 215 | [u'GeoApt LLC'], 1) 216 | ] 217 | -------------------------------------------------------------------------------- /test_plugin/help/source/index.rst: -------------------------------------------------------------------------------- 1 | .. TestPlugin documentation master file, created by 2 | sphinx-quickstart on Sun Feb 12 17:11:03 2012. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to TestPlugin's documentation! 7 | ============================================ 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | Indices and tables 15 | ================== 16 | 17 | * :ref:`genindex` 18 | * :ref:`modindex` 19 | * :ref:`search` 20 | 21 | -------------------------------------------------------------------------------- /test_plugin/i18n/af.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @default 5 | 6 | 7 | Good morning 8 | Goeie more 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test_plugin/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-sherman/plugin_build_tool/b3a6fef19d64d37b4d8040fe2bb4d8bf55c57d2d/test_plugin/icon.png -------------------------------------------------------------------------------- /test_plugin/metadata.txt: -------------------------------------------------------------------------------- 1 | # This file contains metadata for your plugin. Since 2 | # version 2.0 of QGIS this is the proper way to supply 3 | # information about a plugin. The old method of 4 | # embedding metadata in __init__.py will 5 | # is no longer supported since version 2.0. 6 | 7 | # This file should be included when you package your plugin.# Mandatory items: 8 | 9 | [general] 10 | name=Test Plugin 11 | qgisMinimumVersion=2.0 12 | description=Test Plugin 13 | version=0.1 14 | author=GeoApt LLC 15 | email=gsherman@geoapt.com 16 | 17 | # End of mandatory metadata 18 | 19 | # Optional items: 20 | 21 | # Uncomment the following line and add your changelog: 22 | # changelog= 23 | 24 | # Tags are comma separated with spaces allowed 25 | tags= 26 | 27 | homepage= 28 | tracker= 29 | repository= 30 | icon=icon.png 31 | # experimental flag 32 | experimental=False 33 | 34 | # deprecated flag (applies to the whole plugin, not just a single version) 35 | deprecated=False 36 | 37 | -------------------------------------------------------------------------------- /test_plugin/pb_tool.cfg: -------------------------------------------------------------------------------- 1 | #/*************************************************************************** 2 | # TestPlugin 3 | # 4 | # Configuration file for plugin builder tool (pb_tool) 5 | # ------------------- 6 | # begin : 2014-10-06 7 | # copyright : (C) 2014 by GeoApt LLC 8 | # email : gsherman@geoapt.com 9 | # ***************************************************************************/ 10 | # 11 | #/*************************************************************************** 12 | # * * 13 | # * This program is free software; you can redistribute it and/or modify * 14 | # * it under the terms of the GNU General Public License as published by * 15 | # * the Free Software Foundation; either version 2 of the License, or * 16 | # * (at your option) any later version. * 17 | # * * 18 | # ***************************************************************************/ 19 | # 20 | # 21 | # You can install pb_tool using: 22 | # pip install http://geoapt.net/files/pb_tool.zip 23 | # 24 | # Consider doing your development (and install of pb_tool) in a virtualenv. 25 | # 26 | # For details on setting up and using pb_tool, see: 27 | # http://spatialgalaxy.net/qgis-plugin-development-with-pb_tool 28 | # 29 | # Issues and pull requests here: 30 | # https://github.com/g-sherman/plugin_build_tool: 31 | # 32 | # Sane defaults for your plugin generated by the Plugin Builder are 33 | # already set below. 34 | # 35 | # As you add Python source files and UI files to your plugin, add 36 | # them to the appropriate [files] section below. 37 | 38 | [plugin] 39 | # Name of the plugin. This is the name of the directory that will 40 | # be created in .qgis2/python/plugins 41 | name: TestPlugin 42 | 43 | [files] 44 | # Python files that should be deployed with the plugin 45 | python_files: __init__.py test_plugin.py test_plugin_dialog.py 46 | 47 | # The main dialog file that is loaded (not compiled) 48 | main_dialog: test_plugin_dialog_base.ui 49 | 50 | # Other ui files for dialogs you create (these will be compiled) 51 | compiled_ui_files: foo.ui 52 | 53 | # Resource file(s) that will be compiled 54 | resource_files: resources.qrc 55 | 56 | # Other files required for the plugin 57 | extras: icon.png metadata.txt 58 | 59 | # Other directories to be deployed with the plugin. 60 | # These must be subdirectories under the plugin directory 61 | extra_dirs: 62 | 63 | # ISO code(s) for any locales (translations), separated by spaces. 64 | # Corresponding .ts files must exist in the i18n directory 65 | locales: af 66 | 67 | [help] 68 | # the built help directory that should be deployed with the plugin 69 | dir: help/build/html 70 | # the name of the directory to target in the deployed plugin 71 | target: help 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /test_plugin/plugin_upload.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | """This script uploads a plugin package on the server. 4 | Authors: A. Pasotti, V. Picavet 5 | git sha : $TemplateVCSFormat 6 | """ 7 | 8 | import sys 9 | import getpass 10 | import xmlrpclib 11 | from optparse import OptionParser 12 | 13 | # Configuration 14 | PROTOCOL = 'http' 15 | SERVER = 'plugins.qgis.org' 16 | PORT = '80' 17 | ENDPOINT = '/plugins/RPC2/' 18 | VERBOSE = False 19 | 20 | 21 | def main(parameters, arguments): 22 | """Main entry point. 23 | 24 | :param parameters: Command line parameters. 25 | :param arguments: Command line arguments. 26 | """ 27 | address = "%s://%s:%s@%s:%s%s" % ( 28 | PROTOCOL, 29 | parameters.username, 30 | parameters.password, 31 | parameters.server, 32 | parameters.port, 33 | ENDPOINT) 34 | print "Connecting to: %s" % hide_password(address) 35 | 36 | server = xmlrpclib.ServerProxy(address, verbose=VERBOSE) 37 | 38 | try: 39 | plugin_id, version_id = server.plugin.upload( 40 | xmlrpclib.Binary(open(arguments[0]).read())) 41 | print "Plugin ID: %s" % plugin_id 42 | print "Version ID: %s" % version_id 43 | except xmlrpclib.ProtocolError, err: 44 | print "A protocol error occurred" 45 | print "URL: %s" % hide_password(err.url, 0) 46 | print "HTTP/HTTPS headers: %s" % err.headers 47 | print "Error code: %d" % err.errcode 48 | print "Error message: %s" % err.errmsg 49 | except xmlrpclib.Fault, err: 50 | print "A fault occurred" 51 | print "Fault code: %d" % err.faultCode 52 | print "Fault string: %s" % err.faultString 53 | 54 | 55 | def hide_password(url, start=6): 56 | """Returns the http url with password part replaced with '*'. 57 | 58 | :param url: URL to upload the plugin to. 59 | :type url: str 60 | 61 | :param start: Position of start of password. 62 | :type start: int 63 | """ 64 | start_position = url.find(':', start) + 1 65 | end_position = url.find('@') 66 | return "%s%s%s" % ( 67 | url[:start_position], 68 | '*' * (end_position - start_position), 69 | url[end_position:]) 70 | 71 | 72 | if __name__ == "__main__": 73 | parser = OptionParser(usage="%prog [options] plugin.zip") 74 | parser.add_option( 75 | "-w", "--password", dest="password", 76 | help="Password for plugin site", metavar="******") 77 | parser.add_option( 78 | "-u", "--username", dest="username", 79 | help="Username of plugin site", metavar="user") 80 | parser.add_option( 81 | "-p", "--port", dest="port", 82 | help="Server port to connect to", metavar="80") 83 | parser.add_option( 84 | "-s", "--server", dest="server", 85 | help="Specify server name", metavar="plugins.qgis.org") 86 | options, args = parser.parse_args() 87 | if len(args) != 1: 88 | print "Please specify zip file.\n" 89 | parser.print_help() 90 | sys.exit(1) 91 | if not options.server: 92 | options.server = SERVER 93 | if not options.port: 94 | options.port = PORT 95 | if not options.username: 96 | # interactive mode 97 | username = getpass.getuser() 98 | print "Please enter user name [%s] :" % username, 99 | res = raw_input() 100 | if res != "": 101 | options.username = res 102 | else: 103 | options.username = username 104 | if not options.password: 105 | # interactive mode 106 | options.password = getpass.getpass() 107 | main(options, args) 108 | -------------------------------------------------------------------------------- /test_plugin/pylintrc: -------------------------------------------------------------------------------- 1 | [MASTER] 2 | 3 | # Specify a configuration file. 4 | #rcfile= 5 | 6 | # Python code to execute, usually for sys.path manipulation such as 7 | # pygtk.require(). 8 | #init-hook= 9 | 10 | # Profiled execution. 11 | profile=no 12 | 13 | # Add files or directories to the blacklist. They should be base names, not 14 | # paths. 15 | ignore=CVS 16 | 17 | # Pickle collected data for later comparisons. 18 | persistent=yes 19 | 20 | # List of plugins (as comma separated values of python modules names) to load, 21 | # usually to register additional checkers. 22 | load-plugins= 23 | 24 | 25 | [MESSAGES CONTROL] 26 | 27 | # Enable the message, report, category or checker with the given id(s). You can 28 | # either give multiple identifier separated by comma (,) or put this option 29 | # multiple time. See also the "--disable" option for examples. 30 | #enable= 31 | 32 | # Disable the message, report, category or checker with the given id(s). You 33 | # can either give multiple identifiers separated by comma (,) or put this 34 | # option multiple times (only on the command line, not in the configuration 35 | # file where it should appear only once).You can also use "--disable=all" to 36 | # disable everything first and then reenable specific checks. For example, if 37 | # you want to run only the similarities checker, you can use "--disable=all 38 | # --enable=similarities". If you want to run only the classes checker, but have 39 | # no Warning level messages displayed, use"--disable=all --enable=classes 40 | # --disable=W" 41 | # see http://stackoverflow.com/questions/21487025/pylint-locally-defined-disables-still-give-warnings-how-to-suppress-them 42 | disable=locally-disabled,C0103 43 | 44 | 45 | [REPORTS] 46 | 47 | # Set the output format. Available formats are text, parseable, colorized, msvs 48 | # (visual studio) and html. You can also give a reporter class, eg 49 | # mypackage.mymodule.MyReporterClass. 50 | output-format=text 51 | 52 | # Put messages in a separate file for each module / package specified on the 53 | # command line instead of printing them on stdout. Reports (if any) will be 54 | # written in a file name "pylint_global.[txt|html]". 55 | files-output=no 56 | 57 | # Tells whether to display a full report or only the messages 58 | reports=yes 59 | 60 | # Python expression which should return a note less than 10 (10 is the highest 61 | # note). You have access to the variables errors warning, statement which 62 | # respectively contain the number of errors / warnings messages and the total 63 | # number of statements analyzed. This is used by the global evaluation report 64 | # (RP0004). 65 | evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) 66 | 67 | # Add a comment according to your evaluation note. This is used by the global 68 | # evaluation report (RP0004). 69 | comment=no 70 | 71 | # Template used to display messages. This is a python new-style format string 72 | # used to format the message information. See doc for all details 73 | #msg-template= 74 | 75 | 76 | [BASIC] 77 | 78 | # Required attributes for module, separated by a comma 79 | required-attributes= 80 | 81 | # List of builtins function names that should not be used, separated by a comma 82 | bad-functions=map,filter,apply,input 83 | 84 | # Regular expression which should only match correct module names 85 | module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ 86 | 87 | # Regular expression which should only match correct module level names 88 | const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ 89 | 90 | # Regular expression which should only match correct class names 91 | class-rgx=[A-Z_][a-zA-Z0-9]+$ 92 | 93 | # Regular expression which should only match correct function names 94 | function-rgx=[a-z_][a-z0-9_]{2,30}$ 95 | 96 | # Regular expression which should only match correct method names 97 | method-rgx=[a-z_][a-z0-9_]{2,30}$ 98 | 99 | # Regular expression which should only match correct instance attribute names 100 | attr-rgx=[a-z_][a-z0-9_]{2,30}$ 101 | 102 | # Regular expression which should only match correct argument names 103 | argument-rgx=[a-z_][a-z0-9_]{2,30}$ 104 | 105 | # Regular expression which should only match correct variable names 106 | variable-rgx=[a-z_][a-z0-9_]{2,30}$ 107 | 108 | # Regular expression which should only match correct attribute names in class 109 | # bodies 110 | class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ 111 | 112 | # Regular expression which should only match correct list comprehension / 113 | # generator expression variable names 114 | inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ 115 | 116 | # Good variable names which should always be accepted, separated by a comma 117 | good-names=i,j,k,ex,Run,_ 118 | 119 | # Bad variable names which should always be refused, separated by a comma 120 | bad-names=foo,bar,baz,toto,tutu,tata 121 | 122 | # Regular expression which should only match function or class names that do 123 | # not require a docstring. 124 | no-docstring-rgx=__.*__ 125 | 126 | # Minimum line length for functions/classes that require docstrings, shorter 127 | # ones are exempt. 128 | docstring-min-length=-1 129 | 130 | 131 | [MISCELLANEOUS] 132 | 133 | # List of note tags to take in consideration, separated by a comma. 134 | notes=FIXME,XXX,TODO 135 | 136 | 137 | [TYPECHECK] 138 | 139 | # Tells whether missing members accessed in mixin class should be ignored. A 140 | # mixin class is detected if its name ends with "mixin" (case insensitive). 141 | ignore-mixin-members=yes 142 | 143 | # List of classes names for which member attributes should not be checked 144 | # (useful for classes with attributes dynamically set). 145 | ignored-classes=SQLObject 146 | 147 | # When zope mode is activated, add a predefined set of Zope acquired attributes 148 | # to generated-members. 149 | zope=no 150 | 151 | # List of members which are set dynamically and missed by pylint inference 152 | # system, and so shouldn't trigger E0201 when accessed. Python regular 153 | # expressions are accepted. 154 | generated-members=REQUEST,acl_users,aq_parent 155 | 156 | 157 | [VARIABLES] 158 | 159 | # Tells whether we should check for unused import in __init__ files. 160 | init-import=no 161 | 162 | # A regular expression matching the beginning of the name of dummy variables 163 | # (i.e. not used). 164 | dummy-variables-rgx=_$|dummy 165 | 166 | # List of additional names supposed to be defined in builtins. Remember that 167 | # you should avoid to define new builtins when possible. 168 | additional-builtins= 169 | 170 | 171 | [FORMAT] 172 | 173 | # Maximum number of characters on a single line. 174 | max-line-length=80 175 | 176 | # Regexp for a line that is allowed to be longer than the limit. 177 | ignore-long-lines=^\s*(# )??$ 178 | 179 | # Allow the body of an if to be on the same line as the test if there is no 180 | # else. 181 | single-line-if-stmt=no 182 | 183 | # List of optional constructs for which whitespace checking is disabled 184 | no-space-check=trailing-comma,dict-separator 185 | 186 | # Maximum number of lines in a module 187 | max-module-lines=1000 188 | 189 | # String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 190 | # tab). 191 | indent-string=' ' 192 | 193 | 194 | [SIMILARITIES] 195 | 196 | # Minimum lines number of a similarity. 197 | min-similarity-lines=4 198 | 199 | # Ignore comments when computing similarities. 200 | ignore-comments=yes 201 | 202 | # Ignore docstrings when computing similarities. 203 | ignore-docstrings=yes 204 | 205 | # Ignore imports when computing similarities. 206 | ignore-imports=no 207 | 208 | 209 | [IMPORTS] 210 | 211 | # Deprecated modules which should not be used, separated by a comma 212 | deprecated-modules=regsub,TERMIOS,Bastion,rexec 213 | 214 | # Create a graph of every (i.e. internal and external) dependencies in the 215 | # given file (report RP0402 must not be disabled) 216 | import-graph= 217 | 218 | # Create a graph of external dependencies in the given file (report RP0402 must 219 | # not be disabled) 220 | ext-import-graph= 221 | 222 | # Create a graph of internal dependencies in the given file (report RP0402 must 223 | # not be disabled) 224 | int-import-graph= 225 | 226 | 227 | [DESIGN] 228 | 229 | # Maximum number of arguments for function / method 230 | max-args=5 231 | 232 | # Argument names that match this expression will be ignored. Default to name 233 | # with leading underscore 234 | ignored-argument-names=_.* 235 | 236 | # Maximum number of locals for function / method body 237 | max-locals=15 238 | 239 | # Maximum number of return / yield for function / method body 240 | max-returns=6 241 | 242 | # Maximum number of branch for function / method body 243 | max-branches=12 244 | 245 | # Maximum number of statements in function / method body 246 | max-statements=50 247 | 248 | # Maximum number of parents for a class (see R0901). 249 | max-parents=7 250 | 251 | # Maximum number of attributes for a class (see R0902). 252 | max-attributes=7 253 | 254 | # Minimum number of public methods for a class (see R0903). 255 | min-public-methods=2 256 | 257 | # Maximum number of public methods for a class (see R0904). 258 | max-public-methods=20 259 | 260 | 261 | [CLASSES] 262 | 263 | # List of interface methods to ignore, separated by a comma. This is used for 264 | # instance to not check methods defines in Zope's Interface base class. 265 | ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by 266 | 267 | # List of method names used to declare (i.e. assign) instance attributes. 268 | defining-attr-methods=__init__,__new__,setUp 269 | 270 | # List of valid names for the first argument in a class method. 271 | valid-classmethod-first-arg=cls 272 | 273 | # List of valid names for the first argument in a metaclass class method. 274 | valid-metaclass-classmethod-first-arg=mcs 275 | 276 | 277 | [EXCEPTIONS] 278 | 279 | # Exceptions that will emit a warning when being caught. Defaults to 280 | # "Exception" 281 | overgeneral-exceptions=Exception 282 | -------------------------------------------------------------------------------- /test_plugin/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | icon.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /test_plugin/scripts/compile-strings.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | LRELEASE=$1 3 | LOCALES=$2 4 | 5 | 6 | for LOCALE in ${LOCALES} 7 | do 8 | echo "Processing: ${LOCALE}.ts" 9 | # Note we don't use pylupdate with qt .pro file approach as it is flakey 10 | # about what is made available. 11 | $LRELEASE i18n/${LOCALE}.ts 12 | done 13 | -------------------------------------------------------------------------------- /test_plugin/scripts/run-env-linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | QGIS_PREFIX_PATH=/usr/local/qgis-2.0 4 | if [ -n "$1" ]; then 5 | QGIS_PREFIX_PATH=$1 6 | fi 7 | 8 | echo ${QGIS_PREFIX_PATH} 9 | 10 | 11 | export QGIS_PREFIX_PATH=${QGIS_PREFIX_PATH} 12 | export QGIS_PATH=${QGIS_PREFIX_PATH} 13 | export LD_LIBRARY_PATH=${QGIS_PREFIX_PATH}/lib 14 | export PYTHONPATH=${QGIS_PREFIX_PATH}/share/qgis/python:${QGIS_PREFIX_PATH}/share/qgis/python/plugins:${PYTHONPATH} 15 | 16 | echo "QGIS PATH: $QGIS_PREFIX_PATH" 17 | export QGIS_DEBUG=0 18 | export QGIS_LOG_FILE=/tmp/inasafe/realtime/logs/qgis.log 19 | 20 | export PATH=${QGIS_PREFIX_PATH}/bin:$PATH 21 | 22 | echo "This script is intended to be sourced to set up your shell to" 23 | echo "use a QGIS 2.0 built in $QGIS_PREFIX_PATH" 24 | echo 25 | echo "To use it do:" 26 | echo "source $BASH_SOURCE /your/optional/install/path" 27 | echo 28 | echo "Then use the make file supplied here e.g. make guitest" 29 | -------------------------------------------------------------------------------- /test_plugin/scripts/update-strings.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | LOCALES=$* 3 | 4 | # Get newest .py files so we don't update strings unnecessarily 5 | 6 | CHANGED_FILES=0 7 | PYTHON_FILES=`find . -regex ".*\(ui\|py\)$" -type f` 8 | for PYTHON_FILE in $PYTHON_FILES 9 | do 10 | CHANGED=$(stat -c %Y $PYTHON_FILE) 11 | if [ ${CHANGED} -gt ${CHANGED_FILES} ] 12 | then 13 | CHANGED_FILES=${CHANGED} 14 | fi 15 | done 16 | 17 | # Qt translation stuff 18 | # for .ts file 19 | UPDATE=false 20 | for LOCALE in ${LOCALES} 21 | do 22 | TRANSLATION_FILE="i18n/$LOCALE.ts" 23 | if [ ! -f ${TRANSLATION_FILE} ] 24 | then 25 | # Force translation string collection as we have a new language file 26 | touch ${TRANSLATION_FILE} 27 | UPDATE=true 28 | break 29 | fi 30 | 31 | MODIFICATION_TIME=$(stat -c %Y ${TRANSLATION_FILE}) 32 | if [ ${CHANGED_FILES} -gt ${MODIFICATION_TIME} ] 33 | then 34 | # Force translation string collection as a .py file has been updated 35 | UPDATE=true 36 | break 37 | fi 38 | done 39 | 40 | if [ ${UPDATE} == true ] 41 | # retrieve all python files 42 | then 43 | print ${PYTHON_FILES} 44 | # update .ts 45 | echo "Please provide translations by editing the translation files below:" 46 | for LOCALE in ${LOCALES} 47 | do 48 | echo "i18n/"${LOCALE}".ts" 49 | # Note we don't use pylupdate with qt .pro file approach as it is flakey 50 | # about what is made available. 51 | pylupdate4 -noobsolete ${PYTHON_FILES} -ts i18n/${LOCALE}.ts 52 | done 53 | else 54 | echo "No need to edit any translation files (.ts) because no python files" 55 | echo "has been updated since the last update translation. " 56 | fi 57 | -------------------------------------------------------------------------------- /test_plugin/test/__init__.py: -------------------------------------------------------------------------------- 1 | # import qgis libs so that ve set the correct sip api version 2 | import qgis # pylint: disable=W0611 # NOQA -------------------------------------------------------------------------------- /test_plugin/test/qgis_interface.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """QGIS plugin implementation. 3 | 4 | .. note:: This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 2 of the License, or 7 | (at your option) any later version. 8 | 9 | .. note:: This source code was copied from the 'postgis viewer' application 10 | with original authors: 11 | Copyright (c) 2010 by Ivan Mincik, ivan.mincik@gista.sk 12 | Copyright (c) 2011 German Carrillo, geotux_tuxman@linuxmail.org 13 | Copyright (c) 2014 Tim Sutton, tim@linfiniti.com 14 | 15 | """ 16 | 17 | __author__ = 'tim@linfiniti.com' 18 | __revision__ = '$Format:%H$' 19 | __date__ = '10/01/2011' 20 | __copyright__ = ( 21 | 'Copyright (c) 2010 by Ivan Mincik, ivan.mincik@gista.sk and ' 22 | 'Copyright (c) 2011 German Carrillo, geotux_tuxman@linuxmail.org' 23 | 'Copyright (c) 2014 Tim Sutton, tim@linfiniti.com' 24 | ) 25 | 26 | import logging 27 | from PyQt4.QtCore import QObject, pyqtSlot, pyqtSignal 28 | from qgis.core import QgsMapLayerRegistry 29 | from qgis.gui import QgsMapCanvasLayer 30 | LOGGER = logging.getLogger('QGIS') 31 | 32 | 33 | #noinspection PyMethodMayBeStatic,PyPep8Naming 34 | class QgisInterface(QObject): 35 | """Class to expose QGIS objects and functions to plugins. 36 | 37 | This class is here for enabling us to run unit tests only, 38 | so most methods are simply stubs. 39 | """ 40 | currentLayerChanged = pyqtSignal(QgsMapCanvasLayer) 41 | 42 | def __init__(self, canvas): 43 | """Constructor 44 | :param canvas: 45 | """ 46 | QObject.__init__(self) 47 | self.canvas = canvas 48 | # Set up slots so we can mimic the behaviour of QGIS when layers 49 | # are added. 50 | LOGGER.debug('Initialising canvas...') 51 | # noinspection PyArgumentList 52 | QgsMapLayerRegistry.instance().layersAdded.connect(self.addLayers) 53 | # noinspection PyArgumentList 54 | QgsMapLayerRegistry.instance().layerWasAdded.connect(self.addLayer) 55 | # noinspection PyArgumentList 56 | QgsMapLayerRegistry.instance().removeAll.connect(self.removeAllLayers) 57 | 58 | # For processing module 59 | self.destCrs = None 60 | 61 | @pyqtSlot('QStringList') 62 | def addLayers(self, layers): 63 | """Handle layers being added to the registry so they show up in canvas. 64 | 65 | :param layers: list list of map layers that were added 66 | 67 | .. note:: The QgsInterface api does not include this method, 68 | it is added here as a helper to facilitate testing. 69 | """ 70 | #LOGGER.debug('addLayers called on qgis_interface') 71 | #LOGGER.debug('Number of layers being added: %s' % len(layers)) 72 | #LOGGER.debug('Layer Count Before: %s' % len(self.canvas.layers())) 73 | current_layers = self.canvas.layers() 74 | final_layers = [] 75 | for layer in current_layers: 76 | final_layers.append(QgsMapCanvasLayer(layer)) 77 | for layer in layers: 78 | final_layers.append(QgsMapCanvasLayer(layer)) 79 | 80 | self.canvas.setLayerSet(final_layers) 81 | #LOGGER.debug('Layer Count After: %s' % len(self.canvas.layers())) 82 | 83 | @pyqtSlot('QgsMapLayer') 84 | def addLayer(self, layer): 85 | """Handle a layer being added to the registry so it shows up in canvas. 86 | 87 | :param layer: list list of map layers that were added 88 | 89 | .. note: The QgsInterface api does not include this method, it is added 90 | here as a helper to facilitate testing. 91 | 92 | .. note: The addLayer method was deprecated in QGIS 1.8 so you should 93 | not need this method much. 94 | """ 95 | pass 96 | 97 | @pyqtSlot() 98 | def removeAllLayers(self): 99 | """Remove layers from the canvas before they get deleted.""" 100 | self.canvas.setLayerSet([]) 101 | 102 | def newProject(self): 103 | """Create new project.""" 104 | # noinspection PyArgumentList 105 | QgsMapLayerRegistry.instance().removeAllMapLayers() 106 | 107 | # ---------------- API Mock for QgsInterface follows ------------------- 108 | 109 | def zoomFull(self): 110 | """Zoom to the map full extent.""" 111 | pass 112 | 113 | def zoomToPrevious(self): 114 | """Zoom to previous view extent.""" 115 | pass 116 | 117 | def zoomToNext(self): 118 | """Zoom to next view extent.""" 119 | pass 120 | 121 | def zoomToActiveLayer(self): 122 | """Zoom to extent of active layer.""" 123 | pass 124 | 125 | def addVectorLayer(self, path, base_name, provider_key): 126 | """Add a vector layer. 127 | 128 | :param path: Path to layer. 129 | :type path: str 130 | 131 | :param base_name: Base name for layer. 132 | :type base_name: str 133 | 134 | :param provider_key: Provider key e.g. 'ogr' 135 | :type provider_key: str 136 | """ 137 | pass 138 | 139 | def addRasterLayer(self, path, base_name): 140 | """Add a raster layer given a raster layer file name 141 | 142 | :param path: Path to layer. 143 | :type path: str 144 | 145 | :param base_name: Base name for layer. 146 | :type base_name: str 147 | """ 148 | pass 149 | 150 | def activeLayer(self): 151 | """Get pointer to the active layer (layer selected in the legend).""" 152 | # noinspection PyArgumentList 153 | layers = QgsMapLayerRegistry.instance().mapLayers() 154 | for item in layers: 155 | return layers[item] 156 | 157 | def addToolBarIcon(self, action): 158 | """Add an icon to the plugins toolbar. 159 | 160 | :param action: Action to add to the toolbar. 161 | :type action: QAction 162 | """ 163 | pass 164 | 165 | def removeToolBarIcon(self, action): 166 | """Remove an action (icon) from the plugin toolbar. 167 | 168 | :param action: Action to add to the toolbar. 169 | :type action: QAction 170 | """ 171 | pass 172 | 173 | def addToolBar(self, name): 174 | """Add toolbar with specified name. 175 | 176 | :param name: Name for the toolbar. 177 | :type name: str 178 | """ 179 | pass 180 | 181 | def mapCanvas(self): 182 | """Return a pointer to the map canvas.""" 183 | return self.canvas 184 | 185 | def mainWindow(self): 186 | """Return a pointer to the main window. 187 | 188 | In case of QGIS it returns an instance of QgisApp. 189 | """ 190 | pass 191 | 192 | def addDockWidget(self, area, dock_widget): 193 | """Add a dock widget to the main window. 194 | 195 | :param area: Where in the ui the dock should be placed. 196 | :type area: 197 | 198 | :param dock_widget: A dock widget to add to the UI. 199 | :type dock_widget: QDockWidget 200 | """ 201 | pass 202 | 203 | def legendInterface(self): 204 | """Get the legend.""" 205 | return self.canvas 206 | -------------------------------------------------------------------------------- /test_plugin/test/tenbytenraster.asc: -------------------------------------------------------------------------------- 1 | NCOLS 10 2 | NROWS 10 3 | XLLCENTER 1535380.000000 4 | YLLCENTER 5083260.000000 5 | DX 10 6 | DY 10 7 | NODATA_VALUE -9999 8 | 0 1 2 3 4 5 6 7 8 9 9 | 0 1 2 3 4 5 6 7 8 9 10 | 0 1 2 3 4 5 6 7 8 9 11 | 0 1 2 3 4 5 6 7 8 9 12 | 0 1 2 3 4 5 6 7 8 9 13 | 0 1 2 3 4 5 6 7 8 9 14 | 0 1 2 3 4 5 6 7 8 9 15 | 0 1 2 3 4 5 6 7 8 9 16 | 0 1 2 3 4 5 6 7 8 9 17 | 0 1 2 3 4 5 6 7 8 9 18 | CRS 19 | NOTES 20 | -------------------------------------------------------------------------------- /test_plugin/test/tenbytenraster.asc.aux.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Point 4 | 5 | 6 | 7 | 9 8 | 4.5 9 | 0 10 | 2.872281323269 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test_plugin/test/tenbytenraster.keywords: -------------------------------------------------------------------------------- 1 | title: Tenbytenraster 2 | -------------------------------------------------------------------------------- /test_plugin/test/tenbytenraster.lic: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Tim Sutton, Linfiniti Consulting CC 5 | 6 | 7 | 8 | tenbytenraster.asc 9 | 2700044251 10 | Yes 11 | Tim Sutton 12 | Tim Sutton (QGIS Source Tree) 13 | Tim Sutton 14 | This data is publicly available from QGIS Source Tree. The original 15 | file was created and contributed to QGIS by Tim Sutton. 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /test_plugin/test/tenbytenraster.prj: -------------------------------------------------------------------------------- 1 | GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] -------------------------------------------------------------------------------- /test_plugin/test/tenbytenraster.qml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 0 26 | 27 | -------------------------------------------------------------------------------- /test_plugin/test/test_init.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """Tests QGIS plugin init.""" 3 | 4 | __author__ = 'Tim Sutton ' 5 | __revision__ = '$Format:%H$' 6 | __date__ = '17/10/2010' 7 | __license__ = "GPL" 8 | __copyright__ = 'Copyright 2012, Australia Indonesia Facility for ' 9 | __copyright__ += 'Disaster Reduction' 10 | 11 | import os 12 | import unittest 13 | import logging 14 | import ConfigParser 15 | 16 | LOGGER = logging.getLogger('QGIS') 17 | 18 | 19 | class TestInit(unittest.TestCase): 20 | """Test that the plugin init is usable for QGIS. 21 | 22 | Based heavily on the validator class by Alessandro 23 | Passoti available here: 24 | 25 | http://github.com/qgis/qgis-django/blob/master/qgis-app/ 26 | plugins/validator.py 27 | 28 | """ 29 | 30 | def test_read_init(self): 31 | """Test that the plugin __init__ will validate on plugins.qgis.org.""" 32 | 33 | # You should update this list according to the latest in 34 | # https://github.com/qgis/qgis-django/blob/master/qgis-app/ 35 | # plugins/validator.py 36 | 37 | required_metadata = [ 38 | 'name', 39 | 'description', 40 | 'version', 41 | 'qgisMinimumVersion', 42 | 'email', 43 | 'author'] 44 | 45 | file_path = os.path.abspath(os.path.join( 46 | os.path.dirname(__file__), os.pardir, 47 | 'metadata.txt')) 48 | LOGGER.info(file_path) 49 | metadata = [] 50 | parser = ConfigParser.ConfigParser() 51 | parser.optionxform = str 52 | parser.read(file_path) 53 | message = 'Cannot find a section named "general" in %s' % file_path 54 | assert parser.has_section('general'), message 55 | metadata.extend(parser.items('general')) 56 | 57 | for expectation in required_metadata: 58 | message = ('Cannot find metadata "%s" in metadata source (%s).' % ( 59 | expectation, file_path)) 60 | 61 | self.assertIn(expectation, dict(metadata), message) 62 | 63 | if __name__ == '__main__': 64 | unittest.main() 65 | -------------------------------------------------------------------------------- /test_plugin/test/test_qgis_environment.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """Tests for QGIS functionality. 3 | 4 | 5 | .. note:: This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | """ 11 | __author__ = 'tim@linfiniti.com' 12 | __date__ = '20/01/2011' 13 | __copyright__ = ('Copyright 2012, Australia Indonesia Facility for ' 14 | 'Disaster Reduction') 15 | 16 | import os 17 | import unittest 18 | from qgis.core import ( 19 | QgsProviderRegistry, 20 | QgsCoordinateReferenceSystem, 21 | QgsRasterLayer) 22 | 23 | from utilities import get_qgis_app 24 | QGIS_APP = get_qgis_app() 25 | 26 | 27 | class QGISTest(unittest.TestCase): 28 | """Test the QGIS Environment""" 29 | 30 | def test_qgis_environment(self): 31 | """QGIS environment has the expected providers""" 32 | 33 | r = QgsProviderRegistry.instance() 34 | self.assertIn('gdal', r.providerList()) 35 | self.assertIn('ogr', r.providerList()) 36 | self.assertIn('postgres', r.providerList()) 37 | 38 | def test_projection(self): 39 | """Test that QGIS properly parses a wkt string. 40 | """ 41 | crs = QgsCoordinateReferenceSystem() 42 | wkt = ( 43 | 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",' 44 | 'SPHEROID["WGS_1984",6378137.0,298.257223563]],' 45 | 'PRIMEM["Greenwich",0.0],UNIT["Degree",' 46 | '0.0174532925199433]]') 47 | crs.createFromWkt(wkt) 48 | auth_id = crs.authid() 49 | expected_auth_id = 'EPSG:4326' 50 | self.assertEqual(auth_id, expected_auth_id) 51 | 52 | # now test for a loaded layer 53 | path = os.path.join(os.path.dirname(__file__), 'tenbytenraster.asc') 54 | title = 'TestRaster' 55 | layer = QgsRasterLayer(path, title) 56 | auth_id = layer.crs().authid() 57 | self.assertEqual(auth_id, expected_auth_id) 58 | 59 | if __name__ == '__main__': 60 | unittest.main() 61 | -------------------------------------------------------------------------------- /test_plugin/test/test_resources.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """Resources test. 3 | 4 | .. note:: This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 2 of the License, or 7 | (at your option) any later version. 8 | 9 | """ 10 | 11 | __author__ = 'gsherman@geoapt.com' 12 | __date__ = '2014-10-06' 13 | __copyright__ = 'Copyright 2014, GeoApt LLC' 14 | 15 | import unittest 16 | 17 | from PyQt4.QtGui import QIcon 18 | 19 | 20 | 21 | class TestPluginDialogTest(unittest.TestCase): 22 | """Test rerources work.""" 23 | 24 | def setUp(self): 25 | """Runs before each test.""" 26 | pass 27 | 28 | def tearDown(self): 29 | """Runs after each test.""" 30 | pass 31 | 32 | def test_icon_png(self): 33 | """Test we can click OK.""" 34 | path = ':/plugins/TestPlugin/icon.png' 35 | icon = QIcon(path) 36 | self.assertFalse(icon.isNull()) 37 | 38 | if __name__ == "__main__": 39 | suite = unittest.makeSuite(TestPluginResourcesTest) 40 | runner = unittest.TextTestRunner(verbosity=2) 41 | runner.run(suite) 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /test_plugin/test/test_test_plugin_dialog.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """Dialog test. 3 | 4 | .. note:: This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 2 of the License, or 7 | (at your option) any later version. 8 | 9 | """ 10 | 11 | __author__ = 'gsherman@geoapt.com' 12 | __date__ = '2014-10-06' 13 | __copyright__ = 'Copyright 2014, GeoApt LLC' 14 | 15 | import unittest 16 | 17 | from PyQt4.QtGui import QDialogButtonBox, QDialog 18 | 19 | from test_plugin_dialog import TestPluginDialog 20 | 21 | from utilities import get_qgis_app 22 | QGIS_APP = get_qgis_app() 23 | 24 | 25 | class TestPluginDialogTest(unittest.TestCase): 26 | """Test dialog works.""" 27 | 28 | def setUp(self): 29 | """Runs before each test.""" 30 | self.dialog = TestPluginDialog(None) 31 | 32 | def tearDown(self): 33 | """Runs after each test.""" 34 | self.dialog = None 35 | 36 | def test_dialog_ok(self): 37 | """Test we can click OK.""" 38 | 39 | button = self.dialog.button_box.button(QDialogButtonBox.Ok) 40 | button.click() 41 | result = self.dialog.result() 42 | self.assertEqual(result, QDialog.Accepted) 43 | 44 | def test_dialog_cancel(self): 45 | """Test we can click cancel.""" 46 | button = self.dialog.button_box.button(QDialogButtonBox.Cancel) 47 | button.click() 48 | result = self.dialog.result() 49 | self.assertEqual(result, QDialog.Rejected) 50 | 51 | if __name__ == "__main__": 52 | suite = unittest.makeSuite(TestPluginDialogTest) 53 | runner = unittest.TextTestRunner(verbosity=2) 54 | runner.run(suite) 55 | 56 | -------------------------------------------------------------------------------- /test_plugin/test/test_translations.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """Safe Translations Test. 3 | 4 | .. note:: This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 2 of the License, or 7 | (at your option) any later version. 8 | 9 | """ 10 | from utilities import get_qgis_app 11 | 12 | __author__ = 'ismailsunni@yahoo.co.id' 13 | __date__ = '12/10/2011' 14 | __copyright__ = ('Copyright 2012, Australia Indonesia Facility for ' 15 | 'Disaster Reduction') 16 | import unittest 17 | import os 18 | 19 | from PyQt4.QtCore import QCoreApplication, QTranslator 20 | 21 | QGIS_APP = get_qgis_app() 22 | 23 | 24 | class SafeTranslationsTest(unittest.TestCase): 25 | """Test translations work.""" 26 | 27 | def setUp(self): 28 | """Runs before each test.""" 29 | if 'LANG' in os.environ.iterkeys(): 30 | os.environ.__delitem__('LANG') 31 | 32 | def tearDown(self): 33 | """Runs after each test.""" 34 | if 'LANG' in os.environ.iterkeys(): 35 | os.environ.__delitem__('LANG') 36 | 37 | def test_qgis_translations(self): 38 | """Test that translations work.""" 39 | parent_path = os.path.join(__file__, os.path.pardir, os.path.pardir) 40 | dir_path = os.path.abspath(parent_path) 41 | file_path = os.path.join( 42 | dir_path, 'i18n', 'af.qm') 43 | translator = QTranslator() 44 | translator.load(file_path) 45 | QCoreApplication.installTranslator(translator) 46 | 47 | expected_message = 'Goeie more' 48 | real_message = QCoreApplication.translate("@default", 'Good morning') 49 | self.assertEqual(real_message, expected_message) 50 | 51 | 52 | if __name__ == "__main__": 53 | suite = unittest.makeSuite(SafeTranslationsTest) 54 | runner = unittest.TextTestRunner(verbosity=2) 55 | runner.run(suite) 56 | -------------------------------------------------------------------------------- /test_plugin/test/utilities.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """Common functionality used by regression tests.""" 3 | 4 | import sys 5 | import logging 6 | 7 | 8 | LOGGER = logging.getLogger('QGIS') 9 | QGIS_APP = None # Static variable used to hold hand to running QGIS app 10 | CANVAS = None 11 | PARENT = None 12 | IFACE = None 13 | 14 | 15 | def get_qgis_app(): 16 | """ Start one QGIS application to test against. 17 | 18 | :returns: Handle to QGIS app, canvas, iface and parent. If there are any 19 | errors the tuple members will be returned as None. 20 | :rtype: (QgsApplication, CANVAS, IFACE, PARENT) 21 | 22 | If QGIS is already running the handle to that app will be returned. 23 | """ 24 | 25 | try: 26 | from PyQt4 import QtGui, QtCore 27 | from qgis.core import QgsApplication 28 | from qgis.gui import QgsMapCanvas 29 | from qgis_interface import QgisInterface 30 | except ImportError: 31 | return None, None, None, None 32 | 33 | global QGIS_APP # pylint: disable=W0603 34 | 35 | if QGIS_APP is None: 36 | gui_flag = True # All test will run qgis in gui mode 37 | #noinspection PyPep8Naming 38 | QGIS_APP = QgsApplication(sys.argv, gui_flag) 39 | # Make sure QGIS_PREFIX_PATH is set in your env if needed! 40 | QGIS_APP.initQgis() 41 | s = QGIS_APP.showSettings() 42 | LOGGER.debug(s) 43 | 44 | global PARENT # pylint: disable=W0603 45 | if PARENT is None: 46 | #noinspection PyPep8Naming 47 | PARENT = QtGui.QWidget() 48 | 49 | global CANVAS # pylint: disable=W0603 50 | if CANVAS is None: 51 | #noinspection PyPep8Naming 52 | CANVAS = QgsMapCanvas(PARENT) 53 | CANVAS.resize(QtCore.QSize(400, 400)) 54 | 55 | global IFACE # pylint: disable=W0603 56 | if IFACE is None: 57 | # QgisInterface is a stub implementation of the QGIS plugin interface 58 | #noinspection PyPep8Naming 59 | IFACE = QgisInterface(CANVAS) 60 | 61 | return QGIS_APP, CANVAS, IFACE, PARENT 62 | -------------------------------------------------------------------------------- /test_plugin/test_plugin.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | TestPlugin 5 | A QGIS plugin 6 | Test Plugin 7 | ------------------- 8 | begin : 2014-10-06 9 | git sha : $Format:%H$ 10 | copyright : (C) 2014 by GeoApt LLC 11 | email : gsherman@geoapt.com 12 | ***************************************************************************/ 13 | 14 | /*************************************************************************** 15 | * * 16 | * This program is free software; you can redistribute it and/or modify * 17 | * it under the terms of the GNU General Public License as published by * 18 | * the Free Software Foundation; either version 2 of the License, or * 19 | * (at your option) any later version. * 20 | * * 21 | ***************************************************************************/ 22 | """ 23 | from PyQt4.QtCore import QSettings, QTranslator, qVersion, QCoreApplication 24 | from PyQt4.QtGui import QAction, QIcon 25 | # Initialize Qt resources from file resources.py 26 | import resources_rc 27 | # Import the code for the dialog 28 | from test_plugin_dialog import TestPluginDialog 29 | import os.path 30 | 31 | 32 | class TestPlugin: 33 | """QGIS Plugin Implementation.""" 34 | 35 | def __init__(self, iface): 36 | """Constructor. 37 | 38 | :param iface: An interface instance that will be passed to this class 39 | which provides the hook by which you can manipulate the QGIS 40 | application at run time. 41 | :type iface: QgsInterface 42 | """ 43 | # Save reference to the QGIS interface 44 | self.iface = iface 45 | # initialize plugin directory 46 | self.plugin_dir = os.path.dirname(__file__) 47 | # initialize locale 48 | locale = QSettings().value('locale/userLocale')[0:2] 49 | locale_path = os.path.join( 50 | self.plugin_dir, 51 | 'i18n', 52 | 'TestPlugin_{}.qm'.format(locale)) 53 | 54 | if os.path.exists(locale_path): 55 | self.translator = QTranslator() 56 | self.translator.load(locale_path) 57 | 58 | if qVersion() > '4.3.3': 59 | QCoreApplication.installTranslator(self.translator) 60 | 61 | # Create the dialog (after translation) and keep reference 62 | self.dlg = TestPluginDialog() 63 | 64 | # Declare instance attributes 65 | self.actions = [] 66 | self.menu = self.tr(u'&Test Plugin') 67 | # TODO: We are going to let the user set this up in a future iteration 68 | self.toolbar = self.iface.addToolBar(u'TestPlugin') 69 | self.toolbar.setObjectName(u'TestPlugin') 70 | 71 | # noinspection PyMethodMayBeStatic 72 | def tr(self, message): 73 | """Get the translation for a string using Qt translation API. 74 | 75 | We implement this ourselves since we do not inherit QObject. 76 | 77 | :param message: String for translation. 78 | :type message: str, QString 79 | 80 | :returns: Translated version of message. 81 | :rtype: QString 82 | """ 83 | # noinspection PyTypeChecker,PyArgumentList,PyCallByClass 84 | return QCoreApplication.translate('TestPlugin', message) 85 | 86 | 87 | def add_action( 88 | self, 89 | icon_path, 90 | text, 91 | callback, 92 | enabled_flag=True, 93 | add_to_menu=True, 94 | add_to_toolbar=True, 95 | status_tip=None, 96 | whats_this=None, 97 | parent=None): 98 | """Add a toolbar icon to the toolbar. 99 | 100 | :param icon_path: Path to the icon for this action. Can be a resource 101 | path (e.g. ':/plugins/foo/bar.png') or a normal file system path. 102 | :type icon_path: str 103 | 104 | :param text: Text that should be shown in menu items for this action. 105 | :type text: str 106 | 107 | :param callback: Function to be called when the action is triggered. 108 | :type callback: function 109 | 110 | :param enabled_flag: A flag indicating if the action should be enabled 111 | by default. Defaults to True. 112 | :type enabled_flag: bool 113 | 114 | :param add_to_menu: Flag indicating whether the action should also 115 | be added to the menu. Defaults to True. 116 | :type add_to_menu: bool 117 | 118 | :param add_to_toolbar: Flag indicating whether the action should also 119 | be added to the toolbar. Defaults to True. 120 | :type add_to_toolbar: bool 121 | 122 | :param status_tip: Optional text to show in a popup when mouse pointer 123 | hovers over the action. 124 | :type status_tip: str 125 | 126 | :param parent: Parent widget for the new action. Defaults None. 127 | :type parent: QWidget 128 | 129 | :param whats_this: Optional text to show in the status bar when the 130 | mouse pointer hovers over the action. 131 | 132 | :returns: The action that was created. Note that the action is also 133 | added to self.actions list. 134 | :rtype: QAction 135 | """ 136 | 137 | icon = QIcon(icon_path) 138 | action = QAction(icon, text, parent) 139 | action.triggered.connect(callback) 140 | action.setEnabled(enabled_flag) 141 | 142 | if status_tip is not None: 143 | action.setStatusTip(status_tip) 144 | 145 | if whats_this is not None: 146 | action.setWhatsThis(whats_this) 147 | 148 | if add_to_toolbar: 149 | self.toolbar.addAction(action) 150 | 151 | if add_to_menu: 152 | self.iface.addPluginToMenu( 153 | self.menu, 154 | action) 155 | 156 | self.actions.append(action) 157 | 158 | return action 159 | 160 | def initGui(self): 161 | """Create the menu entries and toolbar icons inside the QGIS GUI.""" 162 | 163 | icon_path = ':/plugins/TestPlugin/icon.png' 164 | self.add_action( 165 | icon_path, 166 | text=self.tr(u'Test Plugin'), 167 | callback=self.run, 168 | parent=self.iface.mainWindow()) 169 | 170 | 171 | def unload(self): 172 | """Removes the plugin menu item and icon from QGIS GUI.""" 173 | for action in self.actions: 174 | self.iface.removePluginMenu( 175 | self.tr(u'&Test Plugin'), 176 | action) 177 | self.iface.removeToolBarIcon(action) 178 | 179 | 180 | def run(self): 181 | """Run method that performs all the real work""" 182 | # show the dialog 183 | self.dlg.show() 184 | # Run the dialog event loop 185 | result = self.dlg.exec_() 186 | # See if OK was pressed 187 | if result: 188 | # Do something useful here - delete the line containing pass and 189 | # substitute with your code. 190 | pass 191 | -------------------------------------------------------------------------------- /test_plugin/test_plugin_dialog.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | TestPluginDialog 5 | A QGIS plugin 6 | Test Plugin 7 | ------------------- 8 | begin : 2014-10-06 9 | git sha : $Format:%H$ 10 | copyright : (C) 2014 by GeoApt LLC 11 | email : gsherman@geoapt.com 12 | ***************************************************************************/ 13 | 14 | /*************************************************************************** 15 | * * 16 | * This program is free software; you can redistribute it and/or modify * 17 | * it under the terms of the GNU General Public License as published by * 18 | * the Free Software Foundation; either version 2 of the License, or * 19 | * (at your option) any later version. * 20 | * * 21 | ***************************************************************************/ 22 | """ 23 | 24 | import os 25 | 26 | from PyQt4 import QtGui, uic 27 | 28 | FORM_CLASS, _ = uic.loadUiType(os.path.join( 29 | os.path.dirname(__file__), 'test_plugin_dialog_base.ui')) 30 | 31 | 32 | class TestPluginDialog(QtGui.QDialog, FORM_CLASS): 33 | def __init__(self, parent=None): 34 | """Constructor.""" 35 | super(TestPluginDialog, self).__init__(parent) 36 | # Set up the user interface from Designer. 37 | # After setupUI you can access any designer object by doing 38 | # self., and you can use autoconnect slots - see 39 | # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html 40 | # #widgets-and-dialogs-with-auto-connect 41 | self.setupUi(self) 42 | -------------------------------------------------------------------------------- /test_plugin/test_plugin_dialog_base.ui: -------------------------------------------------------------------------------- 1 | 2 | TestPluginDialogBase 3 | 4 | 5 | 6 | 0 7 | 0 8 | 400 9 | 300 10 | 11 | 12 | 13 | Test Plugin 14 | 15 | 16 | 17 | 18 | 30 19 | 240 20 | 341 21 | 32 22 | 23 | 24 | 25 | Qt::Horizontal 26 | 27 | 28 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 29 | 30 | 31 | 32 | 33 | 34 | 35 | button_box 36 | accepted() 37 | TestPluginDialogBase 38 | accept() 39 | 40 | 41 | 248 42 | 254 43 | 44 | 45 | 157 46 | 274 47 | 48 | 49 | 50 | 51 | button_box 52 | rejected() 53 | TestPluginDialogBase 54 | reject() 55 | 56 | 57 | 316 58 | 260 59 | 60 | 61 | 286 62 | 274 63 | 64 | 65 | 66 | 67 | 68 | --------------------------------------------------------------------------------