def init(caf): """ Initialize the Caf repository. Usage: caf init By default create directory in .caf/db. If 'cache' is defined in ~/.config/caf/conf.yaml, the repository is created there and symlinked to .caf/db, otherwise it is created locally. """ if 'cache' in caf.conf: timestamp = get_timestamp() cache_path = Path(caf.conf['cache'])/'{}_{}'.format(Path().resolve().name, timestamp) mkdir(cache_path) relink(cache_path, caf.cache, relative=False) else: cache_path = caf.cache if cache_path.exists(): error('{} exists, cannot overwrite'.format(cache_path)) mkdir(cache_path) info('Initializing an empty repository at {}.'.format(cache_path)) mkdir(caf.cellar) mkdir(caf.brewery) with open('.gitignore', 'w') as f: f.write('\n'.join(['.caf'])) with open(os.devnull, 'w') as null: sp.call(['git', 'init'], stdout=null) sp.call(['git', 'add', 'caf', 'cscript.py', '.gitignore'], stdout=null) sp.call(['git', 'commit', '-m', 'initial commit'], stdout=null)
def build(caf, dry: '--dry', do_init: 'init'): """ Prepare tasks and targets defined in cscript. Usage: caf [init] build [--dry] Options: -n, --dry Dry run (do not write to disk). Tasks are created in .caf/db/Brewery/Latest and if their preparation does not depened on unfinished tasks, they are prepared and stored in .caf/db/Cellar based on their SHA1 hash. Targets (collections of symlinks to tasks) are created in ./build. """ if not hasattr(caf.cscript, 'build'): error('cscript has to contain function build(ctx)') if do_init: init(['caf', 'init'], caf) ctx = Context(caf.cache/cellar, caf.top, caf.libpath) with timing('dependency tree'): caf.cscript.build(ctx) if not dry: timestamp = get_timestamp() mkdir(caf.brewery/timestamp) relink(timestamp, caf.brewery/latest, relative=False) with timing('build'): ctx.build(caf.brewery/latest) if caf.out.is_dir(): shutil.rmtree(str(caf.out)) mkdir(caf.out) with timing('targets'): ctx.make_targets(caf.out, caf.cache) if hasattr(caf.cscript, 'json'): warn('Make sure json is not printing dictionaries in features') with open(os.devnull, 'w') as null: sp.call(['git', 'add', '--all', 'build'], stdout=null) sp.call(['git', 'commit', '-a', '-m', '#build'], stdout=null)