fix for bug 3970
[blender-staging.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' or sys.platform == 'cygwin':
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/python24.dll", "dist/python24.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/plugins"):
82             shutil.rmtree("dist/plugins")
83         os.makedirs("dist/plugins/include")
84         shutil.copy("source/blender/blenpluginapi/documentation.h", "dist/plugins/include/documentation.h")
85         shutil.copy("source/blender/blenpluginapi/floatpatch.h", "dist/plugins/include/floatpatch.h")
86         shutil.copy("source/blender/blenpluginapi/iff.h", "dist/plugins/include/iff.h")
87         shutil.copy("source/blender/blenpluginapi/plugin.h", "dist/plugins/include/plugin.h")
88         shutil.copy("source/blender/blenpluginapi/util.h", "dist/plugins/include/util.h")
89
90         os.chdir("release")
91         shutil.copytree("scripts/", "../dist/.blender/scripts")
92         # finally copy auxiliaries (readme, license, etc.)
93         if sys.platform == 'win32':
94                 shutil.copy("windows/extra/Help.url", "../dist/Help.url")
95                 shutil.copy("windows/extra/Python24.zip", "../dist/Python24.zip")
96                 shutil.copy("windows/extra/zlib.pyd", "../dist/zlib.pyd")
97         shutil.copy("text/copyright.txt", "../dist/copyright.txt")
98         shutil.copy("text/blender.html", "../dist/blender.html")
99         shutil.copy("text/GPL-license.txt", "../dist/GPL-license.txt")
100         shutil.copy("text/Python-license.txt", "../dist/Python-license.txt")
101         
102         reltext = "release_" + string.join(bs_globals.version.split("."), '') + ".txt"
103         shutil.copy("text/" + reltext, "../dist/" + reltext)
104         
105         os.chdir(startdir)
106         
107         if cleanCVS()==0:
108                 return 0
109         return 1
110
111 def finalisedist(zipname):
112         """
113         Fetch the package created and remove temp dir
114         """
115         
116         try:
117                 import shutil
118         except:
119                 print "no shutil available"
120                 print "make sure you use python 2.3"
121                 print
122                 return 0
123         
124         #shutil.copy("dist/" + zipname, zipname)
125         #shutil.rmtree("dist")
126         
127         return 1