Пример #1
0
 def default(self, line):
     args = shlex.split(line)
     if len(args) > 0 and not args[0].startswith("#"):  # ignore commented lines, ala Bash
         cmd = self._special_commands.get(args[0])
         if cmd:
             cmd(args[1:])
         else:
             print("Unknown command: %s" % (args[0]))
Пример #2
0
 def _doCommand(self, cmd, arg):
     try:
         if arg[0] in string.digits:
             cmd(string.atoi(arg))
         else:
             cmd(arg)
     except ValueError, err:
         print "Bad argument. Operation not performed."
         print err
Пример #3
0
	def _doCommand(self, cmd, arg):
		try:
			if arg[0] in string.digits:
				cmd(string.atoi(arg))
			else:
				cmd(arg)
		except ValueError, err:
			print "Bad argument. Operation not performed."
			print err
Пример #4
0
 def do_make(self, line):
     command, args, line = self.parseline(line)
     if command:
         cmd = getattr(self, 'make_' + command, None)
         if cmd is None:
             print("Cannot make %s" % (command, ))
         else:
             try:
                 cmd(self._make_attributes(args))
             except ValueError:
                 print(self._make_usage % (command, ))
     else:
         print(self._make_usage % ("|".join(self._makers), ))
Пример #5
0
 def do_make(self, line):
     command, args, line = self.parseline(line)
     if command:
         cmd = getattr(self, 'make_' + command, None)
         if cmd is None:
             print("Cannot make %s" % (command,))
         else:
             try:
                 cmd(self._make_attributes(args))
             except ValueError:
                 print(self._make_usage % (command,))
     else:
         print(self._make_usage % ("|".join(self._makers),))
Пример #6
0
    def do_demo(self, line):
        """ Optional wait_time float argument can be given.
    If given, waits that long before executing the rest of the demo.
    The demo consists of resetting both arms, then moving the right
    arm forwards, then up, then out, then in, then down, then backwards,
    then resetting both arms again.
    """
        if line != "":
            # Pause before executing to get setup for video
            wait_time = float(line)
            rospy.sleep(wait_time)

        arm = "right"
        cmd_list = [
            self.do_reset, self.do_forward, self.do_up, self.do_out,
            self.do_in, self.do_down, self.do_backward, self.do_reset
        ]
        for cmd in cmd_list:
            cmd(arm)
            rospy.sleep(1)
Пример #7
0
    def default(self, line):
        try:
            args = shlex.split(line)
        except ValueError:
            if not line.startswith("#"):
                self.show_output("No closing quotation")
            return False

        if len(args) > 0 and not args[0].startswith("#"):  # ignore commented lines, ala Bash
            cmd = self._special_commands.get(args[0])
            if cmd:
                return cmd(args[1:])
            else:
                similar = list(matches(self.all_commands, args[0], 0.85))
                if len(similar) == 1:
                    self.show_output("Unknown command, maybe you meant: %s", similar[0])
                elif len(similar) > 1:
                    options = ", ".join(similar[:-1])
                    options += " or %s" % (similar[-1])
                    self.show_output("Unknown command, maybe you meant: %s", options)
                else:
                    self.show_output("Unknown command: %s", args[0])

        return False
Пример #8
0
 def do_help(self, line):
     "help [command]"
     if line == '':
         cmdfuncs = [x for x in dir(self) if x.startswith('do_')]
         cmdfuncs.sort()
         # only print comments with a docstring
         for cmd in cmdfuncs:
             doc = getattr(self, cmd).__doc__
             if doc:
                 print "%s: %s" % (cmd[3:], doc.split('\n')[0])
     else:
         # call the help method if it exists
         cmd = getattr(self, 'help_%s' % (line.strip()), None)
         if cmd:
             return cmd()
         # otherwise print the docstring
         cmd = getattr(self, 'do_%s' % (line.strip()), None)
         if cmd:
             if cmd.__doc__:
                 print cmd.__doc__
             else:
                 print "%s: No help available" % (line)
         else:
             print "%s: Not a valid command"
Пример #9
0
say(1, "Now, I want you to connect to 'Steve_Waller_Security_Consultant'\nIt's case-sensitive so be sure to remember.\n")

raw_input("Press Enter to Continue")

say(2, "\nMost of the time.\n The computers will be password protected.\nYou can easily bypass it with the 'crack' command.\n")
say(1, "That won't completely do all the work for you but it'll make it easier.\nIt'll show you the amount of letters the password is along with hints \nof some letters contained.\n")

raw_input("Press Enter to Continue")

