-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdevmerge.py
101 lines (77 loc) · 3.21 KB
/
devmerge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- coding: utf-8 -*-
"""
Copyright (c) 2018 beyond-blockchain.org.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
"""
This is a developers tool used for developing libraries and subsystems for
BBc-1 (Beyond Blockchain One), before making these pip-installable.
This tool copies source files being developed onto the core source code tree.
"""
import argparse
import os
import subprocess
DIRS = ['bbc1', 'examples', 'lib', 'tests', 'utils']
EXTS = ['py', 'sol']
def copy_dir(coredir, dir, verbose=False, test=False, remove=False):
files = os.listdir(dir)
for filename in files:
if filename[:1] != '_':
s = filename.split('.')
if s[len(s) - 1] in EXTS:
if remove:
remove_file(coredir, dir, filename, verbose=verbose,
test=test)
else:
copy_file(coredir, dir, filename, verbose=verbose,
test=test)
else:
path = os.path.join(dir, filename)
if os.path.isdir(path):
copy_dir(coredir, path, verbose=verbose, test=test,
remove=remove)
def copy_file(coredir, dir, filename, verbose=False, test=False):
source = os.path.join(dir, filename)
dest = os.path.join(coredir, dir)
if not os.path.exists(dest) and not test:
os.mkdir(dest)
if verbose:
print('cp', source, os.path.join(dest, '.'))
if not test:
subprocess.call(['cp', source, os.path.join(dest, '.')])
def parse_arguments():
argparser = argparse.ArgumentParser(
description='Copy files being developed onto core source code tree'
' or remove them.'
)
argparser.add_argument('-d', '--coredir', type=str, action='store',
help='directory of BBc-1 core', default='bbc1')
argparser.add_argument('-rm', '--remove', action='store_true',
help='remove copied files (leave directories)')
argparser.add_argument('-t', '--test', action='store_true',
help='does not make copies or directories')
argparser.add_argument('-v', '--verbose', action='store_true',
help='verbose output')
return argparser.parse_args()
def remove_file(coredir, dir, filename, verbose=False, test=False):
dest = os.path.join(coredir, dir)
if verbose:
print('rm', os.path.join(dest, filename))
if not test:
subprocess.call(['rm', os.path.join(dest, filename)])
if __name__ == '__main__':
args = parse_arguments()
dest = os.path.join('..', args.coredir)
for dir in DIRS:
if os.path.exists(dir):
copy_dir(dest, dir, verbose=args.verbose, test=args.test,
remove=args.remove)
# end of devmerge.py