Exemple #1
0
def upload_package():
	import tempfile, tarfile, StringIO, sys
	import CREDENTIALS

	pkg_dir = args.get('package_dir')

	# prepare and upload package
	with tempfile.SpooledTemporaryFile(max_size=10240) as tf:
		tar = tarfile.open(fileobj=tf, mode='w:gz')
		tar.add(name=pkg_dir, arcname='.', recursive=True)
		tar.close()
	
		b = aws.s3.get_bucket(CREDENTIALS.bucket)
		if not b:
			b = s3conn.create_bucket(CREDENTIALS.bucket)
		k = b.get_key(CREDENTIALS.package)
		if not k:
			k = b.new_key(CREDENTIALS.package)

		print 'Uploading package %s:' % CREDENTIALS.package
		def report_progress(at, total):
			print '\r%d%%' % ((at/total)*100),
			sys.stdout.flush()
		k.set_contents_from_file(tf, cb=report_progress)
		print ' done'
 def countdown_refresh(self):
     if self.counter > 0:
         self.counter -= 1
         self.text_countdown.set_text(str(self.counter))
         gobject.timeout_add_seconds(1, self.countdown_refresh)
     else:
         self.text_countdown.set_text("All done!")
         commands.getstatusoutput(args.get().command)
         gtk.main_quit()
Exemple #3
0
def load_with_includes(filename, passthrough):
	ret = ''
	with open(filename, mode='rt') as cfile:
		for line in cfile:
			if line.startswith(include_flag):
				for var in passthrough:
					ret += '%s = %s\n' % (var, args.get(var))
			else:
				ret += line
	return ret
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("destroy", self.destroy)

        self.window.set_keep_above(True)
        self.window.show()

        vbox = gtk.VBox()
        vbox.show()
        self.window.add(vbox)

        t = args.get().message
        if t is None:
            t = "Remaining time :"

        self.text = gtk.Label(t)
        self.text.show()
        vbox.pack_start(self.text, False, True)

        self.text_countdown = gtk.Label("text_countdown")
        self.text_countdown.show()
        vbox.pack_start(self.text_countdown, False, True)

        self.cancel_button = gtk.Button("Cancel")
        self.cancel_button.connect("clicked", self.cancel_clicked)
        self.cancel_button.show()
        vbox.pack_start(self.cancel_button, False, True)

        pos = args.get().position
        if pos is not None:
            pos = pos.split(",")

            x = int(pos[0])
            y = int(pos[1])

            self.window.move(x, y)

        self.counter = int(args.get().countdown)
        gobject.timeout_add_seconds(1, self.countdown_refresh)
Exemple #5
0
def process_script():
	import os
	ret = ''
	filename = os.path.dirname(__file__) + os.sep + user_data_script_file
	with open(filename) as user_data:
		for line in user_data:
			if line.strip().startswith(include_prefix):
				ret += 'class CONFIG:\n'
				for value in config_to_include:
					ret += '\t%s = %s\n' % (value, repr(args.get(value)))
				ret += '\n'
			else:
				ret += line
	return ret