say(1, "Just type in a letter at a time to check if it's contained in the word.\nKind of like 'Hangman'\n")
say(1, "Now crack the password.")
say(1, "type: crack Steve_Waller_Security_Consultant\n")

while True:
	if cmd() == ["crack", "Steve_Waller_Security_Consultant"] : break

say(1, "\nNow that the password has been entered, you can connect to it.\n")
say(1, "You type it in this format: connect (name_of_computer)\nNow connect to Steve_Waller_Security_Consultant\n")
	
while True:
	if cmd() == ["connect", "Steve_Waller_Security_Consultant"] : break

say(1, "\nTo see all the files contained in the computer use the 'ls' command.\n")
say(1, "type: ls\n")

while True:
	if cmd() == ["ls"]: break

say(1, "\nTo read files use the 'cat' command\nfollowed by the file you want to read.\n")
say(1, "In this format: cat (name_of_file)\nTry reading SteveMail.hist.\n")
Пример #10
0
 def execute(self, cmd):
     if self.recording:
         self.makro.append(cmd)
     cmd()  # cmd.__call__()
Пример #11
0
 def do_playback(self, arg):
     for cmd in self.makro:
         cmd()
	def do_git(self,line):
		"""Very basic Git commands: init, stage, commit, clone, modified, branch"""
		from gittle import Gittle
		
		#TODO: These git functions all follow the same pattern.
		#Refactor these so they only contain their unique logic

		#TODO: If there is no ~/.gitconfig file, set up the username and password

		self.git_user = None
		self.git_email = None

		def git_init(args):
			if len(args) == 1:
				Gittle.init(args[0])
			else:
				print command_help['init']
		
		
		def git_status(args):
			if len(args) == 0:
				repo = Gittle('.')
				status = porcelain.status(repo.repo)
				print status

				#repo.diff_working()
				#repo.diff(diff_type='changes')
				#print repo.modified_files.intersection(repo.added_files) #repo.tracked_files.intersection(repo.added_files)
				#print repo.added_files
			else:
				print command_help['git_staged']

		def git_remote(args):
			'''List remote repos'''
			if len(args) == 0:
				repo = Gittle('.')
				for key, value in repo.remotes.items():
					print key, value
			else:
				print command_help['remote']

		def git_add(args):
			if len(args) > 0:
				repo = Gittle('.')
				repo.stage(args)
			else:
				print command_help['add']
				
		def git_rm(args):
			if len(args) > 0:
				repo = Gittle('.')
				repo.rm(args)
			else:
				print command_help['rm']

		def git_branch(args):
			if len(args) == 0:
				repo = Gittle('.')
				active = repo.active_branch
				for key, value in repo.branches.items():
					print ('* ' if key == active else '') + key, value
			else:
				print command_help['branch']

		def git_commit(args):
			if len(args) == 3:
				try:
					repo = Gittle('.')
					print repo.commit(name=args[1],email=args[2],message=args[0])
				except:
					print 'Error: {0}'.format(sys.exc_value)
			else:
				print command_help['commit']

		def git_clone(args):
			if len(args) > 0:
				url = args[0]

				#def clone(source, target=None, bare=False, checkout=None, config=None, opener=None, outstream=sys.stdout):
				repo = Gittle.clone(args[0], args[1] if len(args)>1 else '.', bare=False)

				#porcelain.clone(url, target='.')
				#repo = Gittle('.')

				#Set the origin
				config = repo.repo.get_config()
				config.set(('remote','origin'),'url',url)
				config.write_to_path()
			else:
				print command_help['clone']

		def git_pull(args):
			if len(args) <= 1:
				repo = Gittle('.')
				url = args[0] if len(args)==1 else repo.remotes.get('origin','')
				if url:
					repo.pull(origin_uri=url)
				else:
					print 'No pull URL.'
			else:
				print command_help['git pull']
				
				
				
		def git_push(args):
			import argparse
			parser = argparse.ArgumentParser(prog='git push'
											 , usage='git push [http(s)://<remote repo>] [-u username[:password]]'
											 , description="Push to a remote repository")
			parser.add_argument('url', type=str, nargs='?', help='URL to push to')
			parser.add_argument('-u', metavar='username[:password]', type=str, required=False, help='username[:password]')
			result = parser.parse_args(args)

			user, sep, pw = result.u.partition(':') if result.u else (None,None,None)

			repo = Gittle('.')

			#Try to get the remote origin
			if not result.url:
				result.url = repo.remotes.get('origin','')

			branch_name = os.path.join('refs','heads', repo.active_branch)  #'refs/heads/%s' % repo.active_branch

			print "Attempting to push to: {0}, branch: {1}".format(result.url, branch_name)

			if user:
				if not pw:
					pw = getpass.getpass('Enter password for {0}: '.format(user))

				opener = auth_urllib2_opener(None, result.url, user, pw)

				print porcelain.push(repo.repo, result.url, branch_name, opener=opener)
			else:
				print porcelain.push(repo.repo, result.url, branch_name)

		def git_modified(args):
			repo = Gittle('.')
			for mod_file in repo.modified_files:
				print mod_file

		def git_log(args):
			if len(args) <= 1:
				try:
					porcelain.log(max_entries=int(args[0]) if len(args)==1 else None)
				except ValueError:
					print command_help['log']
			else:
				print command_help['log']

