src/tools/build_utils.py
changeset 0 ca70ae20a155
equal deleted inserted replaced
-1:000000000000 0:ca70ae20a155
       
     1 # Copyright (c) 2009 Nokia Corporation
       
     2 #
       
     3 # Licensed under the Apache License, Version 2.0 (the "License");
       
     4 # you may not use this file except in compliance with the License.
       
     5 # You may obtain a copy of the License at
       
     6 #
       
     7 #     http://www.apache.org/licenses/LICENSE-2.0
       
     8 #
       
     9 # Unless required by applicable law or agreed to in writing, software
       
    10 # distributed under the License is distributed on an "AS IS" BASIS,
       
    11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    12 # See the License for the specific language governing permissions and
       
    13 # limitations under the License.
       
    14 
       
    15 import os
       
    16 import sys
       
    17 import shutil
       
    18 import win32con
       
    19 import win32api
       
    20 import zipfile
       
    21 from subprocess import call, STDOUT
       
    22 
       
    23 
       
    24 class BuildFailedException(Exception):
       
    25     pass
       
    26 
       
    27 def deltree(top):
       
    28     for root, dirs, files in os.walk(top, topdown=False):
       
    29         for name in files:
       
    30             win32api.SetFileAttributes(os.path.join(root, name),
       
    31                                        win32con.FILE_ATTRIBUTE_NORMAL)
       
    32             os.remove(os.path.join(root, name))
       
    33         for name in dirs:
       
    34             os.rmdir(os.path.join(root, name))
       
    35     os.rmdir(top)
       
    36 
       
    37 
       
    38 def unzip_file_into_dir(file, dir):
       
    39     if not os.path.exists(dir):
       
    40         os.mkdir(dir, 0777)
       
    41     zfobj = zipfile.ZipFile(file)
       
    42     if not os.path.isdir(dir):
       
    43         os.makedirs(dir)
       
    44     for name in zfobj.namelist():
       
    45         print 'Unzipping: ', os.path.abspath(os.path.join(dir, name))
       
    46         if name.endswith('/') and \
       
    47                  not os.path.exists(os.path.abspath(os.path.join(dir, name))):
       
    48             os.makedirs(os.path.abspath(os.path.join(dir, name)))
       
    49         else:
       
    50             temp = os.path.join(os.path.abspath(dir), name)
       
    51             if not os.path.isdir(os.path.abspath(temp)):
       
    52                 print 'Unzipping: ', os.path.abspath(temp)
       
    53                 dirname = os.path.dirname(temp)
       
    54                 if not os.path.exists(dirname):
       
    55                     os.makedirs(dirname)
       
    56                 outfile = open(os.path.abspath(temp), 'wb')
       
    57                 outfile.write(zfobj.read(name))
       
    58                 outfile.close()
       
    59 
       
    60 
       
    61 def create_clean_env(epoc32_zip):
       
    62     epoc_path = '\\Epoc32'
       
    63     if os.path.exists(epoc_path):
       
    64         shutil.rmtree(epoc_path)
       
    65     unzip_file_into_dir(epoc32_zip, '\\')