Ver Fonte

No more garbage tempfiles, optimizer updated

olivier.massot há 9 anos atrás
pai
commit
ae3cbc7214

BIN
OpenAccess.zip


+ 5 - 5
source/forms/OpenAccess.bas

@@ -23,7 +23,7 @@ Begin Form
     ItemSuffix =43
     Left =-22140
     Top =2430
-    Right =-255
+    Right =-7110
     Bottom =14565
     DatasheetGridlinesColor =14806254
     RecSrcDt = Begin
@@ -828,7 +828,7 @@ Begin Form
                     Height =226
                     TabIndex =2
                     BorderColor =10921638
-                    Name ="chk_optimizer"
+                    Name ="chk_newer_only"
                     DefaultValue ="True"
                     ControlTipText ="Exports only the tables defs, queries, forms, reports, macros and modules modifi"
                         "ed since the last Open Access export"
@@ -1011,8 +1011,8 @@ Option Compare Database
 Dim RUNNING_OP As Boolean
 
 Private Sub cmd_export_Click()
-    Dim optimizer, zip As Boolean
-    optimizer = Me.chk_optimizer
+    Dim newer_only, zip As Boolean
+    newer_only = Me.chk_newer_only
     zip = Me.chk_zip
     
     If Me.chk_debug_mode Then
@@ -1030,7 +1030,7 @@ Private Sub cmd_export_Click()
     
     ' start export
     Dim result As Variant
-    result = make_sources(optimizer, zip)
+    result = make_sources(newer_only, zip)
     
     ' update state
     RUNNING_OP = False

+ 4 - 8
source/modules/OA_Main.bas

@@ -23,7 +23,7 @@ Public Function main()
 
 End Function
 