#    def switch_branch(self, branch_name, tracking=None, create=None):
		def git_checkout(args):
			if len(args) == 1:
				repo = Gittle('.')
				repo.clean_working()
				#repo.checkout('refs/heads/{0}'.format(args[0]))
				repo.switch_branch('{0}'.format(args[0]))
			else:
				print command_help['checkout']

		def git_help(args):
			print 'help:'
			for key, value in command_help.items():
				print value

		#TODO: Alphabetize
		commands = {
		'init': git_init
		,'add': git_add
		,'rm': git_rm
		,'commit': git_commit
		,'clone': git_clone
		,'modified': git_modified
		,'log': git_log
		,'push': git_push
		,'pull': git_pull
		,'branch': git_branch
		,'checkout': git_checkout
		,'remote': git_remote
		,'status': git_status
		,'help': git_help
		}

		command_help = {
		'init':  'git init <directory> - initialize a new Git repository'
		,'add': 'git add <file1> .. [file2] .. - stage one or more files'
		,'rm': 'git rm <file1> .. [file2] .. - git rm one or more files'
		,'commit': 'git commit <message> <name> <email> - commit staged files'
		,'clone': 'git clone <url> [path] - clone a remote repository'
		,'modified': 'git modified - show what files have been modified'
		,'log': 'git log [number of changes to show] - show a full log of changes'
		,'push': 'git push [http(s)://<remote repo>] [-u username[:password]] - push changes back to remote'
		,'pull': 'git pull [http(s)://<remote repo>] - pull changes from a remote repository'
		,'checkout': 'git checkout <branch> - check out a particular branch in the Git tree'
		,'branch': 'git branch - show branches'
		,'status': 'git status - show status of files (staged, unstaged, untracked)'
		,'help': 'git help'
		}

		#git_init.__repr__ = "git init abc"

		args = self.bash(line)

		try:
			#Call the command and pass args
			cmd = commands.get(args[0] if len(args) > 0 else 'help','help')
			cmd(args[1:])
		except:
			#import traceback
			#traceback.print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)
			#traceback.print_tb(sys.exc_traceback)
			print 'Error: {0}'.format(sys.exc_value)
Пример #13
0
	def do_git(self,line):
		"""Very basic Git commands: init, stage, commit, clone, modified"""
		from gittle import Gittle

		def git_init(args):
			if len(args) == 1:
				Gittle.init(args[0])
			else:
				print command_help['init']

		def git_add(args):
			if len(args) > 0:
				repo = Gittle('.')
				repo.stage(args)
			else:
				print command_help['add']

		def git_commit(args):
			if len(args) == 3:
				try:
					repo = Gittle('.')
					print repo.commit(name=args[1],email=args[2],message=args[0])
				except:
					print 'Error: {0}'.format(sys.exc_value)
			else:
				print command_help['commit']

		def git_clone(args):
			if len(args) > 0:
				Gittle.clone(args[0], args[1] if len(args)>1 else '.', bare=False)
			else:
				print command_help['clone']

		def git_push(args):
			from gittle import GittleAuth
			if len(args) == 1 or len(args) == 3:
				if len(args) > 1:
					user = args[1]
					pw = args[2]
					repo = Gittle('.')
					print repo.push_to(args[0],username=user,password=pw)
				else:
					repo = Gittle('.', origin_uri=args[0])
					repo.push()
			else:
				print command_help['push']

		def git_modified(args):
			repo = Gittle('.')
			for mod_file in repo.modified_files:
				print mod_file

		def git_log(args):
			if len(args) == 0:
				repo = Gittle('.')
				print repo.log()
			else:
				print command_help['log']

		def git_help(args):
			print 'help:'
			for key, value in command_help.items():
				print value

		commands = {
		'init': git_init
		,'add': git_add
		,'commit': git_commit
		,'clone': git_clone
		,'modified': git_modified
		,'log': git_log
		,'push': git_push
		,'help': git_help
		}

		command_help = {
		'init': 'git init <directory>'
		,'add': 'git add <file1> .. [file2] ..'
		,'commit': 'git commit <message> <name> <email>'
		,'clone': 'git clone <url> [path]'
		,'modified': 'git modified'
		,'log': 'git log'
		,'push': 'git push http(s)://<remote repo> [username password]'
		,'help': 'git help'
		}

		#git_init.__repr__ = "git init abc"

		args = self.bash(line)

		try:
			#Call the command and pass args
			cmd = commands.get(args[0] if len(args) > 0 else 'help','help')
			cmd(args[1:])
		except:
			print 'Error: {0}'.format(sys.exc_value)
