예제 #1
0
파일: Main.py 프로젝트: cedi/DiffieHellman
from Sockets import Client
from Sockets import Server
from argparse import ArgumentParser

if __name__ == '__main__':

	parser = ArgumentParser()
	parser.add_argument("-m", "--mode", dest="mode", type=str, required=True,
	                    help="CLIENT to start a client or SERVER to start a server"
	                    )

	parser.add_argument("-d", "--debug", dest="debug", required=False,
	                    help="to print debug messages, enable this option",
	                    action="store_true"
	                    )

	args = parser.parse_args()

	if args.debug:
		print(args)

	if args.mode.lower() == "client":
	    server = "localhost" # input("Server IP: ")
	    client = Client.ClientSocket(args.debug)
	    client.start_client(server)

	elif args.mode.lower() == "server":
	    Server.start_server(args.debug)
예제 #2
0
from sys import argv
from Sockets import Client
from Sockets import Server

if len(argv) > 1:
    clinetOrServer = argv[1]
    if clinetOrServer.lower() == 'c' or clinetOrServer.lower() == 'client':
        client = Client.Client()
    elif clinetOrServer.lower() == 's' or clinetOrServer.lower() == 'server':
        Server.Server()
    else:
        print("Please use argument 'c' for client or 's' for server")
else:
    print("Please use argument 'c' for client or 's' for server")
예제 #3
0
                        required=False,
                        help="to print debug messages, enable this option",
                        action="store_true")
    parser.add_argument("-b",
                        "--bytes",
                        dest="bytes",
                        type=str,
                        required=False,
                        help="tamanio en bits de los numeros primos a utlizar")
    parser.add_argument(
        "-e",
        "--mensaje",
        dest="mensaje",
        type=str,
        required=False,
        help="Mensaje a enviar desde el cliente para que decodique el servidor"
    )

    args = parser.parse_args()

    if args.debug:
        print(args)

    if args.mode.lower() == "client":
        server = "localhost"  # input("Server IP: ")
        client = Client.ClientSocket(args.debug)
        client.start_client(server, args.bytes, args.mensaje)

    elif args.mode.lower() == "server":
        Server.start_server(args.debug, args.bytes)
예제 #4
0
	def run(self):
		self.load() # Load les controllers/models/...
		self.Routing = Routing(self.controllers)
		self.Server = Server(self.Routing, self.databaseConfig)
		self.init() # S'occupe d'initialiser les controllers/models/...
		self.Server.run()