-Public Function make_sources(Optional ByVal optimizer As Boolean = True, _
+Public Function make_sources(Optional ByVal newer_only As Boolean = True, _
                              Optional ByVal zip As Boolean = True) As Integer
 'exports the source-code of the app
 If Not debug_mode Then On Error GoTo err
@@ -33,14 +33,10 @@ Dim step As String
     
     step = "Initialization"
     
-    If optimizer Then
-        Call activate_optimizer
-    End If
-    
     'Save is needed to correctly list objects to export
     SaveProject
 
-    If Not prompt_for_export_confirmation Then
+    If Not prompt_for_export_confirmation(newer_only) Then
         GoTo cancelOp
     End If
 
@@ -55,7 +51,7 @@ Dim step As String
     step = "Run Open Access Export"
     logger "make_sources", "INFO", step
     
-    Call ExportAll
+    Call ExportAll(newer_only)
 
     ' new sources date
     step = "Updates sources date"
@@ -222,7 +218,7 @@ Public Function silent_export()
     OA_Log.set_debug_mode
 
     Dim result As Variant
-    result = make_sources(optimizer:=False, zip:=True)
+    result = make_sources(newer_only:=False, zip:=True)
 
     logger "silent_export", "INFO", "make_sources returned " & result
 

+ 2 - 2
source/modules/OA_Msg.bas

@@ -49,12 +49,12 @@ End Function
 
 
 
-Public Function prompt_for_export_confirmation() As Boolean
+Public Function prompt_for_export_confirmation(ByVal newer_only As Boolean) As Boolean
     Dim msg As String
     
     msg = "****   OPENACCESS EXPORT   ****" & vbNewLine & _
           "You're going to export the following:" & vbNewLine & vbNewLine & _
-          msg_list_to_export() & _
+          msg_list_to_export(newer_only) & _
           ""
           
     prompt_for_export_confirmation = (OA_MsgBox(msg, vbOKCancel + vbExclamation, "Confirm") = vbOK)

+ 2 - 12
source/modules/OA_Optimizer.bas

@@ -8,21 +8,11 @@ Option Explicit
 '*
 '****
 
-' *** activates the optimizer
-Private p_optimizer As Boolean
-
 'needs_export
 Public Const NoExportNeeded = 0
 Public Const MissingFiles = 1
 Public Const UpdateNeeded = 2
 
-Public Sub activate_optimizer()
-    p_optimizer = True
-End Sub
-
-Public Function optimizer_activated()
-    optimizer_activated = p_optimizer
-End Function
 '***
 
 
@@ -114,7 +104,7 @@ emptylist:
 End Function
 
 
-Public Function msg_list_to_export() As String
+Public Function msg_list_to_export(ByVal newer_only As Boolean) As String
 'returns a formatted text listing all of the objects which were updated since last export of the sources
     Dim lstmod, obj_type_split, obj_type_label, obj_type_num As String
     Dim obj_type, objname As Variant
@@ -136,7 +126,7 @@ Public Function msg_list_to_export() As String
 
         msg_list_to_export = msg_list_to_export & "> " & UCase(obj_type_label) & ":  "
 
-        If p_optimizer = False Then
+        If newer_only = False Then
     
             msg_list_to_export = msg_list_to_export & "(All)"
         

+ 4 - 10
source/modules/VCS_File.bas

@@ -248,9 +248,8 @@ Public Function UsingUcs2() As Boolean
     End If
     Close fn
     
-    Dim FSO As Object
-    Set FSO = CreateObject("Scripting.FileSystemObject")
-    FSO.DeleteFile (tempFileName)
+    On Error Resume Next
+    Kill tempFileName
 End Function
 
 Public Function ReadFile(filepath As String, Optional encoding As String = "utf-8") As String
@@ -279,14 +278,8 @@ Public Sub MakeFile(filepath As String, content As String, Optional encoding As
 
 End Sub
 
-
-
-
-
-
-
 ' Generate Random / Unique tempprary file name.
-Public Function TempFile(Optional ByVal sPrefix As String = "VBA") As String
+Public Function TempFile(Optional ByVal sPrefix As String = "oa") As String
     Dim sTmpPath As String * 512
     Dim sTmpName As String * 576
     Dim nRet As Long
@@ -296,6 +289,7 @@ Public Function TempFile(Optional ByVal sPrefix As String = "VBA") As String
     nRet = getTempFileName(sTmpPath, sPrefix, 0, sTmpName)
     If nRet <> 0 Then sFileName = Left$(sTmpName, InStr(sTmpName, vbNullChar) - 1)
     TempFile = sFileName
+    
 End Function
 
 Public Function IsValidFileName(ByVal sName As String) As Boolean

+ 11 - 3
source/modules/VCS_Table.bas

@@ -74,6 +74,8 @@ Err_LinkedTable_Fin:
     path = dirpath & to_filename(tbl_name) & ".LNKD"
     VCS_File.ConvertUcs2Utf8 tempFilePath, path
     
+    Kill tempFilePath
+    
     logger "ExportLinkedTable", "DEBUG", "LinkedTable " & tbl_name & " exported to " & path
     
     Exit Sub
@@ -438,9 +440,11 @@ next_field:
     
     Dim path As String
     path = obj_path & to_filename(tbl_name) & ".txt"
+    
     VCS_File.ConvertUcs2Utf8 tempFileName, path
+    
     logger "ExportTableData", "DEBUG", "Data from '" & tbl_name & "' exported to " & path
-    FSO.DeleteFile tempFileName
+    Kill tempFileName
     
     Exit Sub
 err:
@@ -528,11 +532,13 @@ Err_CreateLinkedTable_Fin:
     'CurrentDb.Execute sql
     run_sql sql
     
+    
     logger "ImportLinkedTable", "DEBUG", "LinkedTable " & tblName & " improted from " & obj_path & tblName & ".LNKD"
 
 Err_LinkPK_Fin:
     On Error Resume Next
     InFile.Close
+    Kill tempFilePath
     
 End Sub
 
@@ -626,7 +632,9 @@ Public Sub ImportTableDef(ByVal tblName As String, ByVal directory As String)
     Else
         logger "ImportTableData", "DEBUG", "TableDef '" & tblName & "' imported from " & filepath
     End If
-        
+    
+    On Error Resume Next
+    Kill tempFileName
 End Sub
 
 ' Import the lookup table `tblName` from `source\tables`.
@@ -691,7 +699,7 @@ Public Sub ImportTableData(ByVal tblName As String, ByVal obj_path As String)
     
     logger "ImportTableData", "DEBUG", "Table data '" & tblName & "' imported from " & path
 
-    FSO.DeleteFile tempFileName
+    Kill tempFileName
     Exit Sub
 err:
     logger "ImportTableData", "ERROR", "Table data '" & tblName & "' : Unable to import"

+ 1 - 1
source/tables/USysOpenAccess.txt

@@ -1,3 +1,3 @@
 key	val
 include_tables	USysOpenAccess,USysRegInfo
-sources_date	06/12/2016 14:30:17
+sources_date	06/12/2016 14:44:40

+ 1 - 2
tests/test.py

@@ -12,13 +12,12 @@ def _print_(*args):
 
 _print_("\n** PREPARATION **")
 
-_print_("\nWARNING: CLOSE ANY OPENED ACCESS PROJECT TO AVOID PROBLEMS")
+_print_("\nWARNING: CLOSE ANY OPENED ACCESS PROJECT TO AVOID UNEXPECTED PROBLEMS")
 
 for subdir in (".\\work", ".\\results"):
     if file.fexists(subdir):
         _print_("clean "+subdir)
         file.frmdir(os.path.abspath(subdir))
-        file.fmkdir(os.path.abspath(subdir))
     else:
         _print_("make dir "+subdir)
         file.fmkdir(os.path.abspath(subdir))