ArchiveAllTabs
ArchiveAllTabs
Obsolete - see version 1.3 below.
Here is a script to save all open tabs into a single zip file. Several items are configurable in the script to suit your tastes.
Thanks Jussi for the help.
Here is a script to save all open tabs into a single zip file. Several items are configurable in the script to suit your tastes.
Thanks Jussi for the help.
Last edited by mgag on Tue Sep 22, 2009 9:55 pm, edited 3 times in total.
I just found this zip utility that should work: http://gnuwin32.sourceforge.net/packages/zip.htm
ZIP
Yes, that is the one, I put a reference to it in the comments in the script - I will add the web page.
Version 1.1
Obosolete : see version 1.3 below.
Last edited by mgag on Tue Sep 22, 2009 9:55 pm, edited 2 times in total.
ArchiveAllTabs Update
# Version 1.2 - with Zeus 3.97, had to modify this line
# for the "erase" command,
# zeus.system(cmd, output_dir, 16 + 32 + 64)
# added "16", else cSpawn returns error code 2
# for the "erase" command,
# zeus.system(cmd, output_dir, 16 + 32 + 64)
# added "16", else cSpawn returns error code 2
Version 1.3: Can optionally use timestamped sub-directories to store archives of the open tabs in the editor. To enable sub-directorys (instead of Zip.exe), set ARCHIVE_USE_ZIP to "False".
Code: Select all
import zeus
import datetime
# makes a zip file of all the open tabs. useful if you want to take
# a snapshot of the workspace very quickly. Since it grabs all open tabs
# it makes an "atomic" backup (files are in "build" sync).
#
# Version 1.3 - Optionally use timestamped directories to store files
# rather than using ZIP.
# Version 1.2 - with Zeus 3.97, had to modify the "erase" command
# zeus.system(cmd, output_dir, 16 + 32 + 64)
# to add "16", else cSpawn returns error code 2
# Version 1.1 - changed "rm" to "erase" to remove old files
# - "rm" is not standard windows
# - added website for Zip.exe
# Version 1.0 - Initial release
#
# TODO List:
# 1. remove old archives after some time limit
# 2. add instruction on how to make this macro hook into File:Save
#
# For ZIP archives:
# =================
# See http://gnuwin32.sourceforge.net/packages/zip.htm
# The saved file is of the format: [prefix]YYYYMMDD_HH_MM_SS.zip
# where: [prefix] = optional user input prefix, see zipFilePrefix
# : YYYYMMDD_HH_MM_SS = Year, Month, Day, Hour, Minute, Second
#
# This script requires the zip.exe from Info-ZIP to be in the DOS search path.
# It should be easy enough to modify to use other command line archiving programs.
# To use ZIP archives, set ARCHIVE_USE_ZIP to "True"
ARCHIVE_USE_ZIP = True # true requires zip.exe from Info-ZIP
DEBUG = False # change to enable/disable debugging, Use Macros-Macro/Debug Output to view
def debug( str = ""):
if DEBUG:
zeus.debug_output( str )
def exec_command( cmd, directory, mode = 16 + 32 + 64):
debug(cmd+"\n")
zeus.system(cmd, directory, mode )
def key_macro():
ADDNOTE = True # dialog box to ask user to add a Note to archive
ADDZIPFILENAMEPREFIX = False # dialog box to ask user to add a prefix to zip file
noteFile = "note.txt" # optional notes file name
noteTextDefault = "" # default for user input note text
zipFilePrefixDefault = "" # default for user input zipfilename or directory name
zipFilePrefix = "" # optional prefix for the zip file or directory name
if DEBUG:
zeus.debug_enable()
zeus.screen_update_disable()
# select backup loacation, one of the following,
output_dir = zeus.macro_tag("$BD") # use Zeus backup directory
#output_dir = "e:\\archive\\" # path to archive directory here
debug("Using output_dir: %s\n" % output_dir)
file_list = []
# for each open tab, copy to the output_dir
origTabWindowID = zeus.get_window_id()
if origTabWindowID == -1:
# there are no open windows
return
while True: # python version of a do while loop
tabFileName = zeus.get_file_name().split("\\")[-1]
# duplicate filenames will get a unique prefix
if tabFileName in file_list:
file_list.append( "%d_%s" % (len(file_list),tabFileName) )
else:
file_list.append( tabFileName )
#create temporary copy of the tab file
myFile = open( str(output_dir+file_list[-1]), 'w')
count = zeus.get_line_count()
debug( "%d file:%s lineCount = %d \n" % (len(file_list),file_list[-1], count) )
zeus.debug_disable() # turn off debugging to mute the many get_line_text() calls
for line in range(count):
mystr = zeus.get_line_text(line+1) # 1-indexed
myFile.write( mystr+"\n" )
if DEBUG:
zeus.debug_enable()
myFile.close()
zeus.WindowNext()
if origTabWindowID == zeus.get_window_id():
# we have looped around all the tabs - time to quit
break
# get user note to add to archive
# TODO: when Zeus supports it, put ADDNOTE & ADDZIPFILENAMEPREFIX
# in the same dialog box.
if ADDNOTE:
note = zeus.user_input("Note:", noteTextDefault)
noteFile = output_dir+noteFile
if note or noteTextDefault:
myFile = open( noteFile, 'w')
file_list.append(noteFile.split("\\")[-1])
myFile.write( note+"\n" )
# could add a datetime stamp here, but already part of filename
myFile.close()
if ADDZIPFILENAMEPREFIX:
zipFilePrefix = zeus.user_input("zipFileNamePrefix", zipFilePrefixDefault)
if zipFilePrefix:
zipFilePrefix += "_"
if ARCHIVE_USE_ZIP:
# build the ZIP command to archive the files
zipFileName = zipFilePrefix + datetime.datetime.now().strftime("%Y%m%d_%X.zip ")
zipFileName = zipFileName.replace(":","_") # fix invalid char ":"
cmd = "zip " + zipFileName
for name in file_list:
cmd += name + " "
exec_command( cmd, output_dir )
else:
# copy all the files to the archive directory
# make a sub-directory to store the files
dirName = zipFilePrefix + datetime.datetime.now().strftime("%Y%m%d_%X")
dirName = dirName.replace(":","_") # fix invalid char ":"
cmd = "mkdir " + dirName
exec_command( cmd, output_dir )
debug( "Using output_dir: %s" % output_dir )
for name in file_list:
cmd = "copy " + name + " " + dirName
exec_command( cmd, output_dir )
# now remove all the temp files
cmd = "erase "
for name in file_list:
cmd += name + " "
#exec_command( cmd, output_dir )
if DEBUG:
zeus.debug_disable()
zeus.screen_update_enable()
zeus.screen_update()
key_macro() # run the macro
Jussij,
1. The archiveAllTabs.py script calls zeus.screen_update_disable() , however, I still see partial windows being drawn when the script executes. Is that expected?
2. Recall we discussed a problem with passing multiple fields to a dialog box, I believe you traced that to a python issue with zeus.user_input(); is there any progress on fixing that?
1. The archiveAllTabs.py script calls zeus.screen_update_disable() , however, I still see partial windows being drawn when the script executes. Is that expected?
2. Recall we discussed a problem with passing multiple fields to a dialog box, I believe you traced that to a python issue with zeus.user_input(); is there any progress on fixing that?
The archiveAllTabs.py script calls zeus.screen_update_disable(), however, I still see partial windows being drawn when the script executes. Is that expected?
The screen_update_disable function does not try to stop things like Windows painting, but rather it tries to stop redundant actions.
For example, consider the case where you do a simple find and replace. Zeus will first run a find to locate the text, it will then do a replace of the text found and finally it will scroll the document window to make sure text is correctly displayed on the screen.
In some instance the 'scroll the document window' step can be considered redundant (i.e. when doing a replace all for example) and it is these types of actions that the screen_update_disable tries to eliminate.
When I get some time I will take a look into this and see if it can be fixed2. Recall we discussed a problem with passing multiple fields to a dialog box, I believe you traced that to a python issue with zeus.user_input(); is there any progress on fixing that?

Cheers Jussi