コード例 #1
0
ファイル: hostaction.py プロジェクト: ArloZ/alfred-workflows
def do(query):
    action = query.split()[0]
    if util.command(action) == util.COMMAND_LS:
        name = query.split()[1]
        util.useHost(name)
        showMsg('Use host: ' + name)
    elif util.command(action) == util.COMMAND_DELETE:
        name = query.split()[1]
        util.deleteHost(name)
        showMsg('Delete host: ' + name)
    else:
        showMsg('Unknow command')
コード例 #2
0
def do(query):
    if util.command(query) == util.COMMAND_LS:
        items = listHosts()
    elif util.command(query) == util.COMMAND_OPEN:
        items = openHosts()
    elif util.command(query) == util.COMMAND_NEW:
        items = newHosts()
    elif util.command(query) == util.COMMAND_DELETE:
        items = deleteHosts()
    else:
        items = helpMsg()

    return alfredxml.genAlfredXML(items)
コード例 #3
0
ファイル: apps.py プロジェクト: siggame/server
 def command(**args):
     if self.game.current_player._connection != self:
         return {'type': 'failure',
                 'args': {'message': 'not your turn'}}
     if 'actor' not in args:
         command = getattr(self.game, command_name, None)
         if not command or not is_command(command):
             return {'type': 'error',
                 'args': {'message': 'global command %s does not exist' %
                     command_name
                     }}
     else:
         actor = self.game.objects.get(args['actor'], None)
         del args['actor']
         if not actor:
             return {'type': 'bad arguments',
                     'args': {'message': 'actor does not exist'}}
         command = getattr(actor, command_name, None)
         if not command or not is_command(command):
             return {'type': 'error',
                     'args': {'message': '%s does not have command %s' %
                         (actor.__class__.__name__, command_name)}}
     value = command(**args)
     self.game.flush()
     if not value:
         return {'type': 'success', 'args': {}}
     else:
         return value
コード例 #4
0
ファイル: run_test.py プロジェクト: wangzhenxa/Top1000APK
 def launchAPK(self, sn, apk):
     apk_cmp = apk
     logger(logname, sn + ": lunching %s" % apk_cmp)
     results = command("adb -s %s shell ' am start -W %s'" % (sn, apk_cmp),
                       timeout=30).strip().replace('\n', ';')
     if 'Complete' in results:
         return True
     else:
         return False
コード例 #5
0
def start():
    """
    Start the database.
    """
    if pid():
        return

    if not os.path.exists(os.path.join(conf.get('db_root'), 'metadata')):
        util.command('rethinkdb create -d ' + conf.get('db_root'))
    util.command('rethinkdb serve --config-file ' + conf.DB_FILE)

    start_time = time.time()
    while True:
        try:
            db.common.connect()
            break
        except r.errors.ReqlDriverError:
            time.sleep(1)
            if (time.time() - start_time) > MAX_TIME:
                raise DBTimeout()
コード例 #6
0
ファイル: statistics.py プロジェクト: joshuaevenson/spicerack
def report_feedback(userid):
    """
    """
    print "[statistics] Starting feedback send"
    fbpath = makepath('feedback.json')
    if not path_exists(fbpath):
        feedback = []
    else:
        feedback = jsonload(fbpath)
    if len(feedback) > 0:
        data = {'feedback' : feedback, 'userid' : userid}
        network_POST('/stats/report_feedback', data)
        jsondump(makepath('feedback.json'), [])
    print '[statistics] Finished feedback send'

    altpath = makepath('feedback.txt')
    if path_exists(altpath):
        feedback = fileload(altpath)
        data = {'feedback' : feedback, 'userid' : userid}
        network_POST('/stats/report_legacy_feedback', data)
        command('rm', altpath)
コード例 #7
0
    def run(self):
        if self.beforeAction:
            if self.beforParam:
                self.beforAction(self.beforParam)
            else:
                self.beforAction()

        sts, text = util.command(self.cmd, self.timeout)

        notify = -1
        if sts == 0:
            notify = self.notify()

        if self.afterAction:
            if self.afterParam:
                self.afterAction(self.afterParam)
            else:
                self.afterAction((sts, notify))
コード例 #8
0
 def run(self):
     if self.beforeAction:
         if self.beforParam:
             self.beforAction(self.beforParam)
         else:
             self.beforAction()
         
     sts,text =  util.command(self.cmd, self.timeout)
     
     notify = -1
     if sts == 0:
         notify = self.notify()
         
         
     if self.afterAction:
         if self.afterParam:
             self.afterAction(self.afterParam)
         else:
             self.afterAction((sts, notify))
