def set_prefix_path(prefix_path, build_dir=os.getcwd()): config.REPO_ROOT_DIR = prefix_path config.BUILD_SCRIPT_DIR = posixpath.join(config.REPO_ROOT_DIR, 'scripts') config.CODE_DIR = posixpath.join(config.REPO_ROOT_DIR, 'driver') config.RESOURCE_DIR = posixpath.join(config.REPO_ROOT_DIR, 'resources') config.BINDINGS_DIR = posixpath.join(config.REPO_ROOT_DIR, 'python') config.PY_BINDINGS_DIR = config.BINDINGS_DIR config.TEST_DIR = posixpath.join(config.CODE_DIR, 'tests') config.BUILD_DIR = build_dir config.SERIALIZATION_BUILD_DIR = posixpath.join( config.BUILD_DIR, 'driver') config.BINDINGS_BUILD_DIR = posixpath.join(config.BUILD_DIR, 'python') config.PY_BINDINGS_BUILD_DIR = posixpath.join( config.BINDINGS_BUILD_DIR, 'python') config.TEST_REPORT_DIR = posixpath.join(config.BUILD_DIR, 'test_reports') config.RELEASE_DIR = posixpath.join(config.BUILD_DIR, 'release') config.NRF51_SDK_DIR = Sdk(config.ARTIFACTS_ROOT, config.SDK_VERSION).path config.NRF51_SDK_SOURCE_DIR = posixpath.join(config.NRF51_SDK_DIR, 'components') config.NRF51_SDK_INCLUDE_DIR = posixpath.join(config.NRF51_SDK_DIR, 'components')
def __init__(self): # Create SDK object and current user variable: self.s = Sdk() self.current_user = None
class Logic: def __init__(self): # Create SDK object and current user variable: self.s = Sdk() self.current_user = None def login(self, username, password): # Receive either a response error message or a user dictionary: response = self.s.login(username, password) # Check if user was received by type-checking: if isinstance(response, dict): self.current_user = response # Success message forwarded return "Success!" else: # Error Message forwarded return response def logout(self): # Sets current user to null: self.current_user = None def create_user(self, user_dict): # Response Message forwarded: return self.s.create_user( user_dict["first_name"], user_dict["last_name"], user_dict["username"], user_dict["password"], user_dict["email"], ) def create_game(self, game_name, host_controls, map_size): # Response Message forwarded: return self.s.create_game(self.current_user, game_name, host_controls, map_size) def join_game(self, opponent_controls, game_id): # Reserve spot: Join game if it's open: status = self.s.join_game(self.current_user["id"], game_id) # Check if the game was successfully joined: if status is not "Game closed": # Play game: Start game by sending controls: status = self.s.start_game(self.current_user, opponent_controls, game_id) # Check if the current user won: WIN if status["opponent"]["winner"]: # Here; the opponent key is always the current user # Calculate the score difference: point_difference = status["opponent"]["score"] - status["host"]["score"] # String forwarded: return "You won the game by " + str(point_difference) + " points!" # Check if the host won: LOSS elif status["host"]["winner"]: # Calculate the score difference; vars in reverse order: point_difference = status["host"]["score"] - status["opponent"]["score"] # String forwarded: return "You lost the game by " + str(point_difference) + " points" # If nobody won: DRAW else: # String forwarded: return "It's a draw!" else: # Response Message forwarded: return status def delete_game(self, game_id): # Response Message forwarded: return self.s.delete_game(game_id) def get_open_games(self): # List of game dictionaries forwarded: return self.s.get_open_games() def get_high_score(self): # List of high score dictionaries forwarded: return self.s.get_high_scores() def get_config(self): # Create string to store config data: config_data = "" # Loop through keys in config from sdk: for key in sorted(self.s.config): # Dictionary is sorted to display SQL-credentials together. # Add keys and their respective value to the config_data string. config_data += key + ": " + self.s.config[key] + "\n" # Represented for human reading # Config data forwarded return config_data @staticmethod def is_dict_full(dictionary): # Loops through dictionary to find empty values: for value in dictionary.values(): if value == "" or value is None: return False # If no values were empty or null; return True. return True @staticmethod def valid_moves(moves, map_size): # Check if moves fit map size: if len(moves) > int(map_size): return False # Loop through each char in the string: for m in moves: # Check if the moves are valid: if m.lower() not in ["w", "a", "s", "d"]: return False # If all moves are valid; return True. return True
def main(): args = parse_command_line() root_dir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) config.config_init(args.version, args.revision, args.version_name, args.sdk_root_path, args.sdk_version, root_dir) sdk = Sdk(config.ARTIFACTS_ROOT, config.SDK_VERSION) # Assumes that source root dir is .. since build.py is ran in directory build_scripts patch_dir = os.path.join(root_dir, 'patches') try: if args.clean: clean.clean_all(sdk) if args.create_patch_filename: sdk.prepare_sdk() old_path = sdk.path tempdir_path = None try: tempdir_path = tempfile.mkdtemp(prefix='nordicsemi') sdk.path = os.path.join(tempdir_path, "orig_sdk") sdk.prepare_sdk() p = Patch(patch_dir=patch_dir, apply_patch_root_dir=sdk.path, strip=0 # The old patches has 4 more components ) p.create_patch(tempdir_path, old_path, os.path.join(patch_dir, args.create_patch_filename)) finally: sdk.path = old_path shutil.rmtree(tempdir_path) if args.dependencies: sdk.prepare_sdk() patch_tag_file = posixpath.join(sdk.path, ".patched") if os.path.exists(patch_tag_file): logger.info("Patches are already applied to this SDK, skipping patching") else: open(patch_tag_file, 'w').close() p = Patch(patch_dir=patch_dir, apply_patch_root_dir=sdk.path, strip=0 # The old patches has 4 more components ) p.apply_patches(dry_run=False) if args.build: serialization_dll.build() if args.test: error_code = tests.do_testing() if error_code != 0: return error_code if args.package: package_release() if args.examples: examples.build_examples() except Exception, ex: logger.exception(ex) return -1
def build(): logger.info('Building serialization dll artifacts with CMake') sdk_info = Sdk(config.ARTIFACTS_ROOT, config.SDK_VERSION) utility.make_directory(config.SERIALIZATION_BUILD_DIR) if config.PLATFORM_SYSTEM == 'Windows': generator = 'MinGW Makefiles' elif config.PLATFORM_SYSTEM in ['Linux', 'Darwin']: generator = 'Unix Makefiles' else: raise SystemError('Unknown platform. Not able to determine generator.') cmake_environment = None # Remove any git/bin path in environment variable PATH if config.PLATFORM_SYSTEM == 'Windows': environment_path = os.environ['PATH'] environment_path_list = environment_path.split(';') environment_path_list = [ path for path in environment_path_list if 'Git\\bin' not in path ] environment_path = ';'.join(environment_path_list) cmake_environment = copy.copy(os.environ) cmake_environment['PATH'] = environment_path for artifact in ['driver', 'binding']: cmake_args = [ 'cmake', '-G', '{0}'.format(generator), '-DNRF51_SDK_PATH={0}'.format(sdk_info.path), '-DSERIALIZATION_VERSION={0}'.format(config.VERSION), '-DSERIALIZATION_REVISION={0}'.format(config.REVISION), '-DARTIFACT={0}'.format(artifact), config.REPO_ROOT_DIR ] logging.debug("Starting to build with command: %s", " ".join(cmake_args)) return_code = None try: return_code = subprocess.call(cmake_args, shell=False, env=cmake_environment) if return_code != 0: err_msg = 'Failed to prepare build of {0} libraries. Error code: {1}.'.format( artifact, return_code) utility.add_log_message(err_msg) raise SystemError(err_msg) return_code = subprocess.call([config.PLATFORM_MAKE], shell=True) if return_code != 0: err_msg = 'Failed to build artifact {0}. Error code: {0}.'.format( artifact, return_code) utility.add_log_message(err_msg) raise SystemError(err_msg) except Exception, e: logger.fatal(e) return return_code