예제 #1
0
	def testSwipeScreen(self):
		# swipe home screen 1000 times totally
		u.unlock()
		for i in range(100):
			direction = random.choice(['left','right'])
			step = random.randint(5,50)
			self._swipeScreen(direction,step)
			d.sleep(1)
예제 #2
0
파일: cron.py 프로젝트: noah-de/broctl
def doCron(watch):

    if config.Config.cronenabled == "0":
        return

    if not os.path.exists(os.path.join(config.Config.scriptsdir, "broctl-config.sh")):
        util.output("error: broctl-config.sh not found (try 'broctl install')") 
        return

    config.Config.config["cron"] = "1"  # Flag to indicate that we're running from cron.

    if not util.lock():
        return

    util.bufferOutput()

    if watch:
        # Check whether nodes are still running an restart if neccessary.
        for (node, isrunning) in control.isRunning(config.Config.nodes()):
            if not isrunning and node.hasCrashed():
                control.start([node])

    # Check for dead hosts.
    _checkHosts()

    # Generate statistics.
    _logStats(5)

    # Check available disk space.
    _checkDiskSpace()

    # Expire old log files.
    _expireLogs()

    # Update the HTTP stats directory.
    _updateHTTPStats()

    # Run external command if we have one.
    if config.Config.croncmd:
        (success, output) = execute.runLocalCmd(config.Config.croncmd)
        if not success:
            util.output("error running croncmd: %s" % config.Config.croncmd)

    # Mail potential output.
    output = util.getBufferedOutput()
    if output:
        util.sendMail("cron: " + output.split("\n")[0], output)

    util.unlock()

    config.Config.config["cron"] = "0"
    util.debug(1, "cron done")
예제 #3
0
파일: cron.py 프로젝트: sunchen92/OFM
def doCron(watch):

    if config.Config.cronenabled == "0":
        return

    config.Config.config[
        "cron"] = "1"  # Flag to indicate that we're running from cron.

    if not util.lock():
        return

    util.bufferOutput()

    if watch:
        # Check whether nodes are still running an restart if neccessary.
        for (node, isrunning) in control.isRunning(config.Config.nodes()):
            if not isrunning and node.hasCrashed():
                control.start([node])

    # Check for dead hosts.
    _checkHosts()

    # Generate statistics.
    _logStats(5)

    # Check available disk space.
    _checkDiskSpace()

    # Expire old log files.
    _expireLogs()

    # Update the HTTP stats directory.
    _updateHTTPStats()

    # Run external command if we have one.
    if config.Config.croncmd:
        execute.runLocalCmd(config.Config.croncmd)

    # Mail potential output.
    output = util.getBufferedOutput()
    if output:
        util.sendMail("cron: " + output.split("\n")[0], output)

    util.unlock()

    config.Config.config["cron"] = "0"
    util.debug(1, "cron done")
예제 #4
0
def train_model(num_epochs,
                freeze_layers_number,
                auto_load_finetune=False,
                visual=False):
    try:
        print("Training...")
        train.init()
        train.train(num_epochs,
                    freeze_layers_number,
                    auto_load_finetune=auto_load_finetune,
                    visual=visual)
    except Exception as e:
        print(e)
        traceback.print_exc()
    finally:
        print("finally")
        util.unlock()
예제 #5
0
파일: cron.py 프로젝트: ewust/telex
def doCron():

    if config.Config.cronenabled == "0":
        return

    if not util.lock():
        return

    util.bufferOutput()
    config.Config.config["cron"] = "1"  # Flag to indicate that we're running from cron.

    # Check whether nodes are still running an restart if neccessary.
    for (node, isrunning) in control.isRunning(config.Config.nodes()):
        if not isrunning and node.hasCrashed():
            control.start([node])

    # Check for dead hosts.
    _checkHosts()

    # Generate statistics. 
    _logStats(5)

    # Check available disk space.
    _checkDiskSpace()

    # Expire old log files.
    _expireLogs()

    # Update the HTTP stats directory. 
    _updateHTTPStats()

    # Run external command if we have one.
    if config.Config.croncmd:
        execute.runLocalCmd(config.Config.croncmd)

    # Mail potential output.
    output = util.getBufferedOutput()
    if output:
        util.sendMail("cron: " + output.split("\n")[0], output)

    config.Config.config["cron"] = "0"

    util.unlock()
예제 #6
0
def create_user_github(username, email):
    r = g.redis
    username = username.lower()

    if r.exists("username.to.id:" + username):
        return None, "Username exists, please try a different one."

    if not util.lock('create_user.' + username):
        return None, "Please wait some time before creating a new user."

    user_id = r.incr("users.count")
    auth_token = util.get_rand()
    now = int(time.time())

    pl = r.pipeline()
    pl.hmset(
        "user:%s" % user_id,
        {
            "id": user_id,
            "username": username,
            "ctime": now,
            "karma": config.UserInitialKarma,
            "about": "",
            "email": email,
            "auth": auth_token,
            "apisecret": util.get_rand(),
            "flags": "g",  #github user
            "karma_incr_time": now,
            "replies": 0,
        })

    pl.set("username.to.id:" + username, user_id)
    pl.set("auth:" + auth_token, user_id)

    pl.execute()
    util.unlock('create_user.' + username)

    return auth_token, None
