def __call__(self, parser, namespace, value, option_string=None): if not config_file_exists(): create_config_file() sys.exit(0) print("Config file already exists") sys.exit(1)
def main(): parser = build_arg_list() args = parser.parse_args() ## Create the config file before any operation utils.create_config_file() service = ServiceFactory.create_service(args.service) if service == None: print("The provided service is not supported: " + args.service) return service.backup()
def main(): parser = build_arg_list() args = parser.parse_args() ## Create the config file before any operation utils.create_config_file() service = ServiceFactory.create_service(args.service) if service == None: print ("The provided service is not supported: " + args.service) return service.backup()
def subtest_start_brave_with_tcp_input(run_brave, create_config_file, container, config): config['inputs'] = [{ 'type': 'tcp_client', 'container': container, 'host': TCP_HOST, 'port': TCP_PORT }] if config['enable_video']: config['outputs'] = [ { 'type': 'image', 'source': 'input1' }, # PREVIEW for debugging: # { # 'type': 'local', # 'source': 'input1' # } ] config_file = create_config_file(config) run_brave(config_file.name, BRAVE_2_PORT) utils.check_brave_is_running() time.sleep(3) utils.assert_everything_in_playing_state(port=BRAVE_2_PORT)
def subtest_start_brave_with_rtmp_input(run_brave, create_config_file, rtmp_url): config = { 'inputs': [{ 'type': 'uri', 'uri': rtmp_url }], # 'mixers': [ # { # 'sources': [ # {'uid': 'input1'} # ] # } # ], 'outputs': [ { 'type': 'image', 'source': 'input1' # ADD A PREVIEW, for debugging: }, { 'type': 'local', 'source': 'input1' } ] } config_file = create_config_file(config) run_brave(config_file.name, BRAVE_2_PORT) utils.check_brave_is_running()
def subtest_start_brave_with_rtmp_output(run_brave, create_config_file, rtmp_url): config = { 'inputs': [{ 'type': 'test_video', 'pattern': 4, # RED }], 'outputs': [{ 'type': 'rtmp', 'source': 'input1', 'uri': rtmp_url }] } config_file = create_config_file(config) run_brave(config_file.name, BRAVE_1_PORT) utils.check_brave_is_running()
def subtest_start_brave_with_tcp_output(run_brave, create_config_file, container, config): if config['enable_video']: config['inputs'] = [{ 'type': 'test_video', 'pattern': 4, # RED }] else: config['inputs'] = [{'type': 'test_audio'}] config['outputs'] = [{ 'type': 'tcp', 'container': container, 'source': 'input1', 'host': TCP_HOST, 'port': TCP_PORT }] config_file = create_config_file(config) run_brave(config_file.name, BRAVE_1_PORT) time.sleep(2) utils.check_brave_is_running() utils.assert_everything_in_playing_state(port=BRAVE_1_PORT)
def test_api_host_and_port_config(create_config_file): config = {'api_host': 'api-host', 'api_port': 12345} config_file = create_config_file(config) brave.config.init(config_file.name) assert brave.config.api_host() == 'api-host' assert brave.config.api_port() == 12345
def test_stun_server_config(create_config_file): config = {'stun_server': 'a-stun-server'} config_file = create_config_file(config) brave.config.init(config_file.name) assert brave.config.stun_server() == 'a-stun-server'
# limitations under the License. ########################################################################### #___INFO__MARK_END__ # from nose import SkipTest from utils import needs_uge from utils import create_config_file from uge.api.qconf_api import QconfApi from uge.config.config_manager import ConfigManager from uge.log.log_manager import LogManager from uge.exceptions.object_not_found import ObjectNotFound from uge.exceptions.object_already_exists import ObjectAlreadyExists create_config_file() API = QconfApi() CONFIG_MANAGER = ConfigManager.get_instance() LOG_MANAGER = LogManager.get_instance() @needs_uge def test_list_ahosts(): try: hl = API.list_ahosts() assert (hl is not None) except ObjectNotFound, ex: raise SkipTest('There are no configured UGE admin hosts.') def test_object_already_exists():
def main(): try: if not os.path.exists(sys.argv[1]): sys.exit("O_O No existe el archivo de parametros: ./" + sys.argv[1]) with open(sys.argv[1], 'r') as f: dic = json.load(f) f.close() dic['main_dir'] = os.getcwd().replace('\\', '/') dic['copy_file'] = os.getcwd().replace('\\', '/') + '/' + dic['copy_file'] dic['Filters'] = ['EstPresente', 'Copia', 'Omision'] # # Archivo de logging if os.path.exists(dic['main_dir'] + '/preprocessing.log'): os.remove(dic['main_dir'] + '/preprocessing.log') logging.basicConfig( filename=dic['main_dir'] + '/preprocessing.log', level=logging.INFO, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') # validar archivo de SNP actualizacion if len(sys.argv) == 3: flagUpdate = True if not os.path.exists(dic['main_dir'] + '/input/' + sys.argv[2]): logging.info("ADVERTENCIA .... No existe el archivo (" + sys.argv[2] + ") No se filtraran los .dat") else: pdSNP = pd.read_csv( dic['main_dir'] + '/input/' + sys.argv[2], dtype="str") else: flagUpdate = False print('REVISANDO PARAMETROS...') if not os.path.exists(dic['main_dir'] + '/src/'): sys.exit("FALTA CARPETA SRC") if not os.path.exists(dic['main_dir'] + '/src/bin/'): sys.exit( "CARPETA BIN PARA BILOG NO EXISTE, COPIAR CARPETA EN 'src/'") if not os.path.exists(dic['main_dir'] + '/input'): sys.exit( "CARPETA 'input' NO EXISTE --> CREAR CARPETA INPUT CON .zip Y ARCHIVO DE COPIA" ) if not os.path.isfile(dic['copy_file']): sys.exit( "ARCHIVO DE COPIA NO ENCONTRADO --> REVISAR ARCHIVO DE PARAMETROS 'src/parameters.json' --> parametro 'copy_file'" ) isMissing = [ prueba for prueba in dic['Pruebas'].keys() if not prueba in dic['Codigos'].keys() ] if len(isMissing) > 0: sys.exit( "PARAMETROS INCORRECTOS DE JUNTURAS FALTA AGREGAR: ---->\n" + ', '.join(isMissing) + "\n-------------------------------------------------------" + "\ncambiar en 'src/parameters.json' --> parametro 'Codigos'") isMissing = [ prueba for prueba in dic['Codigos'].keys() if not prueba in dic['Pruebas'].keys() ] if len(isMissing) > 0: sys.exit( "PARAMETROS INCORRECTOS DE FORMAS FALTA AGREGAR: ---->\n" + ', '.join(isMissing) + "\n-------------------------------------------------------" + "\ncambiar en 'src/parameters.json' --> parametro 'Codigos'") logging.info( '#######################################################################' ) logging.info('COMENZO: ' + datetime.now().strftime('%Y-%m-%d %H:%M:%S')) logging.info('Corriendo Preprocessing_stage.py') logging.info( '#######################################################################' ) if dic['subloque']: if ("subloques" not in dic.keys()): logging.info( 'NO DEFINIO SUBLOQUES, no se correran sub-bloques...') dic['subloques'] = [] dic['subloque'] = False if len(dic['subloques']) == 0: logging.info( 'NO DEFINIO SUBLOQUES, no se correran sub-bloques...') dic['subloque'] = False else: logging.info( 'NO DEFINIO BANDERA SUBLOQUE, no se correran sub-bloques...') logging.info('Limpiando carpeta principal') if os.path.exists(dic['main_dir'] + '/input/Descargas'): shutil.rmtree( dic['main_dir'] + '/input/Descargas', ignore_errors=True) if os.path.exists(dic['main_dir'] + '/output'): shutil.rmtree(dic['main_dir'] + '/output', ignore_errors=True) if os.path.exists(dic['main_dir'] + '/doc'): shutil.rmtree(dic['main_dir'] + '/doc', ignore_errors=True) time.sleep(15) logging.info('\tLeyendo archivo de parametros: ' + sys.argv[1]) zipfiles = [] logging.info( "ARCHIVOS .ZIP ENCONTRADOS en 'input'--> ALGUNA INCONSISTENCIA EN LOS ARCHIVOS --> REVISAR CARPETA INPUT Y EJECUTAR NUEVAMENTE EL PROCESO" ) for file in os.listdir(dic['main_dir'] + '/input/'): if file.endswith('.zip'): zipfiles.append(file) if len(zipfiles) == 0: sys.exit( "NINGUN ARCHIVO ZIP ENCONTRADO -- > COPIAR ARCHIVOS ZIP EN 'input/'" ) else: logging.info(str(zipfiles)) logging.info(sep) logging.info('REVISANDO SCRIPTS NECESARIOS...') dirs = os.listdir(dic['main_dir'] + '/src') if not 'JuntarModulosSaber11.pl' in dirs: logging.info("FALTA SCRIPT 'src/JuntarModulosSaber11.pl'") sys.exit("FALTA SCRIPT 'src/JuntarModulosSaber11.pl'") groups = { '01_Estudiantes': None, '02_NoEstudiantes': None, '03_Discapacitados': None } folder_structure = { 'input': None, 'output': { 'calibracion': groups, 'calificacion': groups }, 'doc': None } logging.info(sep) logging.info('CREANDO ESTRUCTURA DE CARPETAS EN: ' + dic['main_dir'] + '/' + str(folder_structure) + '...') utils.make_dirs_from_dict(folder_structure, dic['main_dir'] + '/') logging.info('\tTerminado...') logging.info(sep) logging.info('EXTRAYENDO ARCHIVOS...') utils.extract_files(dic['main_dir'] + '/') logging.info('\tTerminado...') logging.info(sep) if dic['subloque']: logging.info('ELIMINANDO SUBLOQUES 0...') for root, dirs, files in os.walk(dic["main_dir"]): for file in files: pattern = re.compile(r".*sblq(.*)\.|\-.*", re.I) matcher = pattern.match(file) if not matcher == None and not matcher.groups()[0].split( '-')[0] in dic['subloques']: print('ARCHIVO A ELIMINAR..', file) os.remove(os.path.join(root, file)) logging.info('\tTerminado...') logging.info(sep) logging.info('GENERANDO FORMAS DE SUBLOQUES...') print('Generando formas de subloques') pattern = re.compile(r'.*sblq(.*).con', re.I) ext = dic['out_f'][:] ext.remove('.con') for root, dirs, files in os.walk(dic["main_dir"]): for file in files: matcher = pattern.search(file) if not matcher == None: newPath = root + '_' + matcher.groups()[0] if not os.path.exists(newPath): print('NEW_FOLDER: ' + newPath) ensure_dir_exists(newPath + '/salidas') params = { 'main_path': root + '/', 'con_file': file.replace('.con', '') } utils.filterISELECT(params, newPath) logging.info('\tTerminado...') logging.info(sep) logging.info('ADICIONANDO SUBLOQUES A DICCIONARIO...') print('Adicionando subloques a diccionario...') utils.add_subloques(dic) logging.info(dic['Pruebas']) logging.info('\tTerminado...') logging.info(sep) logging.info('ARCHIVOS DE SUBLOQUES...') print('Eliminando archivos de subloques') for root, dirs, files in os.walk(dic["main_dir"]): for file in files: if re.match("(.*)sblq(.*)", file): print('ARCHIVO A ELIMINAR..', file) os.remove(os.path.join(root, file)) logging.info('\tTerminado...') logging.info(sep) logging.info('APLICANDO FILTROS A ARCHIVOS .DAT...') mpath = '' for root, dirs, files in os.walk(dic["main_dir"]): for file in files: if file.endswith(".con"): flagFiltro = True print('CONFILE ENCONTRADO: ' + file) path = (os.path.join(root, file)).replace('\\', '/').split('/') mpath = ('/').join((os.path.join(root, file)).replace( '\\', '/').split('/')[:-1]) + '/' if dic['subloque']: indSubl = [ bloque in file for bloque in dic['subloques'] ] print(indSubl) if not any(indSubl): flagFiltro = False shutil.rmtree(root) if flagFiltro: confile = path[-2] dic['con_file'] = path[-2] logging.info('\tAplicando filtros a : ' + confile) dic['filtered_data'] = '' dic['main_path'] = mpath dic['count_log'] = dic['main_path'] + '/registro.log' con = utils.create_dict_from_con(dic) params = dict(dic.items() + con.items()) params['id_form'] = confile params['aplicacion'] = con['DATA'].split('-')[0][0:7] logging.info('\t\tAplicacion: ' + params['aplicacion']) f_g = {} utils.set_f_g(params['Pruebas'].copy(), confile, f_g) if not f_g == {}: params['curr_group'] = f_g[confile] logging.info('\t\tGrupo: ' + params['curr_group']) if not flagUpdate: filtrado.apply_filters(params) mpath = mpath.replace(confile, '') logging.info('\t\tTerminado...') logging.info(sep) if not flagUpdate: logging.info('CREANDO ARCHIVO DE CONFIGURACION.TXT...') f = [] for root, dirs, files in os.walk(dic['main_dir'] + '/input/Descargas/'): for dir in dirs: f.append(dir) config_file = [] utils.create_config_file(dic['Pruebas'], dic['Codigos'], dic['Pruebas'].keys(), '', config_file, [], f) np.savetxt( dic['main_dir'] + '/output/configuracion.txt', config_file, delimiter=",", fmt="%s") logging.info('\t\tTerminado...') logging.info(sep) logging.info('JUNTANDO ARCHIVOS DAT (JUNTAR.pl)...') os.chdir(mpath) #Change to forms_path p = subprocess.Popen([ 'perl', dic['main_dir'] + '/src/JuntarModulosSaber11.pl', '-com', '-dat', '-conf', dic['main_dir'] + '/output/configuracion.txt' ]) p.communicate() logging.info('\t\tTerminado...') logging.info(sep) ext = dic['out_f'] logging.info( 'MOVIENDO ARCHIVOS A SUS RESPECTIVAS CARPETAS DE SALIDA...') config = [] logging.info( 'SACANDO CARPETAS DE JUNTURA...(Leyendo archivo de configuracion.txt)' ) with open(dic['main_dir'] + '/output/configuracion.txt') as f: config = f.readlines() f.close() J = [] #Formas ya presentes en carpeta JUNTAS for line in config: if line.startswith("PRUEBA"): J.append(line.split()[2]) logging.info('FORMAS DE JUNTURA: ' + str(J)) dirs = os.listdir(os.getcwd()) for d in dirs: if not d in J and os.path.isdir(os.getcwd() + '/' + d): logging.info(sep) logging.info('PATH DE INPUT - OUTPUT PARA CARPETA: ' + d) if d == "JUNTAS": f_g = {'JUNTAS': '01_Estudiantes'} else: f_g = {} utils.set_f_g(dic['Pruebas'].copy(), d, f_g) if not f_g == {}: path_output = dic[ 'main_dir'] + '/output/calibracion/' + f_g[ d] + '/' + d ensure_dir_exists(path_output) if d == 'JUNTAS': path_input = os.getcwd() + '/' + d logging.info('PATH INPUT: ' + path_input) logging.info('PATH OUTPUT: ' + path_output) utils.copytree(path_input, path_output) else: for root, dirs, files in os.walk(os.getcwd() + '/' + d): for file in files: for ex in dic['out_f']: if ex in file: path_input = os.path.join( root, file).replace('\\', '/') logging.info('PATH INPUT: ' + path_input) logging.info('PATH OUTPUT: ' + path_output + '/' + file) shutil.copyfile( path_input, path_output + '/' + file) if not d == 'JUNTAS': ensure_dir_exists(path_output + '/salidas') logging.info('SALIDAS: ' + path_output + '/salidas') logging.info(sep) logging.info( 'MOVIENDO ARCHIVOS DE CALIFICACION A SUS RESPECTIVAS CARPETAS...') ext = [] for e in dic['out_f']: if e.endswith('.DAT') and not flagUpdate: ext.append(e.replace('.DAT', '.O')) else: ext.append(e) removePaths = [] for root, dirs, files in os.walk(os.getcwd()): for d in dirs: if not d == 'JUNTAS': f_g = {} utils.set_f_g(dic['Pruebas'].copy(), d, f_g) if not f_g == {}: path_output = dic[ 'main_dir'] + '/output/calificacion/' + f_g[ d] + '/' + d ensure_dir_exists(path_output) if not os.path.exists(path_output + '/salidas'): os.makedirs(path_output + '/salidas') for file in os.listdir(os.path.join(root, d)): for e in ext: if e in file: path_input = os.path.join(root, d) + '/' + file if file.endswith('.O'): output = path_output + '/' + file.replace( '.O', '.DAT') else: output = path_output + '/' + file if not os.path.exists(output): shutil.copyfile(path_input, output) if flagUpdate and file.endswith( '.DAT'): if ('pdSNP' in locals()): nUpdate = filtroActualizacion( output, pdSNP, dic['id_len']) if nUpdate == 0: removePaths.append( path_output) logging.info( 'FILTRANDO NUEVAS PERSONAS PARA CALIFICAR: ' + file) else: statFile = os.stat(path_input) if str(statFile. st_size) == '0': removePaths.append( path_output) logging.info( 'SE CALIFICARAN TODAS LAS PERSONAS: ' + file) # # Removiendo if flagUpdate: logging.info(sep) logging.info('ELIMANDO CARPETAS EN BLANCO DE LA CALIFICACION...') for path in removePaths: logging.info('Eliminando: ' + path) shutil.rmtree(path) logging.info(sep) logging.info('\tTerminado...') logging.info(sep) logging.info('TERMINO: ' + datetime.now().strftime('%Y-%m-%d %H:%M:%S')) except Exception as e: print(logging.error(traceback.format_exc()))
def subtest_start_brave_with_multiple_positioned_inputs( run_brave, create_config_file): config = { 'inputs': [ { 'type': 'test_video', 'pattern': 3 }, # white { 'type': 'test_video', 'pattern': 4 }, # red { 'type': 'test_video', 'pattern': 5 }, # green { 'type': 'test_video', 'pattern': 6 }, # blue ], 'mixers': [{ 'width': 160, 'height': 90, 'pattern': 2, 'sources': [{ 'uid': 'input1', 'zorder': 1 }, { 'uid': 'input2', 'zorder': 2, 'width': 80 }, { 'uid': 'input3', 'zorder': 3, 'width': 80, 'height': 45 }, { 'uid': 'input4', 'zorder': 4, 'xpos': 80, 'ypos': 45 }] }], 'outputs': [{ 'type': 'image', 'width': 160, 'height': 90 }] } config_file = create_config_file(config) run_brave(config_file.name) utils.check_brave_is_running() time.sleep(4) utils.assert_everything_in_playing_state() utils.assert_mixers([{ 'id': 1, 'sources': [{ 'uid': 'input1', 'in_mix': True, 'zorder': 1 }, { 'uid': 'input2', 'in_mix': True, 'zorder': 2, 'width': 80 }, { 'uid': 'input3', 'in_mix': True, 'zorder': 3, 'width': 80, 'height': 45 }, { 'uid': 'input4', 'in_mix': True, 'zorder': 4, 'xpos': 80, 'ypos': 45 }] }]) im = utils.get_raw_image_for_output(1) utils.assert_image_color_at_dimension(im, (10, 10), (0, 255, 0)) utils.assert_image_color_at_dimension(im, (150, 10), (255, 255, 255)) utils.assert_image_color_at_dimension(im, (10, 80), (255, 0, 0)) utils.assert_image_color_at_dimension(im, (150, 80), (0, 0, 255))
if (args.phase == "2"): fw_rules(2) else: print("Please, specify the phase.") elif (args.listinterfaces): print('\n' + ', '.join(if_list).center(100) + '\n') else: if (args.phase and args.uplink_interface and args.management_interface and args.management_interface_address and args.masquerading and args.teams and args.log): try: if_list.pop(if_list.index(args.uplink_interface)) if_list.pop(if_list.index(args.management_interface)) create_config_file(args.uplink_interface, args.uplink_address, args.management_interface, args.masquerading, args.management_interface_address, args.teams, args.log) if (args.phase == "1"): fw_rules(1) if (args.phase == "2"): fw_rules(2) except ValueError as identifier: # print("Some of the defined interfaces do not exist. Retry!") print(identifier) else: print("Some parameters missing. Retry!")