restore --self
This commit is contained in:
parent
e36af9059b
commit
c2fb14b22e
@ -1,28 +0,0 @@
|
||||
def fetch_url(src, dst):
|
||||
"""
|
||||
Fetch file from URL src and save it to dst.
|
||||
"""
|
||||
# we do not use the nicer sys.version_info.major
|
||||
# for compatibility with Python < 2.7
|
||||
if sys.version_info[0] > 2:
|
||||
import urllib.request
|
||||
|
||||
class URLopener(urllib.request.FancyURLopener):
|
||||
def http_error_default(self, url, fp, errcode, errmsg, headers):
|
||||
sys.stderr.write("ERROR: could not fetch {0}\n".format(url))
|
||||
sys.exit(-1)
|
||||
else:
|
||||
import urllib
|
||||
|
||||
class URLopener(urllib.FancyURLopener):
|
||||
def http_error_default(self, url, fp, errcode, errmsg, headers):
|
||||
sys.stderr.write("ERROR: could not fetch {0}\n".format(url))
|
||||
sys.exit(-1)
|
||||
|
||||
dirname = os.path.dirname(dst)
|
||||
if dirname != '':
|
||||
if not os.path.isdir(dirname):
|
||||
os.makedirs(dirname)
|
||||
|
||||
opener = URLopener()
|
||||
opener.retrieve(src, dst)
|
156
update.py
156
update.py
@ -11,8 +11,6 @@ __version__ = 'X.Y.Z'
|
||||
|
||||
AUTOCMAKE_GITHUB_URL = 'https://github.com/coderefinery/autocmake/raw/yaml/'
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def print_progress_bar(text, done, total, width):
|
||||
"""
|
||||
@ -22,8 +20,6 @@ def print_progress_bar(text, done, total, width):
|
||||
sys.stdout.write("\r{0} [{1}{2}] ({3}/{4})".format(text, '#' * n, ' ' * (width - n), done, total))
|
||||
sys.stdout.flush()
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def align_options(options):
|
||||
"""
|
||||
@ -38,8 +34,6 @@ def align_options(options):
|
||||
s.append(' {0}{1} {2}'.format(opt[0], ' ' * (l - len(opt[0])), opt[1]))
|
||||
return '\n'.join(s)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def gen_cmake_command(config):
|
||||
"""
|
||||
@ -72,8 +66,6 @@ def gen_cmake_command(config):
|
||||
|
||||
return '\n'.join(s)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def autogenerated_notice():
|
||||
current_year = datetime.date.today().year
|
||||
@ -83,8 +75,6 @@ def autogenerated_notice():
|
||||
s.append('# Copyright (c) {0} by Radovan Bast, Jonas Juselius, and contributors.'.format(year_range))
|
||||
return '\n'.join(s)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def gen_setup(config, relative_path, setup_script_name):
|
||||
"""
|
||||
@ -155,8 +145,6 @@ def gen_setup(config, relative_path, setup_script_name):
|
||||
|
||||
return s
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def gen_cmakelists(project_name, min_cmake_version, relative_path, modules):
|
||||
"""
|
||||
@ -200,8 +188,6 @@ def gen_cmakelists(project_name, min_cmake_version, relative_path, modules):
|
||||
|
||||
return s
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def prepend_or_set(config, section, option, value, defaults):
|
||||
"""
|
||||
@ -215,8 +201,6 @@ def prepend_or_set(config, section, option, value, defaults):
|
||||
config.set(section, option, value)
|
||||
return config
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def extract_list(config, section):
|
||||
from collections import Iterable
|
||||
@ -233,8 +217,6 @@ def extract_list(config, section):
|
||||
l.append(x[section])
|
||||
return l
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def fetch_modules(config, relative_path):
|
||||
"""
|
||||
@ -242,7 +224,6 @@ def fetch_modules(config, relative_path):
|
||||
be included in CMakeLists.txt.
|
||||
"""
|
||||
from collections import Iterable
|
||||
from autocmake.http import fetch_url
|
||||
|
||||
download_directory = 'downloaded'
|
||||
if not os.path.exists(download_directory):
|
||||
@ -318,60 +299,9 @@ def fetch_modules(config, relative_path):
|
||||
|
||||
return modules
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def main(argv):
|
||||
"""
|
||||
Main function.
|
||||
"""
|
||||
def process_yaml():
|
||||
from autocmake.parse_yaml import parse_yaml
|
||||
from autocmake.http import fetch_url
|
||||
|
||||
if len(argv) != 2:
|
||||
sys.stderr.write("\nYou can update a project in two steps.\n\n")
|
||||
sys.stderr.write("Step 1: Update or create infrastructure files\n")
|
||||
sys.stderr.write(" which will be needed to configure and build the project:\n")
|
||||
sys.stderr.write(" $ {0} --self\n\n".format(argv[0]))
|
||||
sys.stderr.write("Step 2: Create CMakeLists.txt and setup script in PROJECT_ROOT:\n")
|
||||
sys.stderr.write(" $ {0} <PROJECT_ROOT>\n".format(argv[0]))
|
||||
sys.stderr.write(" example:\n")
|
||||
sys.stderr.write(" $ {0} ..\n".format(argv[0]))
|
||||
sys.exit(-1)
|
||||
|
||||
if argv[1] in ['-h', '--help']:
|
||||
print('Usage:')
|
||||
print(' python update.py --self Update this script and fetch or update infrastructure files under autocmake/.')
|
||||
print(' python update.py <builddir> (Re)generate CMakeLists.txt and setup script and fetch or update CMake modules.')
|
||||
print(' python update.py (-h | --help) Show this help text.')
|
||||
sys.exit(0)
|
||||
|
||||
if argv[1] == '--self':
|
||||
# update self
|
||||
if not os.path.isfile('autocmake.yml'):
|
||||
print('- fetching example autocmake.yml')
|
||||
fetch_url(
|
||||
src='{0}example/autocmake.yml'.format(AUTOCMAKE_GITHUB_URL),
|
||||
dst='autocmake.yml'
|
||||
)
|
||||
if not os.path.isfile('.gitignore'):
|
||||
print('- creating .gitignore')
|
||||
with open('.gitignore', 'w') as f:
|
||||
f.write('*.pyc\n')
|
||||
for f in ['autocmake/configure.py',
|
||||
'autocmake/external/docopt.py',
|
||||
'autocmake/__init__.py',
|
||||
'autocmake/interpolate.py',
|
||||
'autocmake/http.py',
|
||||
'autocmake/parse_rst.py',
|
||||
'autocmake/parse_yaml.py',
|
||||
'update.py']:
|
||||
print('- fetching {0}'.format(f))
|
||||
fetch_url(
|
||||
src='{0}{1}'.format(AUTOCMAKE_GITHUB_URL, f),
|
||||
dst='{0}'.format(f)
|
||||
)
|
||||
sys.exit(0)
|
||||
|
||||
project_root = argv[1]
|
||||
if not os.path.isdir(project_root):
|
||||
@ -424,16 +354,94 @@ def main(argv):
|
||||
if sys.platform != 'win32':
|
||||
make_executable(file_path)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
def main(argv):
|
||||
"""
|
||||
Main function.
|
||||
"""
|
||||
|
||||
if len(argv) != 2:
|
||||
sys.stderr.write("\nYou can update a project in two steps.\n\n")
|
||||
sys.stderr.write("Step 1: Update or create infrastructure files\n")
|
||||
sys.stderr.write(" which will be needed to configure and build the project:\n")
|
||||
sys.stderr.write(" $ {0} --self\n\n".format(argv[0]))
|
||||
sys.stderr.write("Step 2: Create CMakeLists.txt and setup script in PROJECT_ROOT:\n")
|
||||
sys.stderr.write(" $ {0} <PROJECT_ROOT>\n".format(argv[0]))
|
||||
sys.stderr.write(" example:\n")
|
||||
sys.stderr.write(" $ {0} ..\n".format(argv[0]))
|
||||
sys.exit(-1)
|
||||
|
||||
if argv[1] in ['-h', '--help']:
|
||||
print('Usage:')
|
||||
print(' python update.py --self Update this script and fetch or update infrastructure files under autocmake/.')
|
||||
print(' python update.py <builddir> (Re)generate CMakeLists.txt and setup script and fetch or update CMake modules.')
|
||||
print(' python update.py (-h | --help) Show this help text.')
|
||||
sys.exit(0)
|
||||
|
||||
if argv[1] == '--self':
|
||||
# update self
|
||||
if not os.path.isfile('autocmake.yml'):
|
||||
print('- fetching example autocmake.yml')
|
||||
fetch_url(
|
||||
src='{0}example/autocmake.yml'.format(AUTOCMAKE_GITHUB_URL),
|
||||
dst='autocmake.yml'
|
||||
)
|
||||
if not os.path.isfile('.gitignore'):
|
||||
print('- creating .gitignore')
|
||||
with open('.gitignore', 'w') as f:
|
||||
f.write('*.pyc\n')
|
||||
for f in ['autocmake/configure.py',
|
||||
'autocmake/external/docopt.py',
|
||||
'autocmake/__init__.py',
|
||||
'autocmake/interpolate.py',
|
||||
'autocmake/parse_rst.py',
|
||||
'autocmake/parse_yaml.py',
|
||||
'update.py']:
|
||||
print('- fetching {0}'.format(f))
|
||||
fetch_url(
|
||||
src='{0}{1}'.format(AUTOCMAKE_GITHUB_URL, f),
|
||||
dst='{0}'.format(f)
|
||||
)
|
||||
sys.exit(0)
|
||||
|
||||
process_yaml()
|
||||
|
||||
|
||||
# http://stackoverflow.com/a/30463972
|
||||
def make_executable(path):
|
||||
# http://stackoverflow.com/a/30463972
|
||||
mode = os.stat(path).st_mode
|
||||
mode |= (mode & 0o444) >> 2 # copy R bits to X
|
||||
os.chmod(path, mode)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
def fetch_url(src, dst):
|
||||
"""
|
||||
Fetch file from URL src and save it to dst.
|
||||
"""
|
||||
# we do not use the nicer sys.version_info.major
|
||||
# for compatibility with Python < 2.7
|
||||
if sys.version_info[0] > 2:
|
||||
import urllib.request
|
||||
|
||||
class URLopener(urllib.request.FancyURLopener):
|
||||
def http_error_default(self, url, fp, errcode, errmsg, headers):
|
||||
sys.stderr.write("ERROR: could not fetch {0}\n".format(url))
|
||||
sys.exit(-1)
|
||||
else:
|
||||
import urllib
|
||||
|
||||
class URLopener(urllib.FancyURLopener):
|
||||
def http_error_default(self, url, fp, errcode, errmsg, headers):
|
||||
sys.stderr.write("ERROR: could not fetch {0}\n".format(url))
|
||||
sys.exit(-1)
|
||||
|
||||
dirname = os.path.dirname(dst)
|
||||
if dirname != '':
|
||||
if not os.path.isdir(dirname):
|
||||
os.makedirs(dirname)
|
||||
|
||||
opener = URLopener()
|
||||
opener.retrieve(src, dst)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user