コード例 #9
0
ファイル: apps.py プロジェクト: siggame/MegaMinerAI-i
 def command(**args):
     if self.game.current_player._connection != self:
         return {'type': 'failure',
                 'args': {'message': 'not your turn'}}
     if 'actor' not in args:
         return {'type': 'bad arguments',
                 'args': {'message': 'actor required'}}
     actor = self.game.objects.get(args['actor'], None)
     del args['actor']
     if not actor:
         return {'type': 'bad arguments',
                 'args': {'message': 'actor does not exist'}}
     command = getattr(actor, command_name, None)
     if not command or not is_command(command):
         return {'type': 'error',
                 'args': {'message': '%s does not have command %s' %
                     (actor.__class__.__name__, command_name)}}
     #TODO make sure command is a command function rather than a security compromise
     value = command(**args)
     self.game.flush()
     if not value:
         return {'type': 'success', 'args': {}}
     else:
         return value
コード例 #10
0
def systemRefresh():
    """
    Pull the system spices from github and create a new system.tar
    for the clients all to download.
    """
    log('UPDATING SYSTEM SPICE')

    goto_dir(makepath('spicerackclient'))
    command('git', 'pull')
    command('tar', '-cvf', makepath('system.tar)', 'system'))
    goto_dir(makepath(''))
    
    currentversion = dget('systemversion', 0)
    currentversion = 1 + int(currentversion)
    put('systemversion', currentversion)

    filewrite('systemversion.txt', str(currentversion))

    command('tar', '--append', '--file=system.tar', 'systemversion.txt')

    log('UPDATED SYSTEM SPICE TO VERSION: %s' % currentversion)
    return 'success'
コード例 #11
0
ファイル: test_util.py プロジェクト: starcraftman/new-awesome
def test_pid_alive():
    pid = util.command(TRAP_SH, wait=False)
    assert util.pid_alive(pid)
    util.pid_kill(pid)
    util.pid_wait_on(pid)
    assert not util.pid_alive(pid)
コード例 #12
0
ファイル: test_util.py プロジェクト: starcraftman/new-awesome
def test_pid_kill():
    pid = util.command(TRAP_SH, wait=False)
    assert tc.alive(pid)
    util.pid_kill(pid, signal.SIGKILL)
    util.pid_wait_on(pid)
    assert not tc.alive(pid)
コード例 #13
0
ファイル: test_util.py プロジェクト: starcraftman/new-awesome
def test_pid_wait_on_timeout():
    pid = util.command(TRAP_SH, wait=False)
    assert tc.alive(pid)
    with pytest.raises(OSError):
        util.pid_wait_on(pid)
コード例 #14
0
ファイル: test_util.py プロジェクト: starcraftman/new-awesome
def test_command_async():
    pid = util.command(TRAP_SH, wait=False)
    assert tc.alive(pid)
    util.pid_kill(pid)
    util.pid_wait_on(pid)
    assert not tc.alive(pid)
