From e0b81c551690401384cc04a0087ec8565c3a61d6 Mon Sep 17 00:00:00 2001 From: Radovan Bast Date: Wed, 18 May 2016 22:43:32 +0200 Subject: [PATCH] reorg --- autocmake/__init__.py | 1 + autocmake/extract.py | 14 ++++++++++++++ autocmake/generate.py | 25 ++++++++++++++++++++++++- update.py | 39 +++++---------------------------------- 4 files changed, 44 insertions(+), 35 deletions(-) create mode 100644 autocmake/extract.py diff --git a/autocmake/__init__.py b/autocmake/__init__.py index e69de29..87c0951 100644 --- a/autocmake/__init__.py +++ b/autocmake/__init__.py @@ -0,0 +1 @@ +__version__ = 'X.Y.Z' diff --git a/autocmake/extract.py b/autocmake/extract.py new file mode 100644 index 0000000..1b26002 --- /dev/null +++ b/autocmake/extract.py @@ -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 diff --git a/autocmake/generate.py b/autocmake/generate.py index 777050c..f54bbde 100644 --- a/autocmake/generate.py +++ b/autocmake/generate.py @@ -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) diff --git a/update.py b/update.py index c021161..5a31141 100644 --- a/update.py +++ b/update.py @@ -2,12 +2,9 @@ import os import sys -import datetime import ast import collections -__version__ = 'X.Y.Z' - AUTOCMAKE_GITHUB_URL = 'https://github.com/coderefinery/autocmake/raw/yaml/' @@ -21,20 +18,6 @@ def print_progress_bar(text, done, total, width): sys.stdout.flush() -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) - - def prepend_or_set(config, section, option, value, defaults): """ If option is already set, then value is prepended. @@ -48,28 +31,13 @@ def prepend_or_set(config, section, option, value, defaults): return config -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 - - def fetch_modules(config, relative_path): """ Assemble modules which will be included in CMakeLists.txt. """ from collections import Iterable + from autocmake.extract import extract_list download_directory = 'downloaded' if not os.path.exists(download_directory): @@ -148,6 +116,7 @@ def fetch_modules(config, relative_path): def process_yaml(argv): from autocmake.parse_yaml import parse_yaml + from autocmake.generate import gen_cmakelists, gen_setup project_root = argv[1] if not os.path.isdir(project_root): @@ -241,8 +210,10 @@ def main(argv): with open('.gitignore', 'w') as f: f.write('*.pyc\n') for f in ['autocmake/configure.py', - 'autocmake/external/docopt.py', 'autocmake/__init__.py', + 'autocmake/external/docopt.py', + 'autocmake/generate.py', + 'autocmake/extract.py', 'autocmake/interpolate.py', 'autocmake/parse_rst.py', 'autocmake/parse_yaml.py',