예제 #5
0
class PyBack:
	
	# C'est le point d'entrée du programme.
	def run(self):
		self.load() # Load les controllers/models/...
		self.Routing = Routing(self.controllers)
		self.Server = Server(self.Routing, self.databaseConfig)
		self.init() # S'occupe d'initialiser les controllers/models/...
		self.Server.run()
		
	
	####################################################################
	#	   Chargement des configs/models/controllers/compnents         #
	####################################################################
	
	def load(self):
		self.loadConfig()
		self.loadModels()
		self.loadComponents()
		self.loadController()
		
		
	# Charge et instancie les models contenu dans App/Models
	# Pour cela on ajoute le dossier App/Model au PATH et ensuite on liste
	# l'ensemble des fichiers .py pour pouvoir charger à la volé les models.
	# Cette method instancie les models
	def loadModels(self):
		self.models = {}
		sys.path.append("App/Models/")
		filesModel = glob.glob("App/Models/*.py")
		for f in filesModel:
			f = f.replace(".py", "")
			f = f.split("/")
			_className = f[len(f)-1]
			_class = getattr(__import__(_className), _className)
			_className = _className.replace("Model", "")
			self.models[_className] = _class()
	
	
	# Charge les components contenus dans App/Controllers/Components
	# Comme pour models sauf que les components ne sont pas instancié
	def loadComponents(self):
		self.components = {}
		sys.path.append("App/Controllers/Components")
		filesComponents = glob.glob("App/Controllers/Components/*.py")
		for f in filesComponents:
			f = f.replace(".py", "")
			f = f.split("/")
			_className = f[len(f)-1]
			_class = getattr(__import__(_className), _className)
			self.components[_className] = _class
	
	
	# Charge l'ensemble des controllers. Comme les models, les controllers
	# sont persistants tout au long du programme.
	def loadController(self):
		self.controllers = {}
		sys.path.append("App/Controllers/")
		filesController = glob.glob("App/Controllers/*.py")
		for f in filesController:
			f = f.replace(".py", "")
			f = f.split("/")
			_className = f[len(f)-1]
			_class = getattr(__import__(_className), _className)
			_className = _className.replace("Controller", "")
			self.controllers[_className] = _class(self.models, self.components)
	

	# S'occupe d'appeller les fonctions qui chargent les informations
	# de configuration. 
	# S'occupe d'enregistrer ces configurations dans des attributs de la
	# classe.
	# 
	# @param config Instance de la classe contenant les configurations
	# @return Dictionnaire contenant les infos de connexion de la DB
	def loadConfig(self):
		sys.path.append("App/Config/")
		_class = getattr(__import__("Config"), "Config")
		_config = _class()
		self.databaseConfig = self.loadDatabaseConfig(_config)
		self.networkConfig = self.loadNetworkConfig(_config)
		self.logsConfig = self.loadLogsConfig(_config)
		self.logEmailConfig = self.loadLogEmailConfig(_config)


	# Charge les informations de la base de données. Si certaines infos
	# ne sont pas fournies c'est celle par default qui seront utilisées
	# 
	# @param config Instance de la classe contenant les configurations
	# @return Dictionnaire contenant les infos de connexion de la DB
	def loadDatabaseConfig(self, config):
		_config = {
			"driver": "mysql", 
			"host": "localhost", 
			"username": "******", 
			"password": "", 
			"database": "pyBack", 
			"prefix": ""
			}
		_config.update(config.database())
		return _config

		
	# Charge les informations pour les sockets. Si certaines infos ne 
	# sont pas fournies c'est les infos par default qui seront choisies
	# 
	# @param config Instance de la classe contenant les configurations
	# @return Dictionnaire contenant les infos du réseau
	def loadNetworkConfig(self, config):
		_config = {
			"port": "8080",
			"listen": 5
			}
		_config.update(config.network())
		return _config
	
	def loadLogsConfig(self, config):
		_config = {
			"env": "prod",
			"folder": "./",
			"file": "logpyback.log"
			}
		_config.update(config.logs())
		return _config
	
	
	# Charge les emails auquels doivent-être envoyés les mails des logs
	# 
	# @param config Instance de la classe contenant les configurations
	# @return Dictionnaire contenant les emails pour les logs
	def loadLogEmailConfig(self, config):
		_config = {}
		_config.update(config.logEmail())
		return _config
		
	
	####################################################################
	#	   Init des controllers 									   #
	####################################################################
	
	# S'occupe d'envoyer au controller l'objet Server.
	def init(self):
		for key in self.controllers:
			getattr(self.controllers[key], 'setInfos')(self.Server)
	
	####################################################################
	#	  Tools for testing                                            #
	####################################################################
	
	# Permet d'afficher les configurations pour les tests
	def writeConfig(self):
		print self.databaseConfig
		print self.networkConfig
		print self.logsConfig
		print self.logEmailConfig
예제 #6
0
from Sockets import Client
from Sockets import Server
from argparse import ArgumentParser

# main
if __name__ == '__main__':

	parser = ArgumentParser()
	parser.add_argument("-m", "--mode", dest="mode", type=str, required=True,
	                    help="CLIENT to start a client or SERVER to start a server"
	                    )

	parser.add_argument("-d", "--debug", dest="debug", required=False,
	                    help="to print debug messages, enable this option",
	                    action="store_true"
	                    )

	args = parser.parse_args()

	if args.debug:
		print(args)

	if args.mode.lower() == "client":
	    server = 'localhost' #input("Server IP: ")
	    client = Client.ClientSocket(args.debug)
	    client.start_client(server)

	elif args.mode.lower() == "server":
	    Server.start_server(args.debug)