def check_local_config_schema(build): log.info("Verifying your configuration settings...") # leave this import here: might not be on sys.path in some situations import validictory local_conf_filename = build.tool_config.get('general.local_config') if local_conf_filename is not None: # explicit conf file defined if not path.isfile(local_conf_filename): raise ConfigurationError("{file} does not exist!".format(file=local_conf_filename)) else: local_conf_filename = 'local_config.json' if not path.isfile(local_conf_filename): log.warning("Local configuration file '{file}' does not exist!".format(file=local_conf_filename)) with open(local_conf_filename) as local_conf_file: local_conf = json.load(local_conf_file) from forge.remote import Remote from forge import build_config remote = Remote(build_config.load()) local_conf_schema = remote._api_get('platform/{platform_version}/local_config_schema'.format( platform_version=build.config['platform_version'])) try: validictory.validate(local_conf, local_conf_schema) except validictory.validator.UnexpectedPropertyError as e: log.warning('Unexpected setting: "{error}" in "{file}". This will be ignored.'.format( file=local_conf_filename, error=e) ) log.info("Configuration settings check complete")
def run_command(build, args): global remote from forge import build_config import forge from forge.remote import Remote config = build_config.load() remote = Remote(config) remote._authenticate() if len(args) == 0: raise ReloadError("Expecting command to after 'forge reload'") if args[0] == 'list': if len(args) != 1: raise ReloadError( "Invalid number of arguments passed to 'forge reload list'") list_streams(build) elif args[0] == 'create': if len(args) != 2: raise ReloadError( "Invalid number of arguments passed to 'forge reload create'") create_stream(build, args[1]) elif args[0] == 'push': if len(args) != 2: raise ReloadError( "Invalid number of arguments passed to 'forge reload push'") push_stream(build, args[1]) else: raise ReloadError("Unknown command 'forge reload %s'" % args[0])
def ensure_lib_available(build, file): lib_dir = path.join(path.dirname(build.source_dir), '.lib') hash_path = path.join(path.dirname(build.source_dir), '.template', 'lib', 'hash.json') if not path.exists(lib_dir): os.makedirs(lib_dir) # Hide directory on windows if sys.platform == 'win32': try: lib.PopenWithoutNewConsole(['attrib', '+h', lib_dir]).wait() except Exception: # don't care if we fail to hide the templates dir pass hashes = None if path.exists(hash_path): with open(hash_path, 'r') as hash_file: hashes = json.load(hash_file) file_path = path.join(lib_dir, file) if path.exists(file_path) and file in hashes: # Check hash with open(file_path, 'rb') as cur_file: hash = hashlib.md5(cur_file.read()).hexdigest() if hash == hashes[file]: # File exists and is correct build.log.debug("File: %s, already downloaded and correct." % file) return file_path # File doesn't exist, or has the wrong hash or has no known hash - download build.log.info( "Downloading lib file: %s, this will only happen when a new file is available." % file) from forge.remote import Remote from forge import build_config config = build_config.load() remote = Remote(config) server_details = urlparse.urlparse(remote.server) url = "{protocol}://{netloc}/lib-static/{platform_version}/{file}".format( protocol=server_details.scheme, netloc=server_details.netloc, platform_version=build.config['platform_version'], file=file) remote._get_file(url, file_path) # Make file executable. os.chmod( file_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) return file_path
def log_build(build, action): ''' Bundle together some stats and send it to the server for tracking This is called by every other function in this module, just before running the build. ''' from forge import build_config import forge from forge.remote import Remote log = {} log['action'] = action log['platform'] = platform.platform() log['version'] = sys.version log['uuid'] = build.config['uuid'] log['tools_version'] = forge.VERSION config = build_config.load() remote = Remote(config) remote._authenticate() remote._api_post('track/', data=log)