build/sis/nouserpromptspolicy/generatePolicies.py
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 
       
    17 import socket, sys, os
       
    18 import traceback
       
    19 
       
    20 def main():
       
    21     try:
       
    22         java_src_root = os.environ["JAVA_SRC_ROOT"]
       
    23         values = {}
       
    24         
       
    25         # init
       
    26         os.mkdir( java_src_root + "/build/sis/nouserpromptspolicy/tmp" )
       
    27         
       
    28         # generate the policies in external format
       
    29         replaceInFile(java_src_root + "/javacommons/security/data/s60_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/s60_manufacturer.txt", values)
       
    30         replaceInFile(java_src_root + "/javacommons/security/data/msa_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/msa_manufacturer.txt", values)
       
    31         replaceInFile(java_src_root + "/javacommons/security/data/att_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/att_manufacturer.txt", values)
       
    32         values["Manufacturer"] = "Operator"
       
    33         replaceInFile(java_src_root + "/javacommons/security/data/s60_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/s60_operator.txt", values)
       
    34         replaceInFile(java_src_root + "/javacommons/security/data/msa_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/msa_operator.txt", values)
       
    35         replaceInFile(java_src_root + "/javacommons/security/data/att_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/att_operator.txt", values)
       
    36         values["Manufacturer"] = "OperatorExtra"
       
    37         replaceInFile(java_src_root + "/javacommons/security/data/s60_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/s60_operatorextra.txt", values)
       
    38         replaceInFile(java_src_root + "/javacommons/security/data/msa_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/msa_operatorextra.txt", values)
       
    39         replaceInFile(java_src_root + "/javacommons/security/data/att_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/att_operatorextra.txt", values)
       
    40         values["Manufacturer"] = "IdentifiedThirdParty"
       
    41         replaceInFile(java_src_root + "/javacommons/security/data/s60_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/s60_trustedthirdparty.txt", values)
       
    42         replaceInFile(java_src_root + "/javacommons/security/data/msa_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/msa_trustedthirdparty.txt", values)
       
    43         replaceInFile(java_src_root + "/javacommons/security/data/att_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/att_trustedthirdparty.txt", values)
       
    44         values["Manufacturer"] = "UnidentifiedThirdParty"
       
    45         replaceInFile(java_src_root + "/javacommons/security/data/s60_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/s60_untrusted.txt", values)
       
    46         replaceInFile(java_src_root + "/javacommons/security/data/msa_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/msa_untrusted.txt", values)
       
    47         replaceInFile(java_src_root + "/javacommons/security/data/att_manufacturer.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/att_untrusted.txt", values)
       
    48         values["All"] = "All"
       
    49         replaceInFile(java_src_root + "/javacommons/security/data/all.txt", java_src_root + "/build/sis/nouserpromptspolicy/tmp/all.txt", values)
       
    50         
       
    51         # generate the policies in internal format
       
    52         cmd = "java -cp " + java_src_root + "/javatools/javasecuritycustomization/policyeditor/bin/securitypolicyeditor.jar;" + java_src_root + "/javatools/javasecuritycustomization/policyeditor/lib/engine.jar com.nokia.mj.tools.security.midp.PolicyEditor " + java_src_root + "/build/sis/nouserpromptspolicy/tmp " + java_src_root + "/build/sis/nouserpromptspolicy"
       
    53         os.system(cmd)
       
    54 
       
    55         # cleanup
       
    56         remove_tree( java_src_root + "/build/sis/nouserpromptspolicy/tmp" )
       
    57 
       
    58     except:
       
    59         traceback.print_exc()
       
    60         sys.exit(1)
       
    61 
       
    62 
       
    63 def replaceInFile(srcFile, dstFile, values={}):
       
    64     f = open(srcFile, "r")
       
    65     data = f.read()
       
    66     f.close()
       
    67     
       
    68     for key, value in values.items():
       
    69         data = data.replace("%s" % key, value)
       
    70     
       
    71     f = open(dstFile, "w")
       
    72     f.write(data)
       
    73     f.close()
       
    74 
       
    75 def remove_tree(path):
       
    76     for i in os.listdir(path):
       
    77         elem = path + "/" + i
       
    78         if os.path.isdir(elem):
       
    79             remove_tree(elem)
       
    80         else:
       
    81             os.remove(elem)
       
    82     os.rmdir(path)
       
    83 
       
    84 
       
    85 if __name__ == "__main__":
       
    86     main()