-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode_export.py
62 lines (42 loc) · 1.67 KB
/
code_export.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
'''This script copies all text files into specified folder.
Also it checks: are there extra files in "path_to_text" directory
and shows their names.
Author: Vladislav Naumov. [email protected]; github.com/vlad1777d; vk.com/naumovvladislav
License: CC-BY. To use this under other license contact author.
Revision: 2
'''
folder_to_copy = '../../../code-upbge'
import bpy
import os # to get abs. path and list of files in dir ("os.listdir()")
filepath = bpy.data.filepath
filepath = filepath[:filepath.rfind('/') + 1]
path_to_text = os.path.abspath(filepath + folder_to_copy)
names_inner_texts = bpy.data.texts.keys()
extra_texts = []
def check_for_extra_files():
'''Checks: are files, that are not present in current .blend file,
present in "path_to_text" folder.
'''
global extra_texts
for text in os.listdir(path=path_to_text):
if text.startswith('.'):
continue
elif text in names_inner_texts:
continue
else:
extra_texts.append(text)
if len(extra_texts) > 0:
print('Found {0} extra text files:'.format(len(extra_texts)), '\n', extra_texts, '\n')
def write_files():
print('Starting writting files to {0}'.format(path_to_text))
for key in names_inner_texts:
obj = bpy.data.texts[key]
with open( path_to_text + '/{name}'.format(name=key), 'tw' ) as file_to_write:
file_to_write.write( obj.as_string() )
print('File {name} was successfully written.'.format(name=key))
print('\n', 'All files were written.', sep='')
print('Found {0} extra text files. Their names were specified earlier above.'.format(len(extra_texts)))
print('\n\n\n', 'Script "code export" started.', '\n')
#if __name__ == 'main': # doesn't work
check_for_extra_files()
write_files()