def getdest(identifier):
    diskinfo = get("ls -al /dev/disk/by-id/ | grep %s | grep -E '(sd)([a-z][0-9]+)'" % identifier)
    if diskinfo.strip() == "":
        print "No compatible device found, exiting"
        return None

    disk = re.search("sd[a-z]([0-9]+)", diskinfo).group()
    dirinfo = get("cat /etc/mtab | grep " + disk)
    dest = dirinfo.split(" ")[1]
    return dest
Example #2
0
def keyget():
    user = request.query.get('user')
    port = request.query.get('port')
    host = request.query.get('host')
    info = commands.get(user,host,port,'raw')
    
    return info
Example #3
0
def getHelpMessage():
    helpText = ''
    for key in commands:
        command = commands.get(key)
        helpText = helpText + command['command'] + f' --> ' + command[
            'description'] + '\n'
    return helpText
Example #4
0
def keyget():
    user = request.query.get('user')
    port = request.query.get('port')
    host = request.query.get('host')
    info = commands.get(user, host, port, 'raw')

    return info
Example #5
0
def on_get(bot, update):
    path = update.message.text[4:].strip()
    user = update.message.from_user['username']
    f, f_type = get(user, path)
    {
        'video': bot.sendVideo,
        'audio': bot.sendAudio,
        'image': bot.sendPhoto
    }.get(f_type, bot.sendDocument(update.message.chat_id, f,
                                   filename=path))(update.message.chat_id, f)
Example #6
0
def get_core():
	'''Check the idle node,then output the quantity'''
	global cor_len , core
	aa = get('cpu-free-thread | grep -e 56')[1]
	bb = aa.split("\n")
	for l in bb:
	    core.append(l[0:3]) 
	print "Available node:%s" % (core)
	if "" in core:
             core.remove("")
	cor_len = len(core)
	print "Number of available nodes:%s" % (cor_len)	
Example #7
0
def main():
    try:
        subcommand = sys.argv.pop(1)
    except IndexError:
        print parser.print_help()
        sys.exit()

    submodule = commands.get(subcommand, sys.modules[__name__])

    (options, args) = submodule.parser.parse_args(sys.argv[1:])

    submodule.handle(options, args)
Example #8
0
def main():
  try:
    subcommand = sys.argv.pop(1)
  except IndexError:
    print parser.print_help()
    sys.exit()

  submodule = commands.get(subcommand, sys.modules[__name__])

  (options, args) = submodule.parser.parse_args(sys.argv[1:])

  submodule.handle(options, args)
Example #9
0
    def interpreter(self, input):
        commands = self.getCommands()

        splitted = input.split(" ")
        command = splitted[0]
        try:
            value = splitted[1]
        except IndexError:
            value = -1

        try:
            return_value = commands.get(command, self.commandNotFound)(value)
        except ValueError, TypeError:
            return_value = "interpreter: unkown value"
Example #10
0
 def interpreter(self, input):
     commands = self.getCommands()
     
     splitted = input.split(" ")
     command = splitted[0]
     try:
         value = splitted[1]
     except IndexError:
         value = -1
         
     try:
         return_value = commands.get(command, self.commandNotFound)(value)
     except ValueError, TypeError:
         return_value = "interpreter: unkown value"
Example #11
0
def process(link):
    msg = parse.msg(link.read_msg())

    command_name = msg[0]
    args = msg[1]

    command = commands.get(command_name, None)

    if command is None:
        link.send_msg(gen.error(210001, "Unknown command '%s'" % command_name))
        return None

    print "found %s" % command_name
    # noinspection PyCallingNonCallable
    return command(link, args)
Example #12
0
def main():
	artist=get('dcop %s player artist'%amarokid).strip()
	title=get('dcop %s player title'%amarokid).strip()

	if title =='':
		searchstr=get('dcop %s player nowPlaying'%amarokid)+' lyrics'
	else :
		searchstr='''"'''+title+'''"'''+' '+artist+' lyrics'

	gs=GoogleSearch(searchstr)
	print 'Googling for ',searchstr
	gs.results_per_page=10
	try:
		results=gs.get_results()
	except:
		os.popen("dcop %s contextbrowser showLyrics '<lyric>Google.com is not accessible. Check your internet connection and retry</lyric>'"%amarokid)
		print 'google.com is not accessible'
		return ''

	xml=open('%s/tmp.xml'%user.home,'w')
	for res in results:
		lyric=getlyric(res.url.encode('utf8'),title)
		if lyric=='':
			pass
		else :
			print 'the lyric is:\n%s'%lyric
			xmldoc=xmlcorrect(lyric)
			xmldoc="""<lyric artist="%s" title="%s" page_url="%s" >"""%(artist,title,res.url.encode('utf8'))+xmldoc+'</lyric>'
			print >> xml, xmldoc
			xml.close()
			sh=open('%s/tmp.sh'%user.home,'w')
			print >> sh, "xml=$(cat ~/tmp.xml)"
			print >> sh, '''dcop %s contextbrowser showLyrics "${xml}"'''%amarokid
			sh.close()
			get("sh %s/tmp.sh"%user.home)
			break