Пример #14
0
 def __call__(self):
     for cmd in self.cmds:
         cmd()
Пример #15
0
 def execute(self, cmd):
     if self.recording:
         self.makro.append(cmd)
     cmd()
Пример #16
0
def on_start():
	adminfile = open(ADMIN_MSG_FILE, 'a')
	cmd(r'/admin (.*)', on_cmd)
Пример #17
0
atexit.register(readline.write_history_file, histfile)

# Initialize shlex
import shlex

# Initialize pyjira
import pyjira
from cjconf import cjconf

cnf = cjconf()
j = pyjira.jira()

# Commands
import subprocess
from cmd import *
c = cmd(cnf)

def execute(L, p=None):
	L.whitespace_split = True
	token = L.get_token()
  
	try:
		c.command[token](L, j, p)
	except KeyError as e:
		v = str(e)
		if(v == "''"):
			pass
		else:
			print "Unknown command: " + v
	except cmdSyntax:
		print "Syntax error"
Пример #18
0
def run_and_read(ser, cmd, *args):
    ser.write(stuff(packetize(cmd(*args), elysium_apid)))
    return blocking_read(ser)
Пример #19
0
def run(ser, cmd, *args):
    ser.write(stuff(packetize(cmd(*args), elysium_apid)))
Пример #20
0
	def do_git(self,line):
		"""Very basic Git commands: init, stage, commit, clone, modified, branch"""
		from gittle import Gittle
		
		#TODO: These git functions all follow the same pattern.
		#Refactor these so they only contain their unique logic

		#TODO: If there is no ~/.gitconfig file, set up the username and password

		self.git_user = None
		self.git_email = None

		def git_init(args):
			if len(args) == 1:
				Gittle.init(args[0])
			else:
				print command_help['init']
				
		def git_status(args):
			if len(args) == 0:
				repo = Gittle('.')
				status = porcelain.status(repo.repo)
				print status

				#repo.diff_working()
				#repo.diff(diff_type='changes')
				#print repo.modified_files.intersection(repo.added_files) #repo.tracked_files.intersection(repo.added_files)
				#print repo.added_files
			else:
				print command_help['git_staged']

		def git_remote(args):
			'''List remote repos'''
			if len(args) == 0:
				repo = Gittle('.')
				for key, value in repo.remotes.items():
					print key, value
			else:
				print command_help['remote']

		def git_add(args):
			if len(args) > 0:
				repo = Gittle('.')
				repo.stage(args)
			else:
				print command_help['add']

		def git_branch(args):
			if len(args) == 0:
				repo = Gittle('.')
				active = repo.active_branch
				for key, value in repo.branches.items():
					print ('* ' if key == active else '') + key, value
			else:
				print command_help['branch']

		def git_commit(args):
			if len(args) == 3:
				try:
					repo = Gittle('.')
					print repo.commit(name=args[1],email=args[2],message=args[0])
				except:
					print 'Error: {0}'.format(sys.exc_value)
			else:
				print command_help['commit']

		def git_clone(args):
			if len(args) > 0:
				url = args[0]

				#def clone(source, target=None, bare=False, checkout=None, config=None, opener=None, outstream=sys.stdout):
				repo = Gittle.clone(args[0], args[1] if len(args)>1 else '.', bare=False)

				#porcelain.clone(url, target='.')
				#repo = Gittle('.')

				#Set the origin
				config = repo.repo.get_config()
				config.set(('remote','origin'),'url',url)
				config.write_to_path()
			else:
				print command_help['clone']


		def git_push(args):
			import argparse
			parser = argparse.ArgumentParser(prog='git push'
											 , usage='git push [http(s)://<remote repo>] [-u username[:password]]'
											 , description="Push to a remote repository")
			parser.add_argument('url', type=str, nargs='?', help='URL to push to')
			parser.add_argument('-u', metavar='username[:password]', type=str, required=False, help='username[:password]')
			result = parser.parse_args(args)

			user, sep, pw = result.u.partition(':') if result.u else (None,None,None)

			repo = Gittle('.')

			#Try to get the remote origin
			if not result.url:
				result.url = repo.remotes['origin']

			branch_name = os.path.join('refs','heads', repo.active_branch)  #'refs/heads/%s' % repo.active_branch

			print "Attempting to push to: {0}, branch: {1}".format(result.url, branch_name)

			if user:
				if not pw:
					pw = getpass.getpass('Enter password for {0}: '.format(user))

				opener = auth_urllib2_opener(None, result.url, user, pw)

				print porcelain.push(repo.repo, result.url, branch_name, opener=opener)
			else:
				print porcelain.push(repo.repo, result.url, branch_name)

		def git_modified(args):
			repo = Gittle('.')
			for mod_file in repo.modified_files:
				print mod_file

		def git_log(args):
			if len(args) <= 1:
				try:
					porcelain.log(max_entries=int(args[0]) if len(args)==1 else None)
				except ValueError:
					print command_help['log']
			else:
				print command_help['log']

