configurationengine/source/scripts/cone_common.py
changeset 3 e7e0ae78773e
parent 0 2e8eeb919028
equal deleted inserted replaced
2:87cfa131b535 3:e7e0ae78773e
    31 This is done mainly for local installation and testing purposes. 
    31 This is done mainly for local installation and testing purposes. 
    32 """
    32 """
    33 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
    33 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
    34 
    34 
    35 try:
    35 try:
    36     from cone.public import api, settings
    36     from cone.public import api, settings, utils
    37 except ImportError:
    37 except ImportError:
    38     sys.path.append(os.path.join(ROOT_PATH))
    38     sys.path.append(os.path.join(ROOT_PATH))
    39     sys.path.append(os.path.join(ROOT_PATH,'..'))
    39     sys.path.append(os.path.join(ROOT_PATH,'..'))
    40     from cone.public import api, settings
    40     from cone.public import api, settings, utils
    41 
    41 
    42 # Common command line options used by all sub-actions
    42 # Common command line options used by all sub-actions
    43 COMMON_OPTIONS = [
    43 COMMON_OPTIONS = [
    44     Option("--print-settings",
    44     Option("--print-settings",
    45            dest="print_settings",
    45            dest="print_settings",
    67                                     WARNING       3
    67                                     WARNING       3
    68                                     INFO          4
    68                                     INFO          4
    69                                     DEBUG         5""",
    69                                     DEBUG         5""",
    70           metavar="LEVEL",
    70           metavar="LEVEL",
    71           default="3"),
    71           default="3"),
    72     
    72 
    73     Option("--log-file",
    73     Option("--log-file",
    74            dest="log_file",
    74            dest="log_file",
    75            action="store",
    75            action="store",
    76            type="string",
    76            type="string",
    77            help="Location of the used log file. Default is 'cone.log'",
    77            help="Location of the used log file. Default is 'cone.log'",
    88     Option("--username",
    88     Option("--username",
    89            dest="username",
    89            dest="username",
    90            action="store",
    90            action="store",
    91            type="string",
    91            type="string",
    92            help="Username for webstorage operations. Not needed for filestorage or cpf storage. If the username \
    92            help="Username for webstorage operations. Not needed for filestorage or cpf storage. If the username \
    93            is not given, the tool will use the loggged in username.",
    93            is not given, the tool will use the logged in username. "\
       
    94            "Example: cone export -p webstorage_url -r . -c sample.confml --username=admin --password=abc123.",
    94            metavar="USERNAME"),
    95            metavar="USERNAME"),
    95 
    96 
    96     Option("--password",
    97     Option("--password",
    97            dest="password",
    98            dest="password",
    98            action="store",
    99            action="store",
    99            type="string",
   100            type="string",
   100            help="Password for webstorage operations. Not needed for filestorage or cpf storage. If the password \
   101            help="Password for webstorage operations. Not needed for filestorage or cpf storage. If the password \
   101            is not given, the tool will prompt for password if needed.",
   102            is not given, the tool will prompt for password if needed. ",
   102            metavar="PASSWORD"),
   103            metavar="PASSWORD"),
   103 ]
   104 ]
   104 
   105 
   105 def handle_common_options(options, settings=None):
   106 def handle_common_options(options, settings=None):
   106     """
   107     """
   154             "Script location: %s" % ROOT_PATH]
   155             "Script location: %s" % ROOT_PATH]
   155     return '\n'.join(info)
   156     return '\n'.join(info)
   156 
   157 
   157 def open_log(verbose, log_file, log_conf_file=os.path.join(ROOT_PATH, 'logging.ini')):
   158 def open_log(verbose, log_file, log_conf_file=os.path.join(ROOT_PATH, 'logging.ini')):
   158     try:
   159     try:
       
   160         # Convert the reference to the log file as a absolute path so that it would work in all scenarios
       
   161         log_file = repr(os.path.abspath(log_file))
       
   162         
       
   163         if log_file.startswith("'"):
       
   164             log_file = log_file.replace("'", '', 1)
       
   165         if log_file.endswith("'"):
       
   166             log_file = log_file.replace("'",'', 1)
       
   167 
   159         log_dir = os.path.dirname(log_file)
   168         log_dir = os.path.dirname(log_file)
   160         if log_dir != '' and not os.path.exists(log_dir):
   169         if log_dir != '' and not os.path.exists(log_dir):
   161             os.makedirs(log_dir)
   170             os.makedirs(log_dir)
   162         
   171         
   163         if (os.path.exists(log_conf_file)):
   172         if (os.path.exists(log_conf_file)):
   257         
   266         
   258     configs_in_project = sorted(project.list_configurations())
   267     configs_in_project = sorted(project.list_configurations())
   259     
   268     
   260     # Handle configurations specified with --configuration first
   269     # Handle configurations specified with --configuration first
   261     for config in configs:
   270     for config in configs:
   262         if config not in configs_in_project:
   271         if not project.get_storage().is_resource(utils.resourceref.norm(config)):
   263             raise ConfigurationNotFoundError("No such configuration: %s" % config)
   272             raise ConfigurationNotFoundError("No such configuration: %s" % config)
   264         if config not in config_list:
   273         if config not in config_list:
   265             config_list.append(config)
   274             config_list.append(config)
   266     
   275     
   267     # Then handle wildcards
   276     # Then handle wildcards