コード例 #1
0
ファイル: controllers.py プロジェクト: ozw1z5rd/gdg-pescara
    def openCapsule(TSCid=None, lat=None, lng=None, password=None, user=None):
        """
		openCapsule will assign the capsule is mode is not anonymous 
		and then will return to caller
		Is capsule is anonymous or already assigned, it will try to open it
		"""
        L.info("openCapsule Called")
        L.debug({
            'dumping parameters': '',
            'TSCid': TSCid,
            'lat': lat,
            'lng': lng,
            'pwd len': len(password) if password is not None else -1,
            'user': user
        })
        # capsule not found
        tsc = TimespaceCapsule.getByTSCid(TSCid)
        if tsc is None:
            return (TSCController.TSCCTRL_BADTSCID, None)
        # if not anonymous here we require a valid user.
        if not tsc.anonymous and tsc.user is None:
            if user is None:
                return (TSCController.TSCCTRL_BADUSER, None)
            L.info("TSC is not anonymous, binding ...")
            L.info(user)
            tsc.assignToUser(user)
            return (TSCController.TSCCTRL_ASSIGNED, None)

        # try to open
        L.info("try to disclose")
        response = tsc.disclose(lat=lat, lng=lng, user=user, password=password)
        return (TSCController.TSCCTRL_OK, response)
コード例 #2
0
def read_text(path):
    L.debug("read_text" + os.path.abspath(path))
    f = open(path, "r")
    if f.mode == 'r':
        contents = f.read()
        f.close()
        return contents
    f.close()
    return ''
コード例 #3
0
def save(json_content, path):
    path = abs_path(path)
    # json_content = {}
    # for key, value in json_content.iteritems():
    #     print("key: {} | value: {}".format(key, value))
    # content = pattern_save.replace("@content", json.dumps(json_content, indent=4))

    content = pattern_save.replace("@content", json_stringify(json_content))
    write(path, content)
    L.debug("success => save to file:" + path)
コード例 #4
0
ファイル: controllers.py プロジェクト: ozw1z5rd/gdg-pescara
    def radar(TSCid=None, lat=None, lng=None):
        """
		Return how meters are we far away the capsule.
		"""
        L.info("radar Called")
        L.debug({'TSCid': TSCid, 'lat': lat, 'lng': lng})
        tsc = TimespaceCapsule.getByTSCid(TSCid)
        if tsc is None:
            return (TSCController.TSCCTRL_BADTSCID, None)
        return (TSCController.TSCCTRL_OK, tsc.distance(lat, lng))
コード例 #5
0
ファイル: controllers.py プロジェクト: ozw1z5rd/gdg-pescara
	def addCapsule(
			openingDate=None,
			closingDate=None,
			lat=None,
			lng=None,
			tll=0, 
			anonymous=True, 
			encrypt=False, 
			user=None,
			content=None,
			password=None
		):
		"""
		Add a new capsule
		Create a new capsule and assign it to current user ( owner )
		content is uniencoded
		in : all the defining capsule parameters
		out : TSCid if ok, None otherwise
		"""
		L.info("addCapsule called")
		L.debug({
			'openingDate' : openingDate, 
			'closingDate' : closingDate, 
			'lat' : lat,
			'lng' : lng, 
			'ttl' : tll,
			'anonymous' : anonymous,
			'encrypt' : encrypt,
			'user' : user,
			'content' : content, 
			'pwd len' : len(password) if password is not None else -1
		})
		try:
			tsc = \
				TimespaceCapsule(
					openingDate = openingDate,
					closingDate = closingDate,
					content = content,
					positionLat = lat,
					positionLng = lng,
					positionTll = tll,
					anonymous = anonymous,
					owner = user,
					encrypt = encrypt,
					password = password 
				)
			tsc.put()
		except Exception as e:
			L.warning("Got exception!")
			L.exception(e)
			return None
		else:
			L.info("Capsule created")
			return tsc.TSCid
