- #LOGGING, REPORTING, NOTETAKING
-
-
- def do_note_old(self,args):
- '''
- NOTE_OLD
- **deprecated**: Use note instead. Will be removed in 0.9
-
- Writes or displays a note about the current curve.
- If [anything] is empty, it displays the note, otherwise it adds a note.
- The note is then saved in the playlist if you issue a savelist command
- ---------------
- Syntax: note_old [anything]
-
- '''
- if args=='':
- print self.current_list[self.pointer].notes
- else:
- #bypass UnicodeDecodeError troubles
- try:
- args=args.decode('ascii')
- except:
- args=args.decode('ascii','ignore')
- if len(args)==0:
- args='?'
-
- self.current_list[self.pointer].notes=args
- self.notes_saved=0
-
-
- def do_note(self,args):
- '''
- NOTE
-
- Writes or displays a note about the current curve.
- If [anything] is empty, it displays the note, otherwise it adds a note.
- The note is then saved in the playlist if you issue a savelist command.
- ---------------
- Syntax: note_old [anything]
-
- '''
- if args=='':
- print self.current_list[self.pointer].notes
- else:
- if self.notes_filename == None:
- if not os.path.exists(os.path.realpath('output')):
- os.mkdir('output')
- self.notes_filename=raw_input('Notebook filename? ')
- self.notes_filename=os.path.join(os.path.realpath('output'),self.notes_filename)
- title_line='Notes taken at '+time.asctime()+'\n'
- f=open(self.notes_filename,'a')
- f.write(title_line)
- f.close()
-
- #bypass UnicodeDecodeError troubles
- try:
- args=args.decode('ascii')
- except:
- args=args.decode('ascii','ignore')
- if len(args)==0:
- args='?'
- self.current_list[self.pointer].notes=args
-
- f=open(self.notes_filename,'a+')
- note_string=(self.current.path+' | '+self.current.notes+'\n')
- f.write(note_string)
- f.close()
-
- def help_notelog(self):
- print '''
-NOTELOG
-Writes a log of the notes taken during the session for the current
-playlist
---------------
-Syntax notelog [filename]
-'''
- def do_notelog(self,args):
-
- if len(args)==0:
- args=linp.safeinput('Notelog filename?',['notelog.txt'])
-
- note_lines='Notes taken at '+time.asctime()+'\n'
- for item in self.current_list:
- if len(item.notes)>0:
- #FIXME: log should be justified
- #FIXME: file path should be truncated...
- note_string=(item.path+' | '+item.notes+'\n')
- note_lines+=note_string
-
- try:
- f=open(args,'a+')
- f.write(note_lines)
- f.close()
- except IOError, (ErrorNumber, ErrorMessage):
- print 'Error: notes cannot be saved. Catched exception:'
- print ErrorMessage
-
- self.notes_saved=1
-
- def help_copylog(self):
- print '''
-COPYLOG
-Moves the annotated curves to another directory
------------
-Syntax copylog [directory]
- '''
- def do_copylog(self,args):
-
- if len(args)==0:
- args=linp.safeinput('Destination directory?') #TODO default
-
- mydir=os.path.abspath(args)
- if not os.path.isdir(mydir):
- print 'Destination is not a directory.'
- return
-
- for item in self.current_list:
- if len(item.notes)>0:
- try:
- shutil.copy(item.path, mydir)
- except (OSError, IOError):
- print 'Cannot copy file. '+item.path+' Perhaps you gave me a wrong directory?'
-
-#OUTLET management
-#-----------------
- def do_outlet_show(self,args):
- '''OUTLET_SHOW
- ---------
- Shows current content of outlet with index for reference
- '''
- self.outlet.printbuf()
-
- def do_outlet_undo(self, args):
- '''OUTLET_UNDO
- ---------
- Eliminates last entry in outlet
- '''
- print 'Erasing last entry'
- self.outlet.pop()
-
- def do_outlet_delete(self, args):
- '''OUTLET_DELETE
- Eliminates a particular entry from outlet
- Syntax: outlet_delete n
- '''
- if len(args)==0:
- print 'Index needed!, use outlet_show to know it'
- else:
- self.outlet.delete(args)
-
-#OS INTERACTION COMMANDS
-#-----------------
- def help_dir(self):
- print '''
-DIR, LS
-Lists the files in the directory
----------
-Syntax: dir [path]
- ls [path]
- '''
- def do_dir(self,args):
-
- if len(args)==0:
- args='*'
- print glob.glob(args)
-
- def help_ls(self):
- self.help_dir(self)
- def do_ls(self,args):
- self.do_dir(args)
-
- def help_pwd(self):
- print '''
-PWD
-Gives the current working directory.
-------------
-Syntax: pwd
- '''
- def do_pwd(self,args):
- print os.getcwd()
-
- def help_cd(self):
- print '''
-CD
-Changes the current working directory
------
-Syntax: cd
- '''
- def do_cd(self,args):
- mypath=os.path.abspath(args)
- try:
- os.chdir(mypath)
- except OSError:
- print 'I cannot access that directory.'
-
-
- def help_system(self):
- print '''
-SYSTEM
-Executes a system command line and reports the output
------
-Syntax system [command line]
- '''
- pass
- def do_system(self,args):
- waste=os.system(args)
-
- def do_debug(self,args):
- '''
- this is a dummy command where I put debugging things
- '''
- print self.config['plotmanips']
- pass
-
- def help_current(self):
- print '''
-CURRENT
-Prints the current curve path.
-------
-Syntax: current
- '''
- def do_current(self,args):
- print self.current.path
-
- def do_info(self,args):
- '''
- INFO
- ----
- Returns informations about the current curve.
- '''
- print 'Path: ',self.current.path
- print 'Experiment: ',self.current.curve.experiment
- print 'Filetype: ',self.current.curve.filetype
- for plot in self.current.curve.default_plots():
- for set in plot.vectors:
- lengths=[len(item) for item in set]
- print 'Data set size: ',lengths
-
- def do_version(self,args):
- '''
- VERSION
- ------
- Prints the current version and codename, plus library version. Useful for debugging.
- '''
- print 'Hooke '+__version__+' ('+__codename__+')'
- print 'Released on: '+__releasedate__
- print '---'
- print 'Python version: '+python_version
- print 'WxPython version: '+wx_version
- print 'wxMPL version: '+wxmpl_version
- print 'Matplotlib version: '+mpl_version
- print 'SciPy version: '+scipy_version
- print 'NumPy version: '+numpy_version
- print '---'
- print 'Platform: '+str(platform.uname())
- print '---'
- print 'Loaded plugins:',self.config['loaded_plugins']
-
- def help_exit(self):
- print '''
-EXIT, QUIT
-Exits the program cleanly.
-------
-Syntax: exit
-Syntax: quit
-'''
- def do_exit(self,args):
- we_exit='N'
-
- if (not self.playlist_saved) or (not self.notes_saved):
- we_exit=linp.safeinput('You did not save your playlist and/or notes. Exit?',['n'])
- else:
- we_exit=linp.safeinput('Exit?',['y'])
-
- if we_exit[0].upper()=='Y':
- wx.CallAfter(self.frame.Close)
- sys.exit(0)
- else:
- return
-
-
-
-if __name__ == '__main__':
- mycli=HookeCli(0)
- mycli.cmdloop()