def store(self): for channel in self._new_data.keys(): self._data.setdefault(channel, []).extend(self._new_data[channel]) metadata = get_project_metadata(find_project_basedir('.')) metadata.update({'channel_data': self._data}) with open(os.path.join(find_project_basedir('.'), '.leapp/info'), 'w') as f: json.dump(metadata, f, indent=2)
def cli(json): base_dir = find_project_basedir('.') load_all_from(base_dir) actors = [actor for actor in get_actors() if is_local(base_dir, actor)] models = [model for model in get_models() if is_local(base_dir, model)] channels = [ channel for channel in get_channels() if is_local(base_dir, channel) ] if not json: print_group('Models', models) print_group('Channels', channels) print_group('Actors', actors) else: output = { 'project': get_project_name(base_dir), 'base_dir': base_dir, 'channels': { channel.__name__: get_channel_details(channel) for channel in channels }, 'models': {model.__name__: get_model_details(model) for model in models}, 'actors': {actor.__name__: get_actor_details(actor) for actor in actors} } json_mod.dump(output, sys.stdout, indent=2)
def cli(actor_name, discard_output, print_output): basedir = find_project_basedir('.') load_all_from(basedir) channels = RunChannels() channels.load() [actor for actor in get_actors() if actor.name == actor_name][0](channels=channels).process() if not discard_output: channels.store() if print_output: json.dump(channels.get_new(), sys.stdout, indent=2)
def cli(model_name): basedir = find_project_basedir('.') if not basedir: raise click.UsageError( 'This command must be executed from the project directory') basedir = os.path.join(basedir, 'models') if not os.path.isdir(basedir): os.mkdir(basedir) if os.path.exists(os.path.join(basedir, model_name.lower() + '.py')): raise click.UsageError("File already exists") with open(os.path.join(basedir, model_name.lower() + '.py'), 'w') as f: f.write('''from leapp.models import Model, fields class {model_name}(Model): channel = None # TODO: import appropriate channel and set it here '''.format(model_name=make_class_name(model_name)))
def cli(channel_name): basedir = find_project_basedir('.') if not basedir: raise click.UsageError('This command must be executed from the project directory') basedir = os.path.join(basedir, 'channels') if not os.path.isdir(basedir): os.mkdir(basedir) if os.path.exists(os.path.join(basedir, channel_name.lower() + '.py')): raise click.UsageError("File already exists") with open(os.path.join(basedir, channel_name.lower() + '.py'), 'w') as f: f.write('''from leapp.channels import Channel class {channel_name}Channel(Channel): name = '{channel}' '''.format(channel_name=make_class_name(channel_name), channel=make_name(channel_name)))
def cli(actor_name): basedir = find_project_basedir('.') if not basedir: raise click.UsageError( 'This command must be executed from the project directory') actors_dir = os.path.join(basedir, 'actors') if not os.path.isdir(actors_dir): os.mkdir(actors_dir) actor_dir = os.path.join(actors_dir, actor_name.lower()) if not os.path.isdir(actor_dir): os.mkdir(actor_dir) actor_test_dir = os.path.join(actor_dir, 'tests') if not os.path.isdir(actor_test_dir): os.mkdir(actor_test_dir) actor_path = os.path.join(actor_dir, 'actor.py') if os.path.exists(actor_path): raise click.UsageError("File already exists") with open(actor_path, 'w') as f: f.write('''from leapp.actors import Actor class {actor_class}(Actor): name = '{actor_name}' description = 'For the actor {actor_name} has been no description provided.' consumes = () produces = () tags = () def process(self): pass '''.format(actor_class=make_class_name(actor_name), actor_name=make_name(actor_name)))
def get_class_file(cls): path = os.path.abspath(sys.modules[cls.__module__].__file__.replace( '.pyc', '.py')) return os.path.relpath(path, find_project_basedir('.'))
def load(self): self._data = get_project_metadata( find_project_basedir('.'))['channel_data']