7
7
from glob import glob1
8
8
from operator import itemgetter
9
9
from os import unlink , getcwd
10
- from os .path import basename , join , abspath
10
+ from os .path import basename , join , abspath , dirname
11
11
from tarfile import TarFile
12
12
from tempfile import mktemp
13
13
14
14
from git import Repo
15
15
16
- __DIR__ = abspath (getcwd ())
16
+ __CWD_DIR__ = abspath (getcwd ())
17
+ __DIR__ = dirname (abspath (__file__ ))
18
+ __PROJECT_DIR__ = abspath (join (dirname (abspath (__file__ )), '..' ))
17
19
18
20
HEADER = """\
19
21
/*
23
25
* @author {}
24
26
*
25
27
* Generated: {}
28
+ * Academic year: 2017-2018
26
29
* Team: xkobel02, xkolar71, xpazdi02, xnguye16
27
30
* Project URL: https://github.com/thejoeejoee/IFJ-VUT-BIT-2017-2018
28
31
* Encoding: UTF-8
@@ -49,8 +52,17 @@ def _add_header(original, target_file, authors):
49
52
)
50
53
51
54
52
- def deploy (source_dir , to_archive ):
53
- source_dir = abspath (join (__DIR__ , source_dir ))
55
+ def include_tests (archive : TarFile ):
56
+ def exclude (name : str ):
57
+ return name .endswith ('pyc' ) or '__pycache__' in name
58
+
59
+ archive .add (join (__PROJECT_DIR__ , 'test.py' ), 'tests/test.py' )
60
+ for d in 'benchmark interpreter test tests __init__.py' .split ():
61
+ archive .add (join (__PROJECT_DIR__ , 'ifj2017/{}' .format (d )), 'tests/ifj2017/{}' .format (d ), exclude = exclude )
62
+
63
+
64
+ def deploy (source_dir , to_archive , tests = False ):
65
+ source_dir = abspath (join (__CWD_DIR__ , source_dir ))
54
66
source_files = set (glob1 (source_dir , '*.c' ) + glob1 (source_dir , '*.h' ) + glob1 (source_dir , 'Makefile' ))
55
67
source_files .add (join (source_dir , '../rozdeleni' ))
56
68
source_files .add (join (source_dir , '../rozsireni' ))
@@ -64,7 +76,6 @@ def deploy(source_dir, to_archive):
64
76
repository = Repo (source_dir , search_parent_directories = True )
65
77
66
78
with TarFile .open (name = to_archive , mode = 'x:gz' ) as target_archive :
67
-
68
79
for file_ in source_files :
69
80
print ('Processing {}.' .format (file_ ), file = sys .stderr )
70
81
counter = Counter (
@@ -86,6 +97,8 @@ def deploy(source_dir, to_archive):
86
97
map (itemgetter (0 ), counter .most_common ())
87
98
)
88
99
target_archive .add (modified , arcname = basename (file_ ))
100
+ if tests :
101
+ include_tests (target_archive )
89
102
90
103
91
104
def main ():
@@ -95,9 +108,10 @@ def main():
95
108
96
109
parser .add_argument ("source_dir" , help = "path to src of project" )
97
110
parser .add_argument ("archive_name" , help = "name of produced" )
111
+ parser .add_argument ("--tests" , help = "include tests?" , action = 'store_true' )
98
112
99
113
args = parser .parse_args ()
100
- return deploy (args .source_dir , args .archive_name )
114
+ return deploy (args .source_dir , args .archive_name , args . tests )
101
115
102
116
103
117
if __name__ == '__main__' :
0 commit comments