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
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']
-
if __name__ == '__main__':
-"""The playlist module provides :class:`Playlist` its subclass
+"""The `playlist` module provides a :class:`Playlist` and its subclass
:class:`FilePlaylist` for manipulating lists of
:class:`hooke.curve.Curve`\s.
"""
# ('review', True),
# ('showconvoluted', True),
# ('superimpose', True),
+ ('system', True),
# ('tutorial', True),
# ('viewer', True),
]
+class InfoCommand (Command):
+ """Execute a system command and report the output.
+ """
+ def __init__(self):
+ super(SystemCommand, self).__init__(
+ name='system',
+ arguments=[
+ Argument(
+ name='command', type='string', optional=False, count=-1,
+ help="""
+Command line to execute.
+""".strip())
+],
+ help=self.__doc__)
+
+ def _run(self, hooke, inqueue, outqueue, params):
+ os.system(params['command'])
+
+ 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
-"""Defines :class:`CutPlugin` and :class:`CutCommand`.
+"""The `cut` module provides :class:`CutPlugin` and
+:class:`CutCommand`.
"""
from ..command import Command, Argument, Failure
-"""Defines :class:`PlaylistPlugin` several associated
-:class:`hooke.plugin.Command`\s for handling :mod:`hooke.playlist`
-classes.
+"""The `playlist` module provides :class:`PlaylistPlugin` several
+associated :class:`hooke.command.Command`\s for handling
+:mod:`hooke.playlist` classes.
"""
import glob
--- /dev/null
+"""The `system` module provides :class:`SystemPlugin` and several
+associated :class:`hooke.command.Command`\s for interacting with the
+operating system and execution environment.
+"""
+
+import os
+import os.path
+import subprocess
+import sys
+
+from ..command import Command, Argument
+from ..plugin import Builtin
+
+
+class SystemPlugin (Builtin):
+ def __init__(self):
+ super(SystemPlugin, self).__init__(name='system')
+
+ def commands(self):
+ return [ListDirectoryCommand(), GetWorkingDirectoryCommand(),
+ ChangeDirectoryCommand(), SystemCommand()]
+
+
+class ListDirectoryCommand (Command):
+ """List the files in a directory.
+ """
+ def __init__(self):
+ super(ListDirectoryCommand, self).__init__(
+ name='ls', aliases=['dir'],
+ arguments=[
+ Argument(
+ name='path', type='path', default='.',
+ help="""
+Path to the directory whose contents get listed. Defaults to the
+current working directory.
+""".strip()),
+],
+ help=self.__doc__)
+
+ def _run(self, hooke, inqueue, outqueue, params):
+ outqueue.put('\n'.join(sorted(os.listdir(params['path']))))
+
+class GetWorkingDirectoryCommand (Command):
+ """Get the current working directory.
+ """
+ def __init__(self):
+ super(GetWorkingDirectoryCommand, self).__init__(
+ name='cwd', aliases=['pwd'], help=self.__doc__)
+
+ def _run(self, hooke, inqueue, outqueue, params):
+ outqueue.put(os.getcwd())
+
+class ChangeDirectoryCommand (Command):
+ """Change the current working directory.
+ """
+ def __init__(self):
+ super(ChangeDirectoryCommand, self).__init__(
+ name='cd',
+ arguments=[
+ Argument(
+ name='path', type='path', default='~',
+ help="""
+Path of the directory to change into. Default to the user's home
+directory.
+""".strip()),
+],
+ help=self.__doc__)
+
+ def _run(self, hooke, inqueue, outqueue, params):
+ os.chdir(os.path.expanduser(params['path']))
+
+class SystemCommand (Command):
+ """Execute a system command and report the output.
+ """
+ def __init__(self):
+ super(SystemCommand, self).__init__(
+ name='system',
+ arguments=[
+ Argument(
+ name='command', type='string', optional=False, count=-1,
+ help="""
+Command line to execute.
+""".strip()),
+],
+ help=self.__doc__)
+
+ def _run(self, hooke, inqueue, outqueue, params):
+ p = subprocess.Popen(
+ params['command'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout,stderr = p.communicate()
+ returncode = p.wait()
+ outqueue.put(stdout)
+ outqueue.put(stderr)