Example #13
0
	def __init__(self):
		
		self.bus=dbus.SessionBus()
		self.gladefile="./Lyrical.glade"
		self.wTree = gtk.glade.XML(self.gladefile)
		self.wTree.get_widget("combobox1").append_text('Rhythmbox')
		self.wTree.get_widget("combobox1").append_text('Amarok 1.x')	
		try:
			self.last_used=((get("cat /var/log/Lyrical.log | grep last_playing")).split('\t')[1]).strip()
		except:
			self.last_used='Rhythmbox'

		
		dic={"on_combobox1_changed" : self.on_changed,
		     "on_mainwin_destroy" : gtk.main_quit}
		
		self.wTree.signal_autoconnect(dic)
		self.wTree.get_widget("mainwin").show()
Example #14
0
def main():
  try:
    subcommand = sys.argv.pop(1)
  except IndexError:
    parser.print_help(sys.stderr)
    sys.exit()

  if subcommand == "--version":
    print(__version__.__version__)
    sys.exit()

  submodule = commands.get(subcommand, sys.modules[__name__])

  (options, args) = submodule.parser.parse_args(sys.argv[1:])

  try:
    submodule.handle(options, args)
  except GrokCLIError as e:
    print >> sys.stderr, "ERROR:", e.message
    sys.exit(1)
Example #15
0
def main():
    try:
        subcommand = sys.argv.pop(1)
    except IndexError:
        parser.print_help(sys.stderr)
        sys.exit()

    if subcommand == "--version":
        print(__version__.__version__)
        sys.exit()

    submodule = commands.get(subcommand, sys.modules[__name__])

    (options, args) = submodule.parser.parse_args(sys.argv[1:])

    try:
        submodule.handle(options, args)
    except GrokCLIError as e:
        print >> sys.stderr, "ERROR:", e.message
        sys.exit(1)
Example #16
0
def main():
    global chat_buffer_q
    lock = threading.Lock()

    cdoc = open("commands.txt", 'r+')
    commands = {}
    for i in cdoc.readlines():
        j = i.split('|')
        commands[j[0]] = j[1].strip('\n')

    print(commands)

    s = connect()
    while True:
        try:
            with lock:
                ready_to_read, read_to_write, in_error = select.select([s],
                                                                       [s], [],
                                                                       5)
        except select.error:
            s = reconnect(s, "connection error")
            continue
        if len(ready_to_read) > 0:
            with lock:
                responses = s.recv(1024).decode("utf-8")
            if responses == "" or responses == "\r\n":
                s = reconnect(s, "connection f****d up")
                continue
            for response in responses.split('\r\n'):
                #print(response + "\n")
                if response == "PING :tmi.twitch.tv":
                    with lock:
                        s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
                    #print("Pong")
                else:
                    if response and "tmi.twitch.tv 353" not in response and "MODE #" not in response and "JOIN #" not in response and "PART #" not in response\
                            and "USERSTATE #" not in response and "ROOMSTATE #" not in response:
                        #print(response)
                        try:
                            username = re.search(r":\w+!",
                                                 response).group(0)[1:-1]
                        except AttributeError as e:
                            #print("ERROR" + e.args[0])
                            continue
                        else:
                            try:
                                userlvl = re.search(r"mod=\d",
                                                    response).group(0)[4]
                            except AttributeError as e:
                                #print("ERROR" + e.args[0])
                                pass
                            else:
                                try:
                                    chan = re.search(r"#\w+ ",
                                                     response).group(0)[1:-1]
                                except AttributeError as e:
                                    #print("ERROR" + e.args[0])
                                    continue
                                else:
                                    try:
                                        message = response.split(
                                            chan + " :", 1)[1]
                                    except IndexError as e:
                                        #print("ERROR: response truncated" + e.args[0])
                                        message = ""
                                        continue
                                    else:
                                        print(chan + "::" + username + ": " +
                                              message + "\n")
                        output = commands.get(message.strip('\r\n'))
                        if chan == cfg.NICK and output:
                            chat_buffer_q.put((chan, output))
    diskinfo = get("ls -al /dev/disk/by-id/ | grep %s | grep -E '(sd)([a-z][0-9]+)'" % identifier)
    if diskinfo.strip() == "":
        print "No compatible device found, exiting"
        return None

    disk = re.search("sd[a-z]([0-9]+)", diskinfo).group()
    dirinfo = get("cat /etc/mtab | grep " + disk)
    dest = dirinfo.split(" ")[1]
    return dest


