(pcluster.py) again, dirty stuff for testing
[hooke.git] / macro.py
index acb25ce675978c0e28a287c903c71bf8ab63b156..bdeafabe7f9f191981116c26320466e8127006dd 100644 (file)
--- a/macro.py
+++ b/macro.py
@@ -8,7 +8,9 @@ Records, saves and executes batches of commands
 '''
 
 import libhookecurve as lhc
+import libinput as linput
 import os.path
+import string
 
 class macroCommands:
 
@@ -21,15 +23,15 @@ class macroCommands:
        def _plug_init(self):
                self.currentmacro=[]
                self.auxprompt=self.prompt
-               self.macrodir=os.curdir
+               self.macrodir=self.config['workdir']
                if not os.path.exists(os.path.join(self.macrodir,'macros')):
                     try:
                         os.mkdir('macros')
-                        self.macrodir=os.path.join(self.macrodir,'macros')
                     except:
-                       print 'Warning: cannot create macros folder.'
+                        print 'Warning: cannot create macros folder.'
                         print 'Probably you do not have permissions in your Hooke folder, use macro at your own risk.'
-       
+                self.macrodir=os.path.join(self.macrodir,'macros')
+
        def collect(self):
                                
                print 'Enter STOP / PAUSE to go back to normal mode\nUNDO to remove last command'
@@ -88,7 +90,7 @@ class macroCommands:
                        self.pause=0
                        self.prompt=self.auxprompt
                        if len(self.currentmacro) != 0: 
-                               answer=raw_input('Do you want to save this macro? ')
+                               answer=linput.safeinput('Do you want to save this macro? ',['y'])
                                if answer[0].lower() == 'y':
                                        self.do_savemacro('')
                                else:
@@ -104,7 +106,7 @@ class macroCommands:
                                self.collect()  
                        else:
                                if len(self.currentmacro) != 0: 
-                                       answer=raw_input('Another macro is already beign recorded\nDo you want to save it?')
+                                       answer=linput.safeinput('Another macro is already beign recorded\nDo you want to save it?',['y'])
                                        if answer[0].lower() == 'y':
                                                self.do_savemacro('')
                                        else:
@@ -128,13 +130,13 @@ class macroCommands:
                        print 'No macro is being recorded!'
                        return 0
                if len(macroname)==0: 
-                       macroname=raw_input('Enter new macro name: ')
+                       macroname=linput.safeinput('Enter new macro name: ')
                        if len(macroname) == 0:
                                print 'Invalid name'
                                
                macroname=os.path.join(self.macrodir,macroname+'.hkm')
                if os.path.exists(macroname):
-                       overwrite=raw_input('That name is in use, overwrite?')
+                       overwrite=linput.safeinput('That name is in use, overwrite?',['n'])
                        if overwrite[0].lower()!='y':
                                print 'Cancelled save'
                                return 0
@@ -174,7 +176,7 @@ class macroCommands:
                        return 0
                args=args.split()
 
-               print 'args ' + ' '.join(args)
+               #print 'args ' + ' '.join(args)
                
                if len(args)>1:
                        if args[1] == 'playlist':
@@ -185,12 +187,12 @@ class macroCommands:
                        else:
                                if args[1] == 'v':
                                        verbose=1       
-               print cycle
-               print verbose   
+               #print cycle
+               #print verbose  
 
                macropath=os.path.join(self.macrodir,args[0]+'.hkm')
                if not os.path.exists(macropath):
-                       print 'Could not find a macro with that name'
+                       print 'Could not find a macro named '+macropath
                        return 0
                txtfile=open(macropath)
                if cycle ==1: 
@@ -216,12 +218,12 @@ class macroCommands:
                        for command in txtfile:
                                        testcmd=command.split()
                                        w=0
-                                       if verbose==1:
-                                               print 'Executing command '+command
                                        for word in testcmd:
                                                if word=='__curve__':
-                                                       testcmd[w]=os.path.splitext(os.path.basename(self.current.path))[0]
-                                               w=w+1
+                                                       w=w+1
+                                                       testcmd[w]=os.path.splitext(os.path.basename(self.current.path))[0]+'-'+string.lstrip(os.path.splitext(os.path.basename(self.current.path))[1],'.')
+                                       if verbose==1:
+                                               print 'Executing command '+' '.join(testcmd)
                                        self.onecmd(' '.join(testcmd))