예제 #7
0
파일: user.py 프로젝트: argolab/lusernews
def create_user(username, password, userip):
    r = g.redis
    username = username.lower()
    if r.exists("username.to.id:" + username):
        return None, "Username exists, please try a different one."

    if not util.lock('create_user.' + username):
        return None, "Please wait some time before creating a new user."

    user_id = r.incr("users.count")
    auth_token = util.get_rand()
    salt = util.get_rand()
    now = int(time.time())

    pl = r.pipeline()
    pl.hmset("user:%s" % user_id, {
            "id": user_id,
            "username": username,
            "salt": salt,
            "password": util.hash_password(password, salt),
            "ctime": now,
            "karma": config.UserInitialKarma,
            "about": "",
            "email": "",
            "auth": auth_token,
            "apisecret": util.get_rand(),
            "flags": "",
            "karma_incr_time": now,
            "replies": 0,
            })

    pl.set("username.to.id:" + username, user_id)
    pl.set("auth:" + auth_token, user_id)
    pl.execute()

    util.unlock('create_user.' + username)

    return auth_token, None
예제 #8
0
import time
import pause

from settings import settings

launchtime = time.time()

import util

rand = settings.rand

lastping = rand.prevping(launchtime)
nextping = rand.nextping(lastping)

if settings.cygwin:
    util.unlock()  # on cygwin may have stray lock files around.

# Catch up on any old pings.
cmd = os.path.join(settings.path, "launch.py")
if subprocess.call(cmd) != 0:
    print("SYSERR:", cmd, file=sys.stderr)

tdelta = datetime.timedelta(seconds=time.time() - lastping)
print("TagTime is watching you! Last ping would've been", tdelta, "ago.", file=sys.stderr)

start = time.time()
i = 1

while True:
    # sleep till next ping but check again in at most a few seconds in
    # case computer was off (should be event-based and check upon wake).
예제 #9
0
        elif not ln.strip():  # no tags in last line of log.
            # editor(settings.logf,
            # "TagTime Log Editor (add tags for last ping)")
            editorflag = True
        lstping = nxtping
        nxtping = rand.nextping(nxtping)
        # Here's where we would add an artificial gap of $nxtping-$lstping.
    if editorflag:
        editor(settings.logf, "TagTime Log Editor (fill in your RETRO pings)")
        # when editor finishes there may be new pings missed!
        # that's why we have the outer do-while loop here, to start over if
        # there are new pings in the past after we finish editing.
    if nxtping > time.time():
        break

util.unlock()

# SCHDEL (SCHEDULED FOR DELETION): (discussion and code for artificial gaps)
# It can happen that 2 pings can both occur since we last checked (a minute
# ago if using cron) which means that this script would notice them both *now*
# and ping you twice in a row with zero gap.  That's bad.
# This fixes that by checking if the next ping is overdue but not a
# retro-ping (ie, a *now* ping), in which case pause for the number of
# seconds between lstping and nxtping (but not more than retrothresh seconds).
# UPDATE: There were too many subtle corner cases with the above (like what
# if the computer was turned off (hibernating) while executing sleep()) so
# I got rid of it.
#
# We're now counting on this script being run within a
# couple seconds of each ping else all pings within retrothresh will come up
# with zero gap.
예제 #10
0
    util.set_samples_info()
    if not os.path.exists(config.trained_dir):
        os.mkdir(config.trained_dir)


def train(nb_epoch, freeze_layers_number):
    model = util.get_model_class_instance(
        class_weight=util.get_class_weight(config.train_dir),
        nb_epoch=nb_epoch,
        freeze_layers_number=freeze_layers_number)
    model.train()
    print('Training is finished!')


if __name__ == '__main__':
    try:
        args = parse_args()
        if args.data_dir:
            config.data_dir = args.data_dir
            config.set_paths()
        if args.model:
            config.model = args.model

        init()
        train(args.nb_epoch, args.freeze_layers_number)
    except Exception as e:
        print(e)
        traceback.print_exc()
    finally:
        util.unlock()
예제 #11
0
파일: run-test.py 프로젝트: gyagp/example
                    lines[lineIndex] = util.queuePrefix + ",".join(builds) + "\n"
                    util.writeStatus(lines)
                    return True

    return False


if __name__ == "__main__":
    os.chdir(sys.path[0])
    util.dlog("Start to run test")

    lockRunName = "lock-run"
    if util.hasLock(lockRunName):
        util.dlog("It's already running")
        quit()

    util.lock(lockRunName)

    hasUpdate = False
    while util.atomOp(getAvailable):
        hasUpdate = True
        if testMethod == "webmark":
            downloadBinary()
        runTest()
        util.atomOp(updateStatus)

    if not hasUpdate:
        util.dlog("Has no test to run")

    util.unlock(lockRunName)
예제 #12
0
	def testScreenLockUnlock(self):
		for i in range(100):
			# screen off
			d.screen.off()
			u.unlock()