Open Files Auto Archive
Open Files Auto Archive
It would be nice to gather all the open files and store them in an archive - like a poor man's version control. Often one will try different solutions to a problem and as you move from one to the other, it would be nice to be able to save them, as a group (if more than one file which is typical).
I would envision something that could take all the current open files and store them in a zip file, with any kind of name, that auto increments each time, and/or some way of attaching a small message to store with the files as a note. So like you hit the key/menu item and a small window pops up with a text section, and the current defaults for the filename and location, and a OK/Cancel button.
Then later the person can use look at the zip files which will list the contained files - this is better than having a lot of files hanging around.
I would envision something that could take all the current open files and store them in a zip file, with any kind of name, that auto increments each time, and/or some way of attaching a small message to store with the files as a note. So like you hit the key/menu item and a small window pops up with a text section, and the current defaults for the filename and location, and a OK/Cancel button.
Then later the person can use look at the zip files which will list the contained files - this is better than having a lot of files hanging around.
Script
OKay so I am trying to write a script for this. Python is the target language. My attempt is below, but its not working and I may be going about this the wrong way. I thought I would jump from tab to tab and copy the contents of each file to a new file and save it.
1. Why don't I see the "print"s in the Maco debuging window (when I don't call screen_update_disable() )?
2. Once I have the text selected and copied, how can I save it into a file without having a dialog box appear? I tried passing the filename to MarkWriteToFile() but it doesn't accept a file.
1. Why don't I see the "print"s in the Maco debuging window (when I don't call screen_update_disable() )?
2. Once I have the text selected and copied, how can I save it into a file without having a dialog box appear? I tried passing the filename to MarkWriteToFile() but it doesn't accept a file.
Code: Select all
import zeus
output_dir = "e:\\test\\"
print "Start"
zeus.screen_update_disable()
file_list = []
i = 0
while zeus.get_file_name() not in file_list:
file_list.append(zeus.get_file_name())
print "%d file:%s" % (i,file_list[i])
zeus.MoveDocumentStart()
zeus.MarkBlockToggle()
zeus.MoveDocumentEnd()
zeus.MarkWriteToFile("e:\\test\\mg1" )
zeus.MarkBlockToggle()
zeus.WindowNext()
i+=1
zeus.screen_update_enable()
Script
Here is a better attemp, but still have a problem. zeus.get_line_text() is returning an integer (1) rather than string.
Code: Select all
import zeus
output_dir = "e:\\test\\"
file_list = []
i = 0
while zeus.get_file_name() not in file_list:
file_list.append(zeus.get_file_name())
myFile = open( str(output_dir+file_list[0]), 'w')
count = zeus.get_line_count()
mystr = zeus.get_line_text( 0, count )
myFile.write( mystr )
myFile.close()
zeus.WindowNext()
i+=1
Script
Now this looks like a blog. The problem with zeus.get_line_text() is it doesn't like zero as an index. Starting with 1 works.
No need to answer previous posts. When I get stuck again I will post, and/or when I finish.
No need to answer previous posts. When I get stuck again I will post, and/or when I finish.
All the indexes used by the macro scripting functions are one based. I will update the help to make sure this is clear.The problem with zeus.get_line_text() is it doesn't like zero as an index.
I am not overly familiar with Python but I don't think the get_line_text function will work the way you have it coded