dest = getdest("Nokia")
# dest='/media/External/test'

if dest == None:
    get("zenity --warning --text='No compatible device found, exiting'")
    sys.exit()

filelist = (
    get("zenity --file-selection --multiple --file-filter=*.m3u --title='Select the playlist'").strip().split("|")
)

for plist in filelist:
    print "list: ", plist

    playlist = plist

    songdir = dest + "/Sounds" + "/" + playlist.split("/")[-1][:-4]
    get("mkdir '%s'" % songdir)  # create a dest directory

    playlistdir = dest + "/Sounds" + "/Playlists"
Example #18
0
# appropriately.	       			       
#############################################################

# TO CHANGE:
# What abt stupid php/javascript rendered lyrics????
# ? add the tentative cluster item (the 1st item)?? It eliminates the unnecessary titles. added it. disallowing any other tag eliminates that possibility.
# But that creates problems with <p> tags within genuine lyrics.

from commands import getoutput as get
from search import GoogleSearch
from urllib import urlopen
import os
import user
import re

amarokid=get('dcop | grep amarok')

from getlyric import xmlcorrect,ascii_to_char,bylength,getlyric

def main():
	artist=get('dcop %s player artist'%amarokid).strip()
	title=get('dcop %s player title'%amarokid).strip()

	if title =='':
		searchstr=get('dcop %s player nowPlaying'%amarokid)+' lyrics'
	else :
		searchstr='''"'''+title+'''"'''+' '+artist+' lyrics'

	gs=GoogleSearch(searchstr)
	print 'Googling for ',searchstr
	gs.results_per_page=10
Example #19
0
File: oj.py Project: andyjjrt/oj
import argparse

from commands import login, update, submit, get

parser = argparse.ArgumentParser(
    prog="oj",
    description="CLI tool that helping you access CP Online Judge",
)
subcmd = parser.add_subparsers(dest='subcmd', help='methods', metavar='options')
subcmd.required = True

login_parser = subcmd.add_parser('login', help='Login to your oj accont')
update_parser = subcmd.add_parser('update', help='Update your contest and problem list')
submit_parser = subcmd.add_parser('submit', help='submit your hw code')
submit_parser.add_argument("assign_no", type=str, help="assignment number")
submit_parser.add_argument("file", type=str, help="code file")
get_parser = subcmd.add_parser('get', help='Get your assign sample code')
get_parser.add_argument("assign_no", type=str, help="assignment number")


args = parser.parse_args()
if args.subcmd == "login":
    login()
elif args.subcmd == "update":
    update()
elif args.subcmd == "submit":
    submit(args.assign_no, args.file)
elif args.subcmd == "get":
    get(args.assign_no)
Example #20
0
def main():
    global chat_buffer_q
    lock = threading.Lock()

    cdoc = open("commands.txt", 'r+')
    commands = {}
    for i in cdoc.readlines():
        j = i.split('|')
        commands[j[0]] = j[1].strip('\n')

    print(commands)

    s = connect()
    while True:
        try:
            with lock:
                ready_to_read, read_to_write, in_error = select.select([s],[s],[],5)
        except select.error:
            s = reconnect(s, "connection error")
            continue
        if len(ready_to_read) > 0:
            with lock:
                responses = s.recv(1024).decode("utf-8")
            if responses == "" or responses == "\r\n":
                s = reconnect(s, "connection f****d up")
                continue
            for response in responses.split('\r\n'):
                #print(response + "\n")
                if response == "PING :tmi.twitch.tv":
                    with lock:
                        s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
                    #print("Pong")
                else:
                    if response and "tmi.twitch.tv 353" not in response and "MODE #" not in response and "JOIN #" not in response and "PART #" not in response\
                            and "USERSTATE #" not in response and "ROOMSTATE #" not in response:
                        #print(response)
                        try:
                            username = re.search(r":\w+!", response).group(0)[1:-1]
                        except AttributeError as e:
                            #print("ERROR" + e.args[0])
                            continue
                        else:
                            try:
                                userlvl = re.search(r"mod=\d", response).group(0)[4]
                            except AttributeError as e:
                                #print("ERROR" + e.args[0])
                                pass
                            else:
                                try:
                                    chan = re.search(r"#\w+ ", response).group(0)[1:-1]
                                except AttributeError as e:
                                    #print("ERROR" + e.args[0])
                                    continue
                                else:
                                    try:
                                        message = response.split(chan + " :", 1)[1]
                                    except IndexError as e:
                                        #print("ERROR: response truncated" + e.args[0])
                                        message = ""
                                        continue
                                    else:
                                        print(chan + "::" + username + ": " + message + "\n")
                        output = commands.get(message.strip('\r\n'))
                        if chan == cfg.NICK and output:
                            chat_buffer_q.put((chan, output))