コード例 #6
0
ファイル: controllers.py プロジェクト: ozw1z5rd/gdg-pescara
    def addCapsule(openingDate=None,
                   closingDate=None,
                   lat=None,
                   lng=None,
                   tll=0,
                   anonymous=True,
                   encrypt=False,
                   user=None,
                   content=None,
                   password=None):
        """
		Add a new capsule
		Create a new capsule and assign it to current user ( owner )
		content is uniencoded
		in : all the defining capsule parameters
		out : TSCid if ok, None otherwise
		"""
        L.info("addCapsule called")
        L.debug({
            'openingDate': openingDate,
            'closingDate': closingDate,
            'lat': lat,
            'lng': lng,
            'ttl': tll,
            'anonymous': anonymous,
            'encrypt': encrypt,
            'user': user,
            'content': content,
            'pwd len': len(password) if password is not None else -1
        })
        try:
            tsc = \
             TimespaceCapsule(
              openingDate = openingDate,
              closingDate = closingDate,
              content = content,
              positionLat = lat,
              positionLng = lng,
              positionTll = tll,
              anonymous = anonymous,
              owner = user,
              encrypt = encrypt,
              password = password
             )
            tsc.put()
        except Exception as e:
            L.warning("Got exception!")
            L.exception(e)
            return None
        else:
            L.info("Capsule created")
            return tsc.TSCid
コード例 #7
0
ファイル: controllers.py プロジェクト: ozw1z5rd/gdg-pescara
	def radar( TSCid=None, lat=None, lng=None):
		"""
		Return how meters are we far away the capsule.
		"""
		L.info("radar Called")
		L.debug({
			'TSCid':TSCid, 
			'lat': lat, 
			'lng':lng
		})
		tsc = TimespaceCapsule.getByTSCid(TSCid)
		if tsc is None:
			return  (TSCController.TSCCTRL_BADTSCID, None)
		return (TSCController.TSCCTRL_OK, tsc.distance( lat, lng ))
コード例 #8
0
ファイル: http_server.py プロジェクト: lemin2601/easyTools
def run(port=8000, address='', path="./"):
    utils.register_exit()
    L.error("p %s a %s p %s", port, address, path)
    if num_version == 2:
        L.debug(utils.abs_path(path))
        os.chdir(path)
        handler = SimpleHTTPServer.SimpleHTTPRequestHandler
        httpd = SocketServer.TCPServer((address, port), handler)
        httpd.serve_forever()
        pass
    else:
        L.debug(utils.abs_path(path))
        os.chdir(path)
        http.server.test(HandlerClass=SimpleHTTPRequestHandler,
                         port=port,
                         bind=address)
コード例 #9
0
def main(args):
    L.debug("main commander")
    parser = Parser(prog='commander.py')
    parser.add_argument("key", default=None, help=get_help())
    if len(args) > 0:
        arguments = [args.pop(0)]
        arguments = parser.parse_args(arguments)
        if arguments is None:
            pass
        else:
            key_found = arguments.key
            if key_found is not None:
                L.debug("find key:" + key_found)
                execute_func(key_found, args)
    else:
        parser.print_help()
コード例 #10
0
ファイル: controllers.py プロジェクト: ozw1z5rd/gdg-pescara
	def openCapsule(
			TSCid=None,
			lat=None,
			lng=None,
			password=None,
			user=None
		):
		"""
		openCapsule will assign the capsule is mode is not anonymous 
		and then will return to caller
		Is capsule is anonymous or already assigned, it will try to open it
		"""
		L.info("openCapsule Called")
		L.debug({
			'dumping parameters': '',
			'TSCid' : TSCid, 
			'lat' : lat,
			'lng' : lng, 
			'pwd len': len(password) if password is not None else -1,
			'user':user
		})
		# capsule not found
		tsc = TimespaceCapsule.getByTSCid(TSCid)
		if tsc is None:
			return (TSCController.TSCCTRL_BADTSCID, None)
		# if not anonymous here we require a valid user.
		if not tsc.anonymous and tsc.user is None:
			if user is None:
				return (TSCController.TSCCTRL_BADUSER, None)
			L.info("TSC is not anonymous, binding ...")
			L.info(user)
			tsc.assignToUser( user )
			return  (TSCController.TSCCTRL_ASSIGNED, None )
		
		# try to open
		L.info("try to disclose")
		response = tsc.disclose( 
						lat=lat,
						lng=lng,
						user=user,
						password=password
					)
		return ( TSCController.TSCCTRL_OK, response)
コード例 #11
0
def show_version_manifest():
    num_version = gv.cdn_version()
    cdn_path = utils.join_path(gv.cdn_path(), project_manifest_name)
    client_path = utils.join_path(gv.client_path(), project_manifest_name)
    cdn_config = inout.read_json(cdn_path)
    client_config = inout.read_json(client_path)
    L.debug("version manifest:")
    L.debug("dev.json            => %s", num_version)
    L.debug("client/project.json => %s", client_config['version'])
    L.debug("cdn/project.json    => %s", cdn_config['version'])

    pass
