Exemplo n.º 1
0
def import_generate_dynamic(do_reload=False):
    """Load the dynamically-fetched generate libs.

	*N.B*. this has the side effect of checking to see if the app
	needs to be migrated in some way to be useable with this platform version.

	:param do_reload: call reload() on generate_dynamic modules if they're already imported.
	"""
    try:
        import generate_dynamic
        if do_reload:
            # need to do build and lib first so we can use @task
            reload(sys.modules['generate_dynamic.build'])
            reload(sys.modules['generate_dynamic.lib'])
            # ... and not reload them twice
            for name, module in sys.modules.items():
                if module and \
                  name.startswith('generate_dynamic') and \
                  name != 'generate_dynamic.build' and \
                  name != 'generate_dynamic.lib':
                    reload(module)
    except ImportError:
        sys.path.insert(0, path.abspath('.template'))
        sys.path.insert(0, path.abspath(path.join('.template', 'lib')))
        try:
            import generate_dynamic
        except ImportError as e:
            raise ForgeError("Couldn't import generation code: {0}".format(e))

    # make sure app is compatible with generate_dynamic logic
    if hasattr(generate_dynamic.customer_goals, 'migrate_app_to_current'):
        generate_dynamic.customer_goals.migrate_app_to_current(
            path=os.getcwd())

    return generate_dynamic
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
	def __init__(self, errors, *args, **kw):
		ForgeError.__init__(self, *args, **kw)
		self.errors = errors
Exemplo n.º 4
0
	def __init__(self, response, message, errors=None):
		ForgeError.__init__(self, message)
		self.response = response
		self.errors = errors