=== modified file 'common/common_plot_functions.cpp'
--- common/common_plot_functions.cpp	2013-03-28 20:49:17 +0000
+++ common/common_plot_functions.cpp	2013-05-01 13:12:44 +0000
@@ -865,3 +865,69 @@
 #endif
 
 }
+
+/** Get the 'traditional' gerber extension depending on the layer
+*/
+wxString GetGerberExtension( LAYER_NUM layer )/*{{{*/
+{
+    switch( layer )
+    {
+    case LAYER_N_FRONT:
+        return wxString( wxT( "gtl" ) );
+
+    case LAYER_N_2:
+    case LAYER_N_3:
+    case LAYER_N_4:
+    case LAYER_N_5:
+    case LAYER_N_6:
+    case LAYER_N_7:
+    case LAYER_N_8:
+    case LAYER_N_9:
+    case LAYER_N_10:
+    case LAYER_N_11:
+    case LAYER_N_12:
+    case LAYER_N_13:
+    case LAYER_N_14:
+    case LAYER_N_15:
+
+        // TODO: see if we use .gbr or a layer identifier (gb1 .. gbnn ?)
+        // according to the new internal layers designation
+        // (1 is the first internal layer from the front layer)
+        return wxString( wxT( "gbr" ) );
+
+    case LAYER_N_BACK:
+        return wxString( wxT( "gbl" ) );
+
+    case ADHESIVE_N_BACK:
+        return wxString( wxT( "gba" ) );
+
+    case ADHESIVE_N_FRONT:
+        return wxString( wxT( "gta" ) );
+
+    case SOLDERPASTE_N_BACK:
+        return wxString( wxT( "gbp" ) );
+
+    case SOLDERPASTE_N_FRONT:
+        return wxString( wxT( "gtp" ) );
+
+    case SILKSCREEN_N_BACK:
+        return wxString( wxT( "gbo" ) );
+
+    case SILKSCREEN_N_FRONT:
+        return wxString( wxT( "gto" ) );
+
+    case SOLDERMASK_N_BACK:
+        return wxString( wxT( "gbs" ) );
+
+    case SOLDERMASK_N_FRONT:
+        return wxString( wxT( "gts" ) );
+
+    case DRAW_N:
+    case COMMENT_N:
+    case ECO1_N:
+    case ECO2_N:
+    case EDGE_N:
+    default:
+        return wxString( wxT( "gbr" ) );
+    }
+}/*}}}*/

=== modified file 'include/plot_common.h'
--- include/plot_common.h	2013-04-05 08:55:46 +0000
+++ include/plot_common.h	2013-05-01 13:12:38 +0000
@@ -13,6 +13,7 @@
 #include <drawtxt.h>
 #include <common.h>         // PAGE_INFO
 #include <eda_text.h>       // FILL_T
+#include <layers_id_colors_and_visibility.h> //LAYER_NUM
 
 /**
  * Enum PlotFormat
@@ -916,5 +917,6 @@
   */
 wxString GetDefaultPlotExtension( PlotFormat aFormat );
 
+wxString GetGerberExtension( LAYER_NUM layer );
 
 #endif  // PLOT_COMMON_H_

=== modified file 'pcbnew/dialogs/dialog_gendrill.cpp'
--- pcbnew/dialogs/dialog_gendrill.cpp	2013-04-28 09:10:54 +0000
+++ pcbnew/dialogs/dialog_gendrill.cpp	2013-05-01 13:12:02 +0000
@@ -426,6 +426,7 @@
                 }
 
                 excellonWriter.CreateDrillFile( file );
+                fclose( file );
             }
 
             if( aGenMap )

=== modified file 'pcbnew/gendrill_Excellon_writer.cpp'
--- pcbnew/gendrill_Excellon_writer.cpp	2013-03-18 19:36:07 +0000
+++ pcbnew/gendrill_Excellon_writer.cpp	2013-05-01 13:12:00 +0000
@@ -410,7 +410,6 @@
 {
     //add if minimal here
     fputs( "T0\nM30\n", m_file );
-    fclose( m_file );
 }
 
 

=== modified file 'pcbnew/gendrill_Excellon_writer.h'
--- pcbnew/gendrill_Excellon_writer.h	2013-04-28 09:10:54 +0000
+++ pcbnew/gendrill_Excellon_writer.h	2013-05-01 13:09:53 +0000
@@ -207,7 +207,6 @@
      * Function CreateDrillFile
      * Creates an Excellon drill file
      * @param aFile = an opened file to write to
-     *   will be closed by CreateDrillFile
      * @return hole count
      */
     int  CreateDrillFile( FILE * aFile );

=== modified file 'pcbnew/pcbplot.cpp'
--- pcbnew/pcbplot.cpp	2013-04-18 21:21:26 +0000
+++ pcbnew/pcbplot.cpp	2013-05-01 13:09:34 +0000
@@ -42,72 +42,6 @@
 #include <dialog_plot.h>
 
 