コード例 #12
0
ファイル: controllers.py プロジェクト: ozw1z5rd/gdg-pescara
	def searchCapsule(
			TSCid=None,
			seen=False,
			anonymous=True,
			notified=False,
			assigned=False,
			encrypt=False,
			user=None
		):
		"""
		Search a TSC depending on the given parameters, if tscid is 
		provided extra parameters are ignored.
		"""
		L.info("searchCapsule called ")
		L.debug({
			'Dumping paramters' : '',
			'anonymous' : anonymous, 
			'notified' : notified, 
			'assigned' : assigned, 
			'encrypt' : encrypt, 
			'user' : user 
		})
		
		# if TSCid is provided SEARCH only by TSCid.
		if TSCid is not None:
			L.info("TSCid is not None")
			tsc = TimespaceCapsule.getByTSCid( TSCid )
			tscList = [tsc] if tsc is not None else [] 
		else:
			# more elements
			tscList = TimespaceCapsule.getList( 
						user=user, 
						seenFlag=seen,
						assignedFlag=assigned,
						notifiedFlag=notified,
						encryptFlag=encrypt
					)
			
		items = [ tsc.toEndPointMessage() for tsc in tscList ]
		if any(items): 
			L.info( "No capsule found!")
		return ( TSCController.TSCCTRL_OK, items )
コード例 #13
0
ファイル: controllers.py プロジェクト: ozw1z5rd/gdg-pescara
    def searchCapsule(TSCid=None,
                      seen=False,
                      anonymous=True,
                      notified=False,
                      assigned=False,
                      encrypt=False,
                      user=None):
        """
		Search a TSC depending on the given parameters, if tscid is 
		provided extra parameters are ignored.
		"""
        L.info("searchCapsule called ")
        L.debug({
            'Dumping paramters': '',
            'anonymous': anonymous,
            'notified': notified,
            'assigned': assigned,
            'encrypt': encrypt,
            'user': user
        })

        # if TSCid is provided SEARCH only by TSCid.
        if TSCid is not None:
            L.info("TSCid is not None")
            tsc = TimespaceCapsule.getByTSCid(TSCid)
            tscList = [tsc] if tsc is not None else []
        else:
            # more elements
            tscList = TimespaceCapsule.getList(user=user,
                                               seenFlag=seen,
                                               assignedFlag=assigned,
                                               notifiedFlag=notified,
                                               encryptFlag=encrypt)

        items = [tsc.toEndPointMessage() for tsc in tscList]
        if any(items):
            L.info("No capsule found!")
        return (TSCController.TSCCTRL_OK, items)
コード例 #14
0
def loop():
    """
    1. read input
    2. pasrse command
    3. continue

    :return:
    """

    load_config_project()

    L.debug("running with version: %s", sys.version)
    is_version_2 = sys.version.startswith("2")
    while True:
        response = ''
        if num_version == 2:
            response = raw_input("Enter command:")
        if num_version == 3:
            response = input("Enter command:")

        if response != '':
            commander.parse(response)
        sleep(0.5)
コード例 #15
0
ファイル: parse.py プロジェクト: lemin2601/easyTools
 def exit(self, status=0, message=None):
     L.debug("exit")
     pass
コード例 #16
0
def save(json_manifest, json_assets, dest_path, dest_project_manifest):
    L.debug("save-ing ...")
    L.debug(json.dumps(json_manifest, indent=4))
    path_version = abs_path(join_path(dest_path, version_manifest_name))
    L.debug("%s", path_version)

    inout.write_json(path_version, json_manifest)
    json_manifest[assets] = json_assets

    path_project = abs_path(join_path(dest_path, project_manifest_name))
    inout.write_json(path_project, json_manifest)
    L.debug("%s", path_project)

    path_project = abs_path(
        join_path(dest_project_manifest, project_manifest_name))
    inout.write_json(path_project, json_manifest)
    L.debug("project.manifest => %s", path_project)
    L.debug("save success !!!")
コード例 #17
0
def read_json(path):
    L.debug("red_json" + os.path.abspath(path))
    f = open(path, "r")
    result = load(f)
    f.close()
    return result