diff --git a/example/README.md b/example/README.md index 113ac88526addf98475f9bda47dbe5afa41dea91..44bc8a9e2c519412a4aca746ca5c71a9d49b36fb 100644 --- a/example/README.md +++ b/example/README.md @@ -1,12 +1,15 @@ # example -This is description of the box. It will be copied. Keep it short and single-line. Don't remove the line break before. +Example box. Not compiled. Keep four lines in same order. Version: 1.0 -Write what this box consists of and how it behaves. -First four lines have a special meaning - dont move them around. Change only version number, not the word. +This section will be automatically replaced by `python make.py` with auto-generated +content of Vagrantfile that will refer to this box. --- -This section will be automatically replaced by `python make.py` with auto-generated -content of Vagrantfile that will refer to this box. +Usage in Vagrantfile: +``` +config.vm.box = "henrietta/example" +config.vm.box_url = "http://dev.dms-serwis.com.pl/vagrant/example.box" +``` diff --git a/make.py b/make.py index fd569bf482f6a68fca410b64434de7df8d85c17e..fe368ee9eaecd1f2bf3b6ece6d7a37837a8c38ef 100644 --- a/make.py +++ b/make.py @@ -30,15 +30,18 @@ def readfile(path, prefix=None, lines=False, strip=True): return d -def writefile(content, path, prefix=None): +def writefile(content, path, prefix=None, lines=False): if prefix is not None: path = os.path.join(prefix, path) - with open(path, 'wb') as f: - if not isinstance(content, list): - content = [content] - for piece in content: - f.write(piece) + with open(path, 'w' if lines else 'wb') as f: + if lines: + f.writelines([q+'\n' for q in content]) + else: + if not isinstance(content, list): + content = [content] + for piece in content: + f.write(piece) if __name__ == '__main__': @@ -52,18 +55,20 @@ if __name__ == '__main__': for box in boxes: - readme = '\n---\n'.join(readfile('README.md', box).split('\n---\n')[:-1]) - readme = readme + ''' ---- + readme = readfile('README.md', box, lines=True, strip=True) + + if '---' in readme: + try: + readme = readme[readme.index('---')+1:] + except IndexError: + readme = readme[:-1] -Usage in Vagrantfile: -``` -config.vm.box = "$PREFIX$BOX" -config.vm.box_url = "http://dev.dms-serwis.com.pl/vagrant/$BOX.box" -``` -'''.replace('$BOX', box).replace('$PREFIX', PREFIX) + readme = readme + ['', '---', '', 'Usage in Vagrantfile:', '```', + 'config.vm.box = "'+PREFIX+box+'"', + 'config.vm.box_url = "http://dev.dms-serwis.com.pl/vagrant/'+box+'.box"', + '```'] - writefile(readme, 'README.md', box) + writefile(readme, 'README.md', box, lines=True) try: os.unlink(os.path.join(box, 'metadata.json'))