4d1482b436e57ae1a0b42b2f0ffc8ddf9f720e3a
[blender.git] / tools / scons / bs / bs_dirs.py
1 # functions used for dir handling / preperation / cleaning
2
3 import os
4 import string
5 import sys
6 import bs_globals
7
8 def cleanCVS():
9         """
10         walks the dist dir and removes all CVS dirs
11         """
12         
13         try:
14                 import shutil
15         except:
16                 print "no shutil available"
17                 print "make sure you use python 2.3"
18                 print
19                 return 0
20         
21         startdir = os.getcwd()
22         
23         for root, dirs, files in os.walk("dist", topdown=False):
24                 for name in dirs:
25                         if name in ['CVS']:
26                                 if os.path.isdir(root + "/" + name):
27                                         shutil.rmtree(root + "/" + name)
28         
29         os.chdir(startdir)
30         
31         return 1
32
33 def preparedist():
34         """
35         Prepare a directory for creating either archives or the installer
36         """
37         
38         try:
39                 import shutil
40                 import time
41                 import stat
42         except:
43                 print "no shutil available"
44                 print "make sure you use python 2.3"
45                 print
46                 return 0
47         
48         startdir = os.getcwd()
49         
50         if os.path.isdir("dist") == 0:
51                 os.makedirs("dist")
52         else:
53                 shutil.rmtree("dist") # make sure we don't get old cruft
54                 os.makedirs("dist")
55         
56         # first copy binaries
57         
58         if sys.platform == 'win32':
59                 shutil.copy("blender.exe", "dist/blender.exe")
60                 if bs_globals.user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
61                         shutil.copy("blenderplayer.exe", "dist/blenderplayer.exe")
62                 shutil.copy("../lib/windows/python/lib/python23.dll", "dist/python23.dll")
63                 shutil.copy("../lib/windows/sdl/lib/SDL.dll", "dist/SDL.dll")
64                 shutil.copy("../lib/windows/gettext/lib/gnu_gettext.dll", "dist/gnu_gettext.dll")
65         elif sys.platform in ['linux2', 'linux-i386', 'freebsd4', 'freebsd5']:
66                 shutil.copy("blender", "dist/blender")
67                 if bs_globals.user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
68                         shutil.copy("blenderplayer", "dist/blenderplayer")
69         else:
70                 print "update preparedist() for your platform!"
71                 return 0
72         
73         # now copy .blender and necessary extras for it
74         if os.path.isdir("dist/.blender"):
75                 shutil.rmtree("dist/.blender")
76         os.chdir("bin")
77         shutil.copytree(".blender/", "../dist/.blender")
78         os.chdir(startdir)
79         if os.path.isdir("dist/.blender/scripts"):
80                 shutil.rmtree("dist/.blender/scripts")
81         if os.path.isdir("dist/.blender/bpydata"):
82                 shutil.rmtree("dist/.blender/bpydata")
83                 
84         os.makedirs("dist/.blender/bpydata")
85         shutil.copy("release/bpydata/readme.txt", "dist/.blender/bpydata/readme.txt")
86         shutil.copy("release/bpydata/KUlang.txt", "dist/.blender/bpydata/KUlang.txt")
87         
88         os.chdir("release")
89         shutil.copytree("scripts/", "../dist/.blender/scripts")
90         
91         # finally copy auxiliaries (readme, license, etc.)
92         if sys.platform == 'win32':
93                 shutil.copy("windows/extra/Help.url", "../dist/Help.url")
94                 shutil.copy("windows/extra/Python23.zip", "../dist/Python23.zip")
95                 shutil.copy("windows/extra/zlib.pyd", "../dist/zlib.pyd")
96         shutil.copy("text/copyright.txt", "../dist/copyright.txt")
97         shutil.copy("text/blender.html", "../dist/blender.html")
98         shutil.copy("text/GPL-license.txt", "../dist/GPL-license.txt")
99         shutil.copy("text/Python-license.txt", "../dist/Python-license.txt")
100         
101         reltext = "release_" + string.join(bs_globals.version.split("."), '') + ".txt"
102         shutil.copy("text/" + reltext, "../dist/" + reltext)
103         
104         os.chdir(startdir)
105         
106         if cleanCVS()==0:
107                 return 0
108         return 1
109
110 def finalisedist(zipname):
111         """
112         Fetch the package created and remove temp dir
113         """
114         
115         try:
116                 import shutil
117         except:
118                 print "no shutil available"
119                 print "make sure you use python 2.3"
120                 print
121                 return 0
122         
123         #shutil.copy("dist/" + zipname, zipname)
124         #shutil.rmtree("dist")
125         
126         return 1