reorg
This commit is contained in:
parent
0d500bc838
commit
e0b81c5516
@ -0,0 +1 @@
|
||||
__version__ = 'X.Y.Z'
|
14
autocmake/extract.py
Normal file
14
autocmake/extract.py
Normal 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
|
@ -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)
|
||||
|
39
update.py
39
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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user