When this function is called and more than one line is requested then the function returns multiple arguments.
For example the following Lua code use this function to get the first three lines of a file:
Code: Select all
function key_macro()
file_line1, file_line2, file_line3 = get_line_text(1, 3)
message_box(0, file_line1, count)
message_box(0, file_line2, count)
message_box(0, file_line3, count)
end
key_macro() -- run the macro
Here is my version of your macro:
Code: Select all
import zeus
def key_macro():
output_dir = "d:/temp/files/"
file_list = []
i = 0
while zeus.get_file_name() not in file_list:
full_file_name = zeus.macro_tag("$FileName")
zeus.debug_output(full_file_name)
file_list.append(full_file_name)
count = zeus.get_line_count()
file_name = zeus.macro_tag("$file")
new_file_name = output_dir + file_name
zeus.debug_output(new_file_name)
myFile = open(new_file_name, 'w')
for i in range(1, count + 1):
myFile.write(zeus.get_line_text(i))
myFile.write("\n")
myFile.close()
zeus.WindowNext()
i+=1
key_macro() # run the macro
Script
Thats precisely what I did.
Is there an API for a message box that gets some user input? In the zip file that gets created I want to include a notes file. I don't really want to open a new document - I think that would break up the flow of the macro. I would start with a Yes/No message box to ask user if they want to add a note, then I would open a message box for a note of ~100 characters - save that as a file that gets included into the zip file.
Is there an API for a message box that gets some user input? In the zip file that gets created I want to include a notes file. I don't really want to open a new document - I think that would break up the flow of the macro. I would start with a Yes/No message box to ask user if they want to add a note, then I would open a message box for a note of ~100 characters - save that as a file that gets included into the zip file.
Script
I am confused about importing other modules in macros. I tried importing os and it fails; ImportError: No module named os
My python install is at c:\python25
My python install is at c:\python25
Script
zeus.debug_output() doesn't seem to have the desired effect.
Script
Script is almost finished. I want to have two user inputs, but I am not doing something right. When I use two args I get None as the return value.
This is what I have, which works,
note = zeus.user_input("Note:", "")
This is what I want to do,
note = zeus.user_input("Note:", "","FileSuffix","")
But note is None. I would have expected a list.
This is what I have, which works,
note = zeus.user_input("Note:", "")
This is what I want to do,
note = zeus.user_input("Note:", "","FileSuffix","")
But note is None. I would have expected a list.
Here is an example of how to use the debug output:zeus.debug_output() doesn't seem to have the desired effect.
Code: Select all
import zeus
def key_macro():
zeus.screen_update_disable()
# Debug output can be turned on using the 'Debug tools..' option
# found in the General panel of the Options, Editor Options menu.
# But this is an easier way to turn on debug output
zeus.debug_enable()
# Use the Macros, Macro Debug Output menu to see the output
zeus.debug_output("this goes to the debug output...\n")
zeus.screen_update_enable()
zeus.screen_update()
key_macro() # run the macro
This is a historical thing. The original user input dialog only ever returned one value.I want to have two user inputs, but I am not doing something right.
But when the Lua scripting module was added, this function was extended to make use of Lua's feature of return mutiple values (i.e. see the get_line_text example shown earlier). So in a nutshell this feature will only work in Lua

It might be possible to extend this feature for the Python module, but since I don't do a lot of Python coding, I not even sure if something similar is even possible in Python

Cheers Jussi
Archive Script
Here is the current version of the Archive Tabs Script.
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).
#
# The saved file is of the format: [prefix]YYYYMMDD_HH_MM_SS.zip
# where: [prefix] = optional user input prefix
# : YYYYMMDD_HH_MM_SS = Year, Month, Day, Hour, Minute, Second
def debug( str = ""):
if 0: # change to enable/disable debugging
zeus.debug_enable()
zeus.debug_output( str )
zeus.debug_disable()
def key_macro():
output_dir = "e:\\archive\\" # path to archive directory here
noteFile = output_dir + "note.txt" # optional notes file name
noteTextDefault = "" # a default value will force a note to be saved
zipFilePrefix = "" # optional prefix for the zip file
zeus.screen_update_disable()
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" % (len(file_list),file_list[-1], count) )
for line in range(count):
mystr = zeus.get_line_text(line+1) # 1-indexed
myFile.write( mystr+"\n" )
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
note = zeus.user_input("Note:", noteTextDefault)
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()
# 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 + " "
debug(cmd)
zeus.system(cmd, output_dir, 32+64)
# now remove all the temp files
cmd = "rm "
for name in file_list:
cmd += name + " "
debug(cmd)
zeus.system(cmd, output_dir,32+64)
zeus.screen_update_enable()
zeus.screen_update()
key_macro() # run the macro
Last edited by mgag on Fri Jun 19, 2009 3:26 pm, edited 1 time in total.
I suspect this might be due to the fact that Zeus currently embeds Python 2.4 but I am not sureI tried importing os and it fails; ImportError: No module named os My python install is at c:\python25

As a test I created this script:
Code: Select all
import sys
#import os
import zeus
def key_macro():
zeus.screen_update_disable()
zeus.FileNew()
zeus.write("Executable: ", 0);
zeus.write(sys.executable);
zeus.write("\n\nModules: \n", 0);
for name in sys.builtin_module_names:
zeus.write(name + "\n", 0);
zeus.write("\n\nKeys: \n", 0);
for name in sys.modules.keys():
zeus.write(name + "\n", 0);
zeus.screen_update_enable()
zeus.screen_update()
key_macro() # run the macro
And sure enough the os module is not in the list.Executable: d:\Projects\zeus3.96\zeus\Debug\zeus.exe
Modules:
__builtin__
__main__
_bisect
_codecs
_codecs_cn
_codecs_hk
_codecs_iso2022
_codecs_jp
_codecs_kr
_codecs_tw
_csv
_heapq
_hotshot
_locale
_multibytecodec
_random
_sre
_subprocess
_symtable
_weakref
_winreg
array
audioop
binascii
cPickle
cStringIO
cmath
collections
datetime
errno
exceptions
gc
imageop
imp
itertools
marshal
math
md5
mmap
msvcrt
nt
operator
parser
regex
rgbimg
sha
signal
strop
struct
sys
thread
time
xxsubtype
zipimport
Keys:
zipimport
zeus
__builtin__
sys
__main__
exceptions
I suspect if you create a similar Python 2.5 script and ran it from the command line, you would get a different set of default modules.
Cheers Jussi