~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/plugins/plugin_builder.pl

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl
2
 
use Cwd;
3
 
 
4
 
#####################################################
5
 
# A script to automate creation of a new QGIS plugin
6
 
# using the plugin_template
7
 
# Authors GSherman TSutton
8
 
# Feb 21, 2004
9
 
#####################################################
10
 
# $Id: plugin_builder.pl 5212 2006-04-07 23:21:38Z timlinux $ #
11
 
 
12
 
#make sure we are in a the plugins directory otherwise the changes this script will make will 
13
 
#wreak havoc....
14
 
$myDir = fastgetcwd;
15
 
print "\n\nChecking that we are in the <qgis dir>/src/plugins/ directory....";
16
 
if ($myDir =~ m/src\/plugins$/) {
17
 
  print "yes\n";
18
 
}else {
19
 
  print "no\n";
20
 
  print $myDir;
21
 
  print "\nPlease relocate to the plugins directory before attempting to run this script.\n";
22
 
  exit;
23
 
}
24
 
# get the needed information from the user
25
 
print "\n\nEnter the directory name under qgis/src/plugins/ where your new plugin will be created.\n";
26
 
print "We suggest using a lowercase underscore separated name e.g. clever_plugin\n";
27
 
print "Directory for the new plugin:";
28
 
$pluginDir =<STDIN>;
29
 
chop $pluginDir;
30
 
 
31
 
print "\n\nEnter the name that will be used when creating the plugin library.\n";
32
 
print "The name should be entered as a mixed case name with no spaces. e.g. CleverTool\n";
33
 
print "The plugin name will be used in the following ways:\n";
34
 
print "1) it will be 'lower cased' and used as the root of the generated lib name \n";
35
 
print "   e.g. libqgis_plugin_clevertool\n";
36
 
print "2) in its upper cased form it will be used as the basis for class names, in particular\n";
37
 
print "   CleverToolGuiBase <- The base class for the plugins configuration dialog / gui generated by uic\n";
38
 
print "   CleverToolGui     <- The concrete class for the plugins configuration dialog\n";
39
 
print "3) CleverTool     <- The class that includes the plugin loader instructions and\n";
40
 
print "                     and calls to your custom application logic\n";
41
 
print "4) clevertool.h, clevertool.cpp  etc. <- the filenames used to hold the above derived classes\n";
42
 
print "Plugin name: " ;
43
 
$pluginName = <STDIN>;
44
 
chop $pluginName;
45
 
$pluginLCaseName = lc($pluginName); #todo convert to lower case 
46
 
 
47
 
print "\n\nEnter a short description (typically one line)\n";
48
 
print "e.g. The clever plugin does clever stuff in QGIS\n";
49
 
print "Plugin description: " ;
50
 
$pluginDescription = <STDIN>;
51
 
chop $pluginDescription;
52
 
 
53
 
print "\n\n Enter the name of the application menu that will be created for your plugin\n";
54
 
print "Clever Tools\n";
55
 
print "Menu name: ";
56
 
$menuName = <STDIN>;
57
 
chop $menuName;
58
 
 
59
 
print "\n\n Enter the name of the menu entry  (under the menu that you have just defined) that\n";
60
 
print "will be used to invoke your plugin. e.g. Clever Plugin\n";
61
 
print "Menu item name: ";
62
 
$menuItemName = <STDIN>;
63
 
chop $menuItemName;
64
 
 
65
 
# print a summary of what's about to happen
66
 
print << "EOF";
67
 
 
68
 
Summary of plugin parameters:
69
 
---------------------------------------------
70
 
Plugin directory      $pluginDir
71
 
Name of the plugin:   $pluginName
72
 
Library name of the plugin:   libqgis_plugin_$pluginLCaseName
73
 
Description of the plugin:   $pluginDescription
74
 
Menu name:            $menuName
75
 
Menu item name:       $menuItemName
76
 
 
77
 
Warning - Proceeding will make changes to Makefile.am in this directory,
78
 
as well as ../../configure.in. Please use caution.
79
 
EOF
80
 
# ask if we should proceed
81
 
print "Create the plugin? [y/n]: ";
82
 
$createIt = <STDIN>;
83
 
chop $createIt;
84
 
 
85
 
