This commit is contained in:
Radovan Bast
2016-05-18 22:43:32 +02:00
parent 0d500bc838
commit e0b81c5516
4 changed files with 44 additions and 35 deletions

View File

@ -0,0 +1 @@
__version__ = 'X.Y.Z'

14
autocmake/extract.py Normal file
View File

@ -0,0 +1,14 @@
def extract_list(config, section):
from collections import Iterable
l = []
if 'modules' in config:
for module in config['modules']:
for k, v in module.items():
for x in v:
if section in x:
if isinstance(x[section], Iterable) and not isinstance(x[section], str):
for y in x[section]:
l.append(y)
else:
l.append(x[section])
return l

View File

@ -2,8 +2,9 @@ def gen_cmake_command(config):
"""
Generate CMake command.
"""
s = []
from autocmake.extract import extract_list
s = []
s.append("\n\ndef gen_cmake_command(options, arguments):")
s.append(' """')
s.append(" Generate CMake command based on options and arguments.")
@ -32,11 +33,15 @@ def gen_cmake_command(config):
def autogenerated_notice():
from datetime import date
from . import __version__
current_year = date.today().year
year_range = '2015-{0}'.format(current_year)
s = []
s.append('# This file is autogenerated by Autocmake v{0} http://autocmake.org'.format(__version__))
s.append('# Copyright (c) {0} by Radovan Bast, Jonas Juselius, and contributors.'.format(year_range))
return '\n'.join(s)
@ -44,6 +49,8 @@ def gen_setup(config, relative_path, setup_script_name):
"""
Generate setup script.
"""
from autocmake.extract import extract_list
s = []
s.append('#!/usr/bin/env python')
s.append('\n{0}'.format(autogenerated_notice()))
@ -114,6 +121,8 @@ def gen_cmakelists(project_name, min_cmake_version, relative_path, modules):
"""
Generate CMakeLists.txt.
"""
import os
s = []
s.append(autogenerated_notice())
@ -151,3 +160,17 @@ def gen_cmakelists(project_name, min_cmake_version, relative_path, modules):
s.append('include({0})'.format(os.path.splitext(module.name)[0]))
return s
def align_options(options):
"""
Indents flags and aligns help texts.
"""
l = 0
for opt in options:
if len(opt[0]) > l:
l = len(opt[0])
s = []
for opt in options:
s.append(' {0}{1} {2}'.format(opt[0], ' ' * (l - len(opt[0])), opt[1]))
return '\n'.join(s)