diff --git a/apprecommender/main/cli.py b/apprecommender/main/cli.py index d26a5fa..2324b73 100644 --- a/apprecommender/main/cli.py +++ b/apprecommender/main/cli.py @@ -49,29 +49,49 @@ def run_apprecommender(reference_pkgs): return PERMISSION_DENIED +def run_initialize(): + print "Initializing AppRecommender" + initialize = Initialize() + + try: + initialize.prepare_data() + except OSError: + return PERMISSION_DENIED + + return SUCCESS + + +def run_train(): + print "Training machine learning" + + try: + MachineLearning.train(MachineLearningBVA) + MachineLearning.train(MachineLearningBOW) + except IOError: + return PERMISSION_DENIED + except MachineLearningTrainError: + return ERROR_INIT_TRAIN + + return SUCCESS + + def run(args): - if args['init']: - print "Initializing AppRecommender" - initialize = Initialize() + if args['update']: + init_result = run_initialize() - try: - initialize.prepare_data() - except OSError: - return PERMISSION_DENIED + if init_result != SUCCESS: + return init_result - return SUCCESS - elif args['train']: - print "Training machine learning" + train_result = run_train() - try: - MachineLearning.train(MachineLearningBVA) - MachineLearning.train(MachineLearningBOW) - except IOError: - return PERMISSION_DENIED - except MachineLearningTrainError: - return ERROR_INIT_TRAIN + if train_result != SUCCESS: + return train_result return SUCCESS + elif args['init']: + return run_initialize() + elif args['train']: + return run_train() elif args['contribute']: collect_user_data.main() elif args['show_classifications']: diff --git a/apprecommender/main/options.py b/apprecommender/main/options.py index b907116..cd8d83a 100644 --- a/apprecommender/main/options.py +++ b/apprecommender/main/options.py @@ -71,4 +71,9 @@ def get_parser(): help='Disable recommendations when install a package with apt', action='store_true') + parser.add_argument( + '--update', + help='Run both init and train commands', + action='store_true') + return parser