if(($createIt eq 'y') || ($createIt eq 'Y')){
86
 
  #
87
 
  # its a go -- create the plugin and modify the build files
88
 
  #
89
 
  # create the new plugin directory
90
 
  system("mkdir $pluginDir");
91
 
  # copy files to appropriate names
92
 
  system("cp plugin_template/Makefile.am $pluginDir/");
93
 
  system("cp plugin_template/README.whatnext $pluginDir/README");
94
 
  system("cp plugin_template/plugin.qrc $pluginDir/$pluginLCaseName.qrc");
95
 
  system("cp plugin_template/plugin.png $pluginDir/$pluginLCaseName.png");
96
 
  system("cp plugin_template/plugin.cpp $pluginDir/$pluginLCaseName.cpp");
97
 
  system("cp plugin_template/plugin.h $pluginDir/$pluginLCaseName.h");
98
 
  system("cp plugin_template/plugingui.cpp $pluginDir/${pluginLCaseName}gui.cpp");
99
 
  system("cp plugin_template/plugingui.h $pluginDir/${pluginLCaseName}gui.h");
100
 
  system("cp plugin_template/pluginguibase.ui $pluginDir/${pluginLCaseName}guibase.ui");
101
 
  system("cp plugin_template/pluginguibase.ui.h $pluginDir/${pluginLCaseName}guibase.ui.h");
102
 
  
103
 
  # Substitute the plugin specific vars in the various files
104
 
  # This is a brute force approach but its quick and dirty :)
105
 
  #
106
 
  # replace [pluginlcasename] in template with the new plugin name
107
 
  system("perl -pi -e 's/\\\[pluginlcasename\\\]/$pluginLCaseName/g' $pluginDir/*.qrc $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am $pluginDir/*.ui");
108
 
  # replace [pluginname] in template with the new plugin name
109
 
  system("perl -pi -e 's/\\\[pluginname\\\]/$pluginName/g' $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am $pluginDir/*.ui");
110
 
  # replace [plugindescription] in template with the description
111
 
  system("perl -pi -e 's/\\\[plugindescription\\\]/$pluginDescription/g' $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am");
112
 
  # replace [menuname] in the template with the menu name
113
 
  system("perl -pi -e 's/\\\[menuname\\\]/$menuName/g' $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am");
114
 
  # replace [menuitemname] in the template with the menu item name
115
 
  system("perl -pi -e 's/\\\[menuitemname\\\]/$menuItemName/g' $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am");
116
 
  
117
 
  # Add an entry to qgis/plugins/Makefile.am
118
 
  # We won't add it the EXTRA_DIST since we don't want to necesarily distribute
119
 
  # third party plugins
120
 
  open MAKEFILE, "<./Makefile.am" || die 'Unable to open Makefile.am';
121
 
  open MAKEFILEMOD, ">./Makefile.am.mod" || die 'Unable to create Makefile.am.mod';
122
 
  # read through Makefile.am and write each line to Makefile.am.mod
123
 
  while(<MAKEFILE>){
124
 
    if(/^\s*SUBDIRS =*/){
125
 
      # add our plugin dir to the next line after SUBDIRS line
126
 
      print MAKEFILEMOD;
127
 
      print MAKEFILEMOD "\t\t$pluginDir \\\n";
128
 
    }else{
129
 
      print MAKEFILEMOD;
130
 
    }
131
 
  }
132
 
  # close the Makefile file handles
133
 
  close MAKEFILEMOD;
134
 
  close MAKEFILE;
135
 
  
136
 
  # save Makefile.am in case we die before done moving things around
137
 
  system("mv Makefile.am Makefile.am.save");
138
 
  # move the new Makefile.am to where it belongs
139
 
  system("mv Makefile.am.mod Makefile.am");
140
 
  # delete the original Makefile.am
141
 
  unlink("Makefile.am.save");
142
 
 
143
 
  # Add an entry to qgis/configure.in
144
 
  # Do we really want to do this or add a message telling the user how to do
145
 
  # it?
146
 
  open CONFIGUREIN, "<../../configure.in" || die 'Unable to open ../../configure.in';
147
 
  open CONFIGUREINMOD, ">../../configure.in.mod" || die 'Unable to create ../../configure.in.mod';
148
 
  # read through configure.in until we find the AC_CONFIG_FILES section
149
 
   while(<CONFIGUREIN>){
150
 
    if(/^\s*AC_CONFIG_FILES*/){
151
 
      # set the flag so we can look for the closing ])
152
 
      $inConfigFile = 1;
153
 
      print CONFIGUREINMOD;
154
 
      
155
 
    }else{
156
 
      if($inConfigFile){
157
 
        if(/^\s*\]\)*/){
158
 
          # write our entry 
159
 
          print CONFIGUREINMOD "\tsrc/plugins/$pluginDir/Makefile\n";
160
 
          $inConfigFile = 0;
161
 
        }
162
 
      }
163
 
      print CONFIGUREINMOD;
164
 
    }
165
 
  }
166
 
  close CONFIGUREIN;
167
 
  close CONFIGUREINMOD;
168
 
  
169
 
   # save configure.in in case we die before done moving things around
170
 
  system("mv ../../configure.in ../../configure.in.save");
171
 
  # move the new configure.in to where it belongs
172
 
  system("mv ../../configure.in.mod ../../configure.in");
173
 
  # delete the original configure.in
174
 
  unlink("../../configure.in.save");
175
 
  
176
 
# print out some end of processing info
177
 
print << "EOP";
178
 
 
179
 
Your plugin ($pluginName) has been created in $pluginDir.
180
 
Makefile.am and configure.in have been modified.
181
 
To build the plugin, you must change to the top level of the source tree and
182
 
run autoreconf, configure, then make.
183
 
 
184
 
Once your plugin has successfully built, please see $pluginDir/README for 
185
 
hints on how to get started.
186
 
 
187
 
EOP
188
 
 
189
 
}else{
190
 
  # user cancelled
191
 
  print "Plugin not created\n";
192
 
}
193