Book a Demo

Author Topic: Saving/backup vbscripts  (Read 9533 times)

George..Brennan

  • EA Novice
  • *
  • Posts: 13
  • Karma: +1/-0
    • View Profile
Saving/backup vbscripts
« on: October 04, 2018, 08:52:09 pm »
Currently looking at export/backup user VBS-Scripts from the repository to the file system.
Has anyone tried this?

G.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Saving/backup vbscripts
« Reply #1 on: October 04, 2018, 09:03:33 pm »
I wrote a script to do that.

https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Tools/Script%20Management/SaveAllScripts.vbs

This way I can manage my scripts in a version control system.

Geert

George..Brennan

  • EA Novice
  • *
  • Posts: 13
  • Karma: +1/-0
    • View Profile
Re: Saving/backup vbscripts
« Reply #2 on: October 04, 2018, 11:40:35 pm »
Thanks, Geert,

Just seen this, that's  an impressive and extensive body of code, I'll need time to review it before I can make real use of it - and learn some lessons  ;)

Meanwhile I've been diving in and taking a much less generic view with XML to handle the SQL, works for the moment.

FYI


option explicit

!INC Local Scripts.EAConstants-VBScript
!INC ESFA-ScriptLib.VBS-Utils
'
' Script Name: EA-Utils
' Author:  George Brennan (xxxxxxxxxxxx)
' Purpose: Export VBS scripts from the repository for versioning
' Assumes path of  of "{user}\Documents\VBS-Sparx\"
'
const basePath = "Documents\VBS-Sparx\" '-- root for output files
const dataNodes = "//EADATA//Dataset_0//Data//Row" '-- EA XML Elements
'
const K_GROUP2FOLDER = 0
const K_SCRIPT_FILE = 1
const K_SCRIPT_TEXT = 2
'
const K_DEBUG = true

main
sub main

   '-- prep for outputs
   dim wsh       : Set wsh = CreateObject("WScript.Shell")
    dim fso        : Set fso = CreateObject("Scripting.FileSystemObject")   
   dim userProfile : userProfile = wsh.ExpandEnvironmentStrings( "%userprofile%" )
   dim path       : path = userProfile & "\" & basePath
   dim filePathName
   
    '-- Make an EA repository SQL Call and parse the return set as a DOM tree
    dim SQL
    SQL =    "SELECT g.Script as ScriptGroup, " & _
         "       cast(s.Notes as xml).value('(Script/@Name)[1]', 'varchar(max)') as ScriptName, " & _
         "       s.[Script] " & _
         "  from t_script s " & _
         " inner join t_script g on s.ScriptAuthor = g.ScriptName " & _
         " where cast(s.Notes as xml).value('(Script/@Language)[1]', 'varchar(max)') = 'VBScript' "& _
         " order by g.Script " '-- by target folder
    dim doc : set doc = CreateObject("MSXML2.DOMDocument")
    doc.validateOnParse = False
    doc.async = False
    doc.loadXML(SQLQuery(SQL))

   '-- Traverse the DOMDocument and output each script as a file
    dim rowSet : Set rowSet = doc.selectNodes(dataNodes)
   For Each row In rowSet   
           
      '-- check group folder exists
      If not fso.FolderExists( path & row.childNodes(K_GROUP2FOLDER).text ) Then
         fso.CreateFolder( path & row.childNodes(K_GROUP2FOLDER).text )
      end if
      
      '-- build path/name and write file
      filePathName = path & row.childNodes(K_GROUP2FOLDER).text & "\" & row.childNodes(K_SCRIPT_FILE).text & ".vbs"
      dim oFile : Set oFile = fso.CreateTextFile( filePathName, True)            
      oFile.Write ( "'" & vbNewLine & "'-- exported : " & FormatDateTime(Now, vbGeneralDate) & vbNewLine & "'" & vbNewLine )
      oFile.Write (row.childNodes(K_SCRIPT_TEXT).text)
      oFile.Close    

      if K_DEBUG then Session.output(">> wrote: " & filePathName) end if

    Next 

end sub
'--


George

I wrote a script to do that.

https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Tools/Script%20Management/SaveAllScripts.vbs

This way I can manage my scripts in a version control system.

Geert
« Last Edit: October 04, 2018, 11:42:48 pm by George..Brennan »