#    def switch_branch(self, branch_name, tracking=None, create=None):
		def git_checkout(args):
			if len(args) == 1:
				repo = Gittle('.')
				#repo.checkout('refs/heads/{0}'.format(args[0]))
				repo.switch_branch('{0}'.format(args[0]))
			else:
				print command_help['checkout']

		def git_help(args):
			print 'help:'
			for key, value in command_help.items():
				print value

		#TODO: Alphabetize
		commands = {
		'init': git_init
		,'add': git_add
		,'commit': git_commit
		,'clone': git_clone
		,'modified': git_modified
		,'log': git_log
		,'push': git_push
		,'branch': git_branch
		,'checkout': git_checkout
		,'remote': git_remote
		,'status': git_status
		,'help': git_help
		}

		command_help = {
		'init':  'git init <directory> - initialize a new Git repository'
		,'add': 'git add <file1> .. [file2] .. - stage one or more files'
		,'commit': 'git commit <message> <name> <email> - commit staged files'
		,'clone': 'git clone <url> [path] - clone a remote repository'
		,'modified': 'git modified - show what files have been modified'
		,'log': 'git log [number of changes to show] - show a full log of changes'
		,'push': 'git push [http(s)://<remote repo>] [-u username[:password]] - push changes back to remote'
		,'checkout': 'git checkout <branch> - check out a particular branch in the Git tree'
		,'branch': 'git branch - show branches'
		,'status': 'git status - show status of files (staged, unstaged, untracked)'
		,'help': 'git help'
		}

		#git_init.__repr__ = "git init abc"

		args = self.bash(line)

		try:
			#Call the command and pass args
			cmd = commands.get(args[0] if len(args) > 0 else 'help','help')
			cmd(args[1:])
		except:
			#import traceback
			#traceback.print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)
			#traceback.print_tb(sys.exc_traceback)
			print 'Error: {0}'.format(sys.exc_value)
Пример #21
0
    def do_conf(self, params):
        """
\x1b[1mNAME\x1b[0m
        conf - Runtime configuration management

\x1b[1mSYNOPSIS\x1b[0m
        conf <describe|get|save|set> [args]

\x1b[1mDESCRIPTION\x1b[0m

        conf describe [name]

          describes the configuration variable [name], or all if no name is given.

        conf get [name]

          with a name given, it gets the value for the configuration variable. Otherwise, it'll
          get all available configuration variables.

        conf set <name> <value>

          sets the variable <name> to <value>.

        conf save

          persists the running configuration.

\x1b[1mEXAMPLES\x1b[0m
        > conf get
        foo: bar
        two: dos

        > conf describe foo
        foo is used to set the operating parameter for bar

        > conf get foo
        bar

        > conf set foo 2

        > conf get foo
        2

        > conf save
        Configuration saved.

        """
        conf = self._conf
        error = 'Unknown variable.'

        def get():
            if len(params.args) == 0:
                out = str(conf)
            else:
                out = conf.get_str(params.args[0], error)
            self.show_output(out)

        def setv():
            if len(params.args) != 2:
                raise ValueError
            cvar = conf.get(params.args[0])
            if cvar:
                cvar.value = params.args[1]
            else:
                self.show_output(error)

        def describe():
            if len(params.args) == 0:
                self.show_output(conf.describe_all())
            else:
                self.show_output(conf.describe(params.args[0], error))

        def save():
            if self.prompt_yes_no('Save configuration?'):
                if self._conf_store.save('config', self._conf):
                    self.show_output('Configuration saved')
                # FIXME: not dealing with failure now

        cmds = {
            'get': get,
            'describe': describe,
            'save': save,
            'set': setv,
        }

        cmd = cmds.get(params.cmd)
        if not cmd:
            raise ValueError
        cmd()