Exemple #6
0
def launch_local(user_data):
	import os, subprocess, sys, pwd
	homedir = pwd.getpwuid(os.getuid()).pw_dir
	tf = ScopedTemporaryFile(executable=True, dir=homedir)
	tf.file.writelines(user_data)
	tf.close()
	sys.stdout.flush()
	new_args = [tf.name, '--local']
	if args.get('debug'):
		new_args += ['--debug']
	try:
		errno = subprocess.check_call(args=new_args, cwd=homedir, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
	except KeyboardInterrupt:
		errno = 1
	exit(errno)
Exemple #7
0
def main():
	import sys
	do_launch = True

	if args.get('list_configurations'):
		for section in args.config.sections():
			print section
		return

	script = process_script()
	if args.get('script_only'):
		print script
		do_launch = False

	upload_package()
	if args.get('upload_only'):
		do_launch = False

	if do_launch:
		if args.get('local'):
			launch_local(user_data=script)
		else:
			request_response = launch_remote(user_data=script)
			print request_response
Exemple #8
0
	def build(self, h):
		## applies the selected style to the histogram h

		## note 
		if self.alist.has("note")  : self.note  = args.get("note") 
		elif self.defaults != []   : self.note  = self.defaults[1]
		else                       : self.note  = "cmsPrel"
	
		## grid 
		if self.alist.has("grid")  : self.grid  = args.get("grid")
		elif self.defaults != []   : self.grid  = self.defaults[2]
		else                       : self.grid  = "y"

		## scale
		if self.alist.has("scale") : self.scale = args.get("scale")
		elif self.defaults != []   : self.scale = self.defaults[3]
		else                       : self.scale = "lin"
		
		## norm
		if self.alist.has("norm")  : self.norm  = args.get("norm")
		elif self.defaults != []   : self.norm  = self.defaults[4]
		else                       : self.norm  = "norm"

		## errors
		if self.alist.has("errors"): self.norm  = args.get("norm")
		elif self.defaults != []   : self.norm  = self.defaults[4]
		else                       : self.norm  = "norm"

		
		#h = self.buildNote  (h)
		#h = self.buildGrid  (h)
		#h = self.buildScale (h)
		#h = self.buildNorm  (h)
		#h = self.buildErrors(h)

		return h
Exemple #9
0
import asyncio
from asyncio import Lock
import logging

import args
from args import Arguments
import sync


LOG_FORMAT = '[%(relativeCreated)6d %(levelname)10s \
%(filename)10s:%(lineno)4s %(funcName)15s() ] %(message)s'


async def connect(token: str, ip: str, port: int, lock: Lock) -> None:
    reader, writer = await asyncio.open_connection(ip, port)
    await sync.sync(token, reader, writer, lock)


def main(args: Arguments) -> None:
    logging.basicConfig(format=LOG_FORMAT, level=logging.INFO)

    loop = asyncio.get_event_loop()
    lock = Lock()
    loop.run_until_complete(connect(args.token, args.ip, args.port, lock))
    loop.close()


if __name__ == '__main__':
    args.DEFAULT_IP = '127.0.0.1'
    main(args.get())
Exemple #10
0
import numpy as np
import os
from os import listdir
from os.path import join
from PIL import Image, ImageOps
import random
import pyflow
from skimage import img_as_float
from random import randrange
import os.path
import args

FLAGS = args.get()


def is_image_file(filename):
    return any(
        filename.endswith(extension)
        for extension in [".png", ".jpg", ".jpeg"])


def load_img(filepath, nFrames, scale, other_dataset):
    seq = [i for i in range(1, nFrames)]
    #random.shuffle(seq) #if random sequence
    if other_dataset:
        target = modcrop(Image.open(filepath).convert('RGB'), scale)
        input = target.resize(
            (int(target.size[0] / scale), int(target.size[1] / scale)),
            Image.BICUBIC)

        char_len = len(filepath)
Exemple #11
0
import boto
import args
from ConfigParser import NoOptionError, NoSectionError

try:
	ec2 = boto.connect_ec2(aws_access_key=args.get('local_access_key', section='local'),
							aws_secret_access_key=args.get('local_secret_key', section='local'))
except NoOptionError, NoSectionError:
	ec2 = boto.connect_ec2()

try:
	s3 = boto.connect_s3(aws_access_key=args.get('local_access_key', section='local'),
							aws_secret_access_key=args.get('local_secret_key', section='local'))
except NoOptionError, NoSectionError:
	s3 = boto.connect_s3()

Exemple #12
0
 def sym_gen():
     mode = get(args.symbol_arg, 'mode', str, 'train')
     layout = get(args.symbol_arg, 'layout', str, 'NCHW')
     with Context(reset_counter=True, mode=mode, layout=layout):
         return args.symbol(**args.symbol_arg)
Exemple #13
0
        """
        self.already_run.append((sync, None))

    def can_sync_run(self, sync, args = None):
        """
        Return False if a sync should not be run, True otherwise
        """
        if sync.name in self.exclude:
            logger.debug('sync "%s" has been excluded', sync.name)
            return False
        if not self.allow_rerun and (sync, args) in self.already_run:
            logger.debug('sync "%s" (%s) has already been run', sync.name, args)
            return False
        return True


# run! run! run!
args = args.parse_args()
if args.get('verbosity'):
    logging.basicConfig(level=logging.DEBUG)

synctrex = Synctrex(**args)
config = args.get('config')
for config in utils.as_list(config):
    synctrex.load(config)

synctrex.prepare()
synctrex.run()


Exemple #14
0
import logger
import logging
import controller
import data
import time
import random
import json
from gevent import monkey

monkey.patch_all()
import gevent

import args

args.init({"port": 8000, "debug": False})
if args.get("debug"):
    logging.basicConfig(level=logging.DEBUG)
else:
    logging.basicConfig(level=logging.INFO)

app = Flask(__name__)
app.debug = args.get("debug")
app.config.update(SECRET_KEY=hashlib.sha1(os.urandom(24)).digest())

eventLogger = logger.EventLogger()
loxoneDevice = controller.LoxoneDevice()
# loxone controller works fine, just have to test registering the listeners and also making sure that sending message through the proxy method works

# singleton controllers
lightController = controller.LightController(loxoneDevice)
# sensor controllers
Exemple #15
0
def launch_remote(user_data):
	import StringIO, gzip
	from contextlib import closing

	# prepare gzipped user-data
	with closing(StringIO.StringIO()) as sio:
		with closing(gzip.GzipFile(fileobj=sio, mode='wb')) as zipper:
			zipper.write(user_data)
		zipped_user_data = sio.getvalue()

	if args.get('spot_instances'):
		requests = aws.ec2.request_spot_instances(
								price=args.get('price'),
								image_id=args.get('ami'),
								count=args.get('count'),
								instance_type=args.get('instance_type'),
								type=('persistent' if args.get('persistent') else 'one-time'),
								key_name=args.get('key_pair'),
								security_groups=args.get('security_groups'),
								user_data=zipped_user_data
								)
		return requests
	else:
		reservation = aws.ec2.run_instances(
								image_id=args.get('ami'),
								min_count=args.get('count'),
								max_count=args.get('count'),
								key_name=args.get('key_pair'),
								security_groups=args.get('security_groups'),
								instance_type=args.get('instance_type'),
								user_data=zipped_user_data
								)
		return reservation
Exemple #16
0
import numpy as np
import sys
import bvh
import freqfilter
import angle
import args
import spacefilter

ARGS = args.get()
INPUT = ARGS["-i"]
OUTPUT = ARGS["-o"]
FILTER = ARGS["--filter"]
if FILTER == "butterworth":
    ORDER = int(ARGS["--order"])
    U0 = int(ARGS["--u0"])
    BORDER = int(ARGS["--border"])
if FILTER == "gaussian":
    SIGMA = int(ARGS["--sigma"])
    BORDER = int(ARGS["--border"])
if FILTER == "average":
    M = int(ARGS["-m"])

bvh_file = bvh.read_file(INPUT)

for j in range(len(bvh_file["ROTATIONS"][0, :, 0])):
    for i in range(3):
        v = angle.floats_to_degrees(bvh_file["ROTATIONS"][:, j, i])
        p = angle.degrees_to_polars(v)
        if FILTER == "average": f_filtered = spacefilter.apply_average(p, M)
        else:
            f = freqfilter.fft(p, BORDER)
Exemple #17
0
#need two masks because red "wraps" around 180 in HSV color range
redLower1 = (0, 50, 50)
redUpper1 = (10, 255, 255)
redUpper2 = (170, 50, 50)
redUpper2 = (180, 255, 255)

#start getting video from PiCam
camera = PiCamera()
vs = cv2.VideoCapture(camera)
time.sleep(2.0)

# Algorithm to create masks for red and find x, y coordinates of center
while True:
    # record each frame
    frame = vs.read()
    frame = frame[1] if args.get("video", False) else frame

    # resize the frame, blur it, and convert it to the HSV
    # color space
    frame = imutils.resize(frame, width=600)
    blurred = cv2.GaussianBlur(frame, (11, 11), 0)
    hsv = cv2.cvtColor(blurred, cv2.COLOR_BGR2HSV)

    # construct a mask for the color "red", then perform
    # a series of dilations and erosions
    mask1 = cv2.inRange(hsv, redLower1, redUpper1)
    mask2 = cv2.inRange(hsv, redLower2, redUpper2)
    mask = mask1 + mask2
    mask = cv2.erode(mask, None, iterations=2)
    mask = cv2.dilate(mask, None, iterations=2)
            self.window.move(x, y)

        self.counter = int(args.get().countdown)
        gobject.timeout_add_seconds(1, self.countdown_refresh)

    def countdown_refresh(self):
        if self.counter > 0:
            self.counter -= 1
            self.text_countdown.set_text(str(self.counter))
            gobject.timeout_add_seconds(1, self.countdown_refresh)
        else:
            self.text_countdown.set_text("All done!")
            commands.getstatusoutput(args.get().command)
            gtk.main_quit()

    def cancel_clicked(self, sender):
        gtk.main_quit()

    def main(self):
        gtk.main()

if __name__ == "__main__":
    theme = args.get().theme
    if theme is not None:
        gtk.rc_parse(theme)

    app = App()
    app.main()

    sys.exit(args.get().command)