Exemple #1
0
    def pre_setup(cls):
        super(Common, cls).pre_setup()

        cls.load_features()

        ctx = Context()

        with pw.resource_set(ctx, name='main'):
            for feature in cls.FEATURES:
                requirements = []
                for req in feature.get_required_packages(cls):
                    requirements.append(req)

                if requirements:
                    ctx.apply(
                        pw.pip_package(*requirements)
                    )

        changes = ctx.changeset()

        if changes.needed():

            if len(sys.argv) == 2 and sys.argv[1] == '--requirements':
                print('\nChanges to be applied:\n')
                for item in changes.items:
                    print('\t - %s' % item.description)

                changes.commit()

                exit(0)

            else:
                print('\nSome required packages are not installed:\n')
                for item in changes.items:
                    print('\t - %s' % item.description)

                print 'Execute "cratis --requirements" to install those'

                exit(1)
Exemple #2
0
def apply_action(args):
    """
    Handles pywizard execution
    """

    path = args.path

    context = Context()

    with pw.resource_set(context, name='main', rollback=args.rollback):
        execute(path, context)

    if args.tree:
        more_indent = re.compile(r'^(\s*)', re.MULTILINE)
        print(more_indent.sub(r'\1\1\1', context.to_xml().prettify()))

    changes = context.changeset()

    if changes.needed():
        if not args.force:
            print('\nChanges to be applied:\n')
            for item in changes.items:
                print('\t - %s' % item.description)

        if not args.dry:
            if args.force or yn_choice('\nApply?', default='n'):
                changes.commit()

                print('\nChanges has been successfully applied.\n')

            else:
                print('\nNo changes has been made.\n')

    else:
        print('\nNo changes needed.\n')

    logging.info('Pywizard execution completed')
Exemple #3
0
import pywizard.api as pw
import os

ctx = pw.context(locals())


tmp_file1 = os.getcwd() + '/foo1.txt'
tmp_file2 = os.getcwd() + '/foo2.txt'
tmp_file3 = os.getcwd() + '/foo3.txt'

ctx.apply(
    pw.file(str(tmp_file1), 'foo1')
)

with pw.resource_set(ctx, name='Fooo'):

    ctx.apply(
        pw.file(str(tmp_file2), 'foo2'),
        pw.file(str(tmp_file3), 'foo3')
    )