params = sys.argv[1:] usage = """Usage: report_data_manager.py <report_id> <command> <params> <command>: create_table generate_data [<initial measurement date>] rename_table <old table name> test_table_name <table name> drop_table """ data_manager.command = 'unknown' if params: if params[0] == '-h' or params[0] == '--h' or params[0] == '-help' or params[0] == '--help': print usage sys.exit() elif is_int(params[0]) and int(params[0]) > 0: data_manager.element_id = int(params[0]) del(params[0]) if params: if params[0] == 'create_table': data_manager.command = 'create_table' elif params[0] == 'generate_data': data_manager.command = 'generate_data' del(params[0]) if params: data_manager.initial_measurement_time = params[0] elif params[0] == 'rename_table' and len(params) >= 2: data_manager.command = 'rename_table' data_manager.report_name = params[1] elif params[0] == 'test_table_name' and len(params) >= 2: data_manager.command = 'test_table_name'
Examples: 1) Duplicate element 2 to element 500 without pivots, charts and drill-to-detail: sudo report_duplicate.py 2 500 2) Duplicate element 2 to element 500 with pivots and drill-to-detail: sudo report_duplicate.py 2 500 -p -d 2) Duplicate element 2 to element 500 with all data (pivots, charts, drill-to-detail) sudo report_duplicate.py 2 500 -p -c -d """ if params: _logger.info('Duplicator run: %s' % ' '.join(sys.argv)) if params[0] == '-h' or params[0] == '--h' or params[0] == '-help' or params[0] == '--help': print usage sys.exit() if is_int(params[0]) and is_int(params[1]): orig_element_id = int(params[0]) new_element_id = int(params[1]) # try: # from metric.report_validator import ReportValidator # from db.db_conn import DBManager # except Exception, e: # if str(e).find('Check file path and permissions'): # print "This module has to be run under the root permissions." # sys.exit() # else: # raise try: db = DBManager().get_query()
Available only if <metric_id> is set. <interval_id> : process charting interval if <metric_id> and <segment_value_id> are set. All metric intervals are processed if <segment_value_id> is not set. -delete_all : delete all metric files. -delete_segment : delete metric segment files. Available only if <segment_id> is set. -delete_interval : delete metric interval files. Available only if <interval_id> is set. -index : process only index charting interval. -h : show this message. """ element_id = None updater = Updater() if params: if params[0] == '-h' or params[0] == '--h' or params[0] == '-help' or params[0] == '--help': print usage sys.exit() if is_int(params[0]) and int(params[0]) > 0: # get <metric_id> updater.element_id = int(params[0]) del(params[0]) if params: if params[0] == '-delete_all': # get <metric_id> -delete_all updater.command = 'delete_all' elif len(params) >= 2 and params[0] == '-delete_interval' and is_int(params[1]) and int(params[1]) > 0: # get <metric_id> -delete_interval <interval_id> updater.command = 'delete_interval' updater.charting_interval_id = int(params[1]) elif params[0] == '-index': # get <metric_id> -index updater.index_interval_only = True elif is_int(params[0]):
List of ids is comma-separated, interval are available, for example: 1,2,3-5,8 Available only if <report_id> and <segment_value_id> are set. -c : populate existing data to composite report table. Report files will not be regenerated. -h,--h,-help,--help : show this message. """ updater = Updater() # import hotshot # prof = hotshot.Profile("your_project.prof") # prof.start() if params: if params[0] == '-h' or params[0] == '--h' or params[0] == '-help' or params[0] == '--help': print usage sys.exit() if is_int(params[0]) and int(params[0]) > 0: # get <report_id> updater.element_id = int(params[0]) del(params[0]) if params: if params[0] == '-delete_all': # get <report_id> -delete_all updater.command = 'delete_all' elif len(params) >= 2 and params[0] == '-delete_pivot' and is_int(params[1]) and int(params[1]) > 0: # get <report_id> -delete_pivot <pivot_id> updater.command = 'delete_pivot' updater.pivot_id = params[1] elif len(params) >= 2 and params[0] == '-delete_chart' and is_int(params[1]) and int(params[1]) > 0: # get <report_id> -delete_chart <chart_id> updater.command = 'delete_chart' updater.chart_id = params[1]
<report_id> : process dashboard report element with specified id. -h,--h,-help,--help : show this message. """ has_error = False validator_command = None element_id = None extra_id = None if params: if params[0] == '-h' or params[0] == '--h' or params[0] == '-help' or params[0] == '--help': print usage sys.exit() validator_command = params[0] del(params[0]) if params: if is_int(params[0]) and int(params[0]) > 0: element_id = int(params[0]) del(params[0]) if params and is_int(params[0]) and int(params[0]) > 0: extra_id = int(params[0]) else: has_error = True else: has_error = True else: has_error = True if has_error: print simplejson.dumps({'status':'ERROR', 'message':'incorrect arguments', 'fetched_rows':''}) exit()