-/** Get the 'traditional' gerber extension depending on the layer
-*/
-static wxString GetGerberExtension( LAYER_NUM layer )/*{{{*/
-{
-    switch( layer )
-    {
-    case LAYER_N_FRONT:
-        return wxString( wxT( "gtl" ) );
-
-    case LAYER_N_2:
-    case LAYER_N_3:
-    case LAYER_N_4:
-    case LAYER_N_5:
-    case LAYER_N_6:
-    case LAYER_N_7:
-    case LAYER_N_8:
-    case LAYER_N_9:
-    case LAYER_N_10:
-    case LAYER_N_11:
-    case LAYER_N_12:
-    case LAYER_N_13:
-    case LAYER_N_14:
-    case LAYER_N_15:
-
-        // TODO: see if we use .gbr or a layer identifier (gb1 .. gbnn ?)
-        // according to the new internal layers designation
-        // (1 is the first internal layer from the front layer)
-        return wxString( wxT( "gbr" ) );
-
-    case LAYER_N_BACK:
-        return wxString( wxT( "gbl" ) );
-
-    case ADHESIVE_N_BACK:
-        return wxString( wxT( "gba" ) );
-
-    case ADHESIVE_N_FRONT:
-        return wxString( wxT( "gta" ) );
-
-    case SOLDERPASTE_N_BACK:
-        return wxString( wxT( "gbp" ) );
-
-    case SOLDERPASTE_N_FRONT:
-        return wxString( wxT( "gtp" ) );
-
-    case SILKSCREEN_N_BACK:
-        return wxString( wxT( "gbo" ) );
-
-    case SILKSCREEN_N_FRONT:
-        return wxString( wxT( "gto" ) );
-
-    case SOLDERMASK_N_BACK:
-        return wxString( wxT( "gbs" ) );
-
-    case SOLDERMASK_N_FRONT:
-        return wxString( wxT( "gts" ) );
-
-    case DRAW_N:
-    case COMMENT_N:
-    case ECO1_N:
-    case ECO2_N:
-    case EDGE_N:
-    default:
-        return wxString( wxT( "gbr" ) );
-    }
-}/*}}}*/
-
 /* Complete a plot filename: forces the output directory,
  * add a suffix to the name and sets the specified extension
  * the suffix is usually the layer name
@@ -342,6 +276,17 @@
                                     PlotFormat aFormat,
                                     const wxString &aSheetDesc )
 {
+    return PLOT_CONTROLLER::OpenPlotfile( aSuffix,
+            aFormat,
+            aSheetDesc,
+            GetDefaultPlotExtension( m_plotOpts.GetFormat() ) );
+}
+
+bool PLOT_CONTROLLER::OpenPlotfile( const wxString &aSuffix, /*{{{*/
+                                    PlotFormat aFormat,
+                                    const wxString &aSheetDesc,
+                                    const wxString &aExt)
+{
     LOCALE_IO toggle;
 
     /* Save the current format: sadly some plot routines depends on this

=== modified file 'pcbnew/plotcontroller.h'
--- pcbnew/plotcontroller.h	2013-04-18 21:21:26 +0000
+++ pcbnew/plotcontroller.h	2013-05-01 13:03:58 +0000
@@ -25,6 +25,9 @@
     void ClosePlot();
     bool OpenPlotfile( const wxString &aSuffix, PlotFormat aFormat,
                        const wxString &aSheetDesc );
+    bool OpenPlotfile( const wxString &aSuffix, PlotFormat aFormat,
+                       const wxString &aSheetDesc,
+                       const wxString &aExt);
     
     bool PlotLayer( LAYER_NUM layer );
     

=== modified file 'pcbnew/scripting/pcbnew.i'
--- pcbnew/scripting/pcbnew.i	2012-11-10 06:39:18 +0000
+++ pcbnew/scripting/pcbnew.i	2013-05-01 13:03:32 +0000
@@ -97,8 +97,10 @@
   #include <pcbnew_scripting_helpers.h>
 
   #include <plotcontroller.h>
+  #include <plot_common.h>
   #include <pcb_plot_params.h>
   #include <colors.h>
+  #include <gendrill_Excellon_writer.h>
 
   BOARD *GetBoard(); /* get current editor board */
 %}
@@ -134,6 +136,7 @@
 %include <pcb_plot_params.h>
 %include <plot_common.h>
 %include <colors.h>
+%include <gendrill_Excellon_writer.h>
 
 %include "board_item.i"
 

=== modified file 'scripting/kicad.i'
--- scripting/kicad.i	2012-07-15 20:01:05 +0000
+++ scripting/kicad.i	2013-05-01 13:02:05 +0000
@@ -27,6 +27,18 @@
  * @brief General wrappers for kicad / wx structures and classes
  */
 
+/* Typemap to convert FILE* to python file objects */
+/* Converts a PyFile instance to a stdio FILE* */
+%typemap(in) FILE* {
+    if ( PyFile_Check($input) ){
+        $1 = PyFile_AsFile($input);
+    } else {
+        PyErr_SetString(PyExc_TypeError, "$1_name must be a file type.");
+        return NULL;
+    }
+}
+
+
 %include <std_vector.i>
 %include <std_string.i>
 

