configurationengine/source/scripts/cone_tool.py
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
equal deleted inserted replaced
-1:000000000000 0:2e8eeb919028
       
     1 #!/usr/bin/env python
       
     2 #
       
     3 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 # All rights reserved.
       
     5 # This component and the accompanying materials are made available
       
     6 # under the terms of "Eclipse Public License v1.0"
       
     7 # which accompanies this distribution, and is available
       
     8 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 #
       
    10 # Initial Contributors:
       
    11 # Nokia Corporation - initial contribution.
       
    12 #
       
    13 # Contributors:
       
    14 #
       
    15 # Description: 
       
    16 #
       
    17 
       
    18 import sys
       
    19 
       
    20 if sys.version_info[0] >= 3 or sys.version_info[0] <= 1:
       
    21     print("WARNING: You are using not officially supported Python version:", sys.version_info[0], ".", sys.version_info[1], ".", sys.version_info[2])
       
    22     print("Officially supported versions are 2.5 and 2.6")
       
    23     sys.exit(1)
       
    24 elif sys.version_info[0] == 2:
       
    25     if sys.version_info[1] == 5 or sys.version_info[1] == 6:
       
    26         pass
       
    27     elif sys.version_info[1] == 4 or sys.version_info[1] >= 7:
       
    28         print("WARNING: You are using not officially supported Python version:", sys.version_info[0], ".", sys.version_info[1], ".", sys.version_info[2])
       
    29         print("Officially supported versions are 2.5 and 2.6")
       
    30     else:
       
    31         print("WARNING: You are using not officially supported Python version:", sys.version_info[0], ".", sys.version_info[1], ".", sys.version_info[2])
       
    32         print("Officially supported versions are 2.5 and 2.6")
       
    33         sys.exit(1)
       
    34 
       
    35 import os
       
    36 import fnmatch 
       
    37 import re
       
    38 import logging
       
    39 from optparse import OptionParser, OptionGroup
       
    40 
       
    41 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
       
    42 
       
    43 import cone
       
    44 import cone_subaction
       
    45 from cone.public import settings
       
    46 
       
    47 CONE_SCRIPT_PATTERN = 'conesub_*.py'
       
    48 ROOT_PATH           = os.path.dirname(os.path.abspath(__file__))
       
    49 SUBS                = cone_subaction.get_subactions(ROOT_PATH, CONE_SCRIPT_PATTERN)
       
    50 ACTIONS             = [sub for sub in SUBS]
       
    51 logger              = logging.getLogger('cone')
       
    52 VERSION             = cone.__version__
       
    53 if cone._svnrevision not in ("", "exported"):
       
    54     VERSION += " (SVN %s)" % cone._svnrevision
       
    55 CONE_USAGE          = "%prog [action] [options]."
       
    56 CONE_ACTIONS        = '\n'
       
    57 for act in ACTIONS:
       
    58      CONE_ACTIONS += '    %s\n' % act
       
    59 CONE_ACTION_HELP    = "Available actions %s\nUse %%prog [action] -h to get action specific help." % CONE_ACTIONS
       
    60 
       
    61 def main():
       
    62     parser = OptionParser(usage="%s\n\n%s" % (CONE_USAGE,CONE_ACTION_HELP),
       
    63                           version="%%prog %s" % VERSION,
       
    64                           prog="ConE")
       
    65     
       
    66     # Set the path for cone .cfg files to the same directory as this script
       
    67     settings.SettingsFactory.configpath = ROOT_PATH
       
    68     
       
    69     try:
       
    70         action = sys.argv[1]
       
    71         subaction = SUBS[action]
       
    72         print "Running action %s" % subaction.name
       
    73     except (IndexError, KeyError):
       
    74         (options, args) = parser.parse_args()
       
    75         parser.error("Action must be given! See --help.")
       
    76     
       
    77     subaction.run()
       
    78 
       
    79 
       
    80 if __name__ == "__main__":
       
    81     main()