コード例 #15
0
def spiceMerge(spices, username):
    """
    Manages the merger of a spice into the development repository.

    @param spices: list of (spicename, dirname)
    """
    log('[spicemanager] In func:spiceMerge')
    goto_dir(makepath('spicerackdev'))
    command('git', 'pull')
    goto_dir(makepath(''))

    spice_to_metadata = {}
    for dirname in spices:
        data = jsonload(makepath('spicerackdev', dirname, 'metadata.json'))
        spicename = data['name']
        if 'spicename' not in data:
            data['spicename'] = spicename
        if 'width' not in data:
            data['width'] = 0
            data['height'] = 0
            data['dependencies'] = []

        Statsd.increment('spices.spicerackdev.%s' % spicename.replace(' ', '-'))

        mid = get('spice-id:%s' % spicename.replace(' ', '-'))
        if mid is None:
            mid = str(uuid.uuid4())
            put('spice-id:%s' % spicename.replace(' ', '-'), mid)

        log('[spicemanager] Processing %s %s' % (spicename, mid))

        version = 1 + int(dget('version:%s' % mid, 0))
        put('version:%s' % mid, version)
        log('[spicemanager] Version: %s' % version)

        spice_to_metadata[mid] = {
            'spicename' : data['spicename'],
            'gituser' : username,
            'author' : data['author'],
            'tagline' : data['description'],
            'description' : data['description'],
            'version' : version,
            'hotkey' : False,
            'main' : data['main'],
            'width' : data['width'],
            'height' : data['height'],
            'dependencies' : data['dependencies']
            }

        put('metadata:%s' % mid, spice_to_metadata[mid])
        
        jsondump(makepath('spicerackdev', dirname, 'metadata.json'), spice_to_metadata[mid])
                   
        # Tar the spice directory into /spices/{mid}.tar.gz
        command('tar', '-cvf', makepath('spices', '%s.tar.gz' % mid), makepath('spicerackdev', dirname))

        # Copy the icon file into /icons
        iconpath = makepath('spicerackdev', dirname, 'icon.png')
        command('cp', '-f', iconpath, makepath('icons', '%s.png' % mid))
        
        iconpath = makepath(dirname, 'icon.png')
        if not os.path.exists(iconpath):
            command('tar', '-cvf', makepath('spices', '%s.tar.gz' % mid), makepath('spicerackdev', dirname))
        else:
            iconpath = iconpath.strip('icon.png')
            command('tar',
                    '-cvf',
                    makepath('spices', '%s.tar.gz' % mid),
                    makepath('spicerackdev', dirname),
                    '--directory=%s' % iconpath,
                    'icon.png')

        goto_dir(makepath('spicerackdev'))
        command('git', 'stash')
        goto_dir(makepath(''))

        heroku_metadata = {
            'spicename' : data['spicename'],
            'gituser' : username,
            'author' : data['author'],
            'tagline' : data['description'],
            'description' : data['description'],
            'version' : version,
            'hotkey' : False,
            'main' : data['main']
            }

        log('HEROKU: %s %s', type(heroku_metadata), heroku_metadata)
        for key, val in heroku_metadata.iteritems():
            log('KEY %s VAL %s %s', key, type(val), val)

        resp, content = send_post({str(mid) : heroku_metadata}, '/spices/refresh')
        log('[spicemanager] Heroku response: %s' % str(resp))

    return 'success'
コード例 #16
0
ファイル: test_util.py プロジェクト: starcraftman/new-awesome
def test_command_dir():
    ndir = os.path.expanduser('~')
    ret = util.command('pwd', cwd=ndir)
    assert ret == (0, ndir + "\n")
コード例 #17
0
util.move_file('problem.ca.tex', 'problem.ca.tex.latin1')
os.system('iconv -f latin1 -t utf8 < problem.ca.tex.latin1 > problem.ca.tex')
util.del_file('problem.ca.tex.latin1')

handler = 'std'

source_modifier = 'none'
if util.file_exists('main.cc'):
    source_modifier = 'no_main'
if util.file_exists('tuples.txt'):
    util.del_file('tuples.txt')
    source_modifier = 'structs'
    
# we should add something for elastic checkers of I2.

title = util.command('grep Problema problem.ca.tex').split('Problema')[1].split('{')[1].split('}')[-2]

inf = '''title: %s
author: Professorat de P1
email: [email protected]
''' % (title)

util.write_file('problem.ca.yml', inf)


inf = '''handler: %s
source_modifier: %s
''' % (handler, source_modifier)

util.write_file('handler.yml', inf)
コード例 #18
0
ファイル: test_util.py プロジェクト: starcraftman/new-awesome
def test_command_sync():
    ret = util.command('echo "Hello"')
    assert ret == (0, "Hello\n")
コード例 #19
0
util.move_file('problem.es.tex', 'problem.es.tex.latin1')
os.system('iconv -f latin1 -t utf8 < problem.es.tex.latin1 > problem.es.tex')
util.del_file('problem.es.tex.latin1')

handler = 'std'

source_modifier = 'none'
if util.file_exists('main.cc'):
    source_modifier = 'no_main'
if util.file_exists('tuples.txt'):
    util.del_file('tuples.txt')
    source_modifier = 'structs'
    
# we should add something for elastic checkers of I2.

title = util.command('grep Problema problem.es.tex').split('Problema')[1].split('{')[1].split('}')[-2]
event = util.command('grep "{Prueba:}" problem.es.tex').split('{Prueba:}')[1].split('\\\\')[0]
author = util.command('grep "{Autor:}" problem.es.tex').split('{Autor:}')[1]

res = re.search("(1\d)",event)
if not res: res = re.search("(0\d)",event)
if res: date = res.group(1)
else:
  date = "??"
  print "  !!! UNKNOWN DATE !!! "

print "Title: %s" % title
print "Event: %s" % event
print "Date: 20%s" % date 
print "Author: %s" % author
print "  PLEASE CHECK THIS IS CORRECT; IF NOT, CHANGE problem.es.yml"