def load_app(app_path="."): '''Read in and JSON parse the per-app configuration file (src/config.json) and identify JSON file (src/identity.json) ''' app_config_file = defaults.APP_CONFIG_FILE with open_file(path.join(app_path, app_config_file)) as app_config: try: config = json.load(app_config) except ValueError as e: raise forge.ForgeError("Your configuration file ({0}) is malformed:\n{1}".format(app_config_file, e)) identity_file = defaults.IDENTITY_FILE if not path.isfile(path.join(app_path, identity_file)): if 'uuid' in config: # old-style config, where uuid was in config.json, rather than identity.json identity_contents = {"uuid": config["uuid"]} LOG.warning("we need to update your configuration to include an 'identity.json' file") with open_file(path.join(app_path, identity_file), 'w') as identity: json.dump(identity_contents, identity) LOG.info("configuration updated: 'identity.json' created") else: raise IOError("'identity.json' file is missing") with open_file(path.join(app_path, identity_file)) as identity: try: identity_config = json.load(identity) except ValueError as e: raise forge.ForgeError("Your identity file ({0}) is malformed:\n{1}".format(identity_file, e)) config.update(identity_config) return config
def save_local(settings, app_path="."): """Dump a dict as JSON into local_config.json, overwriting anything currently in there""" local_config_path = defaults.LOCAL_CONFIG_FILE with open_file(path.join(app_path, local_config_path), 'w') as local_config_file: try: json.dump(settings, local_config_file, indent=4) except IOError as e: raise IOError("Couldn't write to local_config.json")
def _get_ignore_patterns_for_src(src_dir): """Returns the set of match_patterns :param src_dir: Relative path to src directory containing user's code """ try: with lib.open_file(os.path.join(src_dir, '.forgeignore')) as ignore_file: ignores = map(lambda s: s.strip(), ignore_file.readlines()) except Exception: ignores = [] return list(set(ignores))
def load_app(app_path="."): '''Read in and JSON parse the per-app configuration file (src/config.json) and identify JSON file (src/identity.json) ''' app_config_file = defaults.APP_CONFIG_FILE with async.current_call().io_lock: with open_file(path.join(app_path, app_config_file)) as app_config: try: config = json.load(app_config) except ValueError as e: raise forge.ForgeError("Your configuration file ({0}) is malformed:\n{1}".format(app_config_file, e))
def load_app(app_path="."): '''Read in and JSON parse the per-app configuration file (src/config.json) and identify JSON file (src/identity.json) ''' app_config_file = defaults.APP_CONFIG_FILE with open_file(path.join(app_path, app_config_file)) as app_config: try: config = json.load(app_config) except ValueError as e: raise forge.ForgeError( "Your configuration file ({0}) is malformed:\n{1}".format( app_config_file, e)) identity_file = defaults.IDENTITY_FILE if not path.isfile(path.join(app_path, identity_file)): if 'uuid' in config: # old-style config, where uuid was in config.json, rather than identity.json identity_contents = {"uuid": config["uuid"]} LOG.warning( "we need to update your configuration to include an 'identity.json' file" ) with open_file(path.join(app_path, identity_file), 'w') as identity: json.dump(identity_contents, identity) LOG.info("configuration updated: 'identity.json' created") else: raise IOError("'identity.json' file is missing") with open_file(path.join(app_path, identity_file)) as identity: try: identity_config = json.load(identity) except ValueError as e: raise forge.ForgeError( "Your identity file ({0}) is malformed:\n{1}".format( identity_file, e)) config.update(identity_config) return config
def load_local(app_path="."): """Read in and parse local configuration containing things like location of provisioning profiles, certificates, deployment details """ local_config_path = path.join(app_path, defaults.LOCAL_CONFIG_FILE) local_config_dict = {} if path.isfile(local_config_path): try: with async.current_call().io_lock: with open_file(local_config_path) as local_config_file: local_configs = local_config_file.read() if local_configs: local_config_dict = json.loads(local_configs) except IOError as e: LOG.debug("Couldn't load local_config.json") LOG.debug("%s" % traceback.format_exc())
def load_local(app_path="."): """Read in and parse local configuration containing things like location of provisioning profiles, certificates, deployment details """ local_config_path = path.join(app_path, defaults.LOCAL_CONFIG_FILE) local_config_dict = {} if path.isfile(local_config_path): try: with open_file(local_config_path) as local_config_file: local_configs = local_config_file.read() if local_configs: local_config_dict = json.loads(local_configs) except IOError as e: LOG.debug("Couldn't load local_config.json") LOG.debug("%s" % traceback.format_exc()) return local_config_dict
def command_create(): if os.path.exists(defaults.SRC_DIR): raise ForgeError( 'Source folder "%s" already exists, if you really want to create a new app you will need to remove it!' % defaults.SRC_DIR) questions = { 'description': 'Enter details for app', 'properties': { 'name': { 'type': 'string', 'title': 'App Name', 'description': 'This name is what your application will be called on devices. You can change it later through config.json.' } } } answers = cli.ask_question({'schema': questions}) if 'name' in answers and answers['name']: forge.settings['name'] = answers['name'] username = forge.settings['username'] app_uuid = str(uuid.uuid4().hex) app_name = forge.settings['name'] # generate app with open_file(path.join(config_dir, 'manifest.json')) as manifest_file: manifest = json.loads(manifest_file.read()) zipf = InMemoryZip() for item in manifest: initial_file = template_file( config_dir, item["path"], item["template"], ( ('${username}', username), ('${uuid}', app_uuid), ('${name}', app_name), ('${platform_version}', forge.settings['LAST_STABLE']), )) zipf.writestr(item["path"], initial_file) with zipfile.ZipFile(StringIO(zipf.read())) as myzip: myzip.extractall() LOG.info('App structure created. To proceed:') LOG.info('1) Put your code in the "%s" folder' % defaults.SRC_DIR) LOG.info('2) Run %s build to make a build' % ENTRY_POINT_NAME)
def command_create(): if os.path.exists(defaults.SRC_DIR): raise ForgeError('Source folder "%s" already exists, if you really want to create a new app you will need to remove it!' % defaults.SRC_DIR) questions = { 'description': 'Enter details for app', 'properties': { 'name': { 'type': 'string', 'title': 'App Name', 'description': 'This name is what your application will be called on devices. You can change it later through config.json.' } } } answers = cli.ask_question({ 'schema': questions }) if 'name' in answers and answers['name']: forge.settings['name'] = answers['name'] username = forge.settings['username'] app_uuid = str(uuid.uuid4().hex) app_name = forge.settings['name'] # generate app with open_file(path.join(config_dir, 'manifest.json')) as manifest_file: manifest = json.loads(manifest_file.read()) zipf = InMemoryZip() for item in manifest: initial_file = template_file(config_dir, item["path"], item["template"], ( ('${username}', username), ('${uuid}', app_uuid), ('${name}', app_name), ('${platform_version}', forge.settings['LAST_STABLE']), )) zipf.writestr(item["path"], initial_file) with zipfile.ZipFile(StringIO(zipf.read())) as myzip: myzip.extractall() LOG.info('App structure created. To proceed:') LOG.info('1) Put your code in the "%s" folder' % defaults.SRC_DIR) LOG.info('2) Run %s build to make a build' % ENTRY_POINT_NAME)
def _app_config_file_for_path(path): """Returns a handle to the config file for the app at the given location""" path_to_config_for_app = os.path.join(path, 'src', 'config.json') with async.current_call().io_lock: yield forge_lib.open_file(path_to_config_for_app)
with async.current_call().io_lock: with open_file(path.join(app_path, app_config_file)) as app_config: try: config = json.load(app_config) except ValueError as e: raise forge.ForgeError("Your configuration file ({0}) is malformed:\n{1}".format(app_config_file, e)) identity_file = defaults.IDENTITY_FILE if not path.isfile(path.join(app_path, identity_file)): if 'uuid' in config: # old-style config, where uuid was in config.json, rather than identity.json identity_contents = {"uuid": config["uuid"]} LOG.warning("we need to update your configuration to include an 'identity.json' file") with async.current_call().io_lock: with open_file(path.join(app_path, identity_file), 'w') as identity: json.dump(identity_contents, identity) LOG.info("configuration updated: 'identity.json' created") else: raise IOError("'identity.json' file is missing") with async.current_call().io_lock: with open_file(path.join(app_path, identity_file)) as identity: try: identity_config = json.load(identity) except ValueError as e: raise forge.ForgeError("Your identity file ({0}) is malformed:\n{1}".format(identity_file, e)) config.update(identity_config) return config