def execute(self, argv): Provider = get_current_provider() optlist, args = getopt.getopt(argv, '', ['file=', 'help']) optmap = {opt[0].lstrip('-'): opt[1] for opt in optlist} if 'help' in optmap: print("usage: bucket-list backup [options]", "\n options:", "\n --file absolute path of backup file", "\n --help prints help") print( "\nFor more details you can refer official documentation here:", "\nhttps://github.com/arpitbbhayani/bucket-list/wiki/backup") return if 'file' not in optmap: optmap['file'] = speedyio.askfor('file', empty_allowed=False) try: with open(optmap['file'], 'w') as f: f.write('') except Exception as e: raise BucketlistError(str(e)) provider_name = appconfig.get('provider', 'name') backup_data = { 'provider': provider_name, } data = {} categories = Provider.get_categories() speedyio.info("{} categories fetched".format(len(categories))) for category in categories: tasks_incomplete = Provider.get_items(category, completed=False) speedyio.info("{} incomplete items fetched for category {}".format( len(tasks_incomplete), category.name)) tasks_complete = Provider.get_items(category, completed=True) speedyio.info("{} completed items fetched for category {}".format( len(tasks_complete), category.name)) data[category.name] = [ t.__dict__ for t in tasks_incomplete + tasks_complete ] backup_data['data'] = data self.dump(backup_data, optmap['file']) speedyio.success("Backup successfully created at {}".format( optmap['file']))
def execute(self, argv): Provider = get_current_provider() optlist, args = getopt.getopt(argv, 'c:', ['count=', 'completed', 'help']) optmap = { opt[0].lstrip('-'): opt[1] for opt in optlist } if 'help' in optmap: print( "usage: bucket-list view [options]", "\n options:", "\n -c category from which you want to view items", "\n --count maximum number ites to be fetched from your bucket list", "\n --completed fetches completed items from your bucket list", "\n --help prints help" ) print( "\nFor more details you can refer official documentation here:", "\nhttps://github.com/arpitbbhayani/bucket-list/wiki/view" ) return if 'c' not in optmap: options = [speedyio.Item(x.name, x) for x in Provider.get_categories()] if not options: raise BucketlistError("You have not added any item in your bucket list.") bucketlist_category = speedyio.chooseone(options, message="Select a category") else: bucketlist_category = Provider.get_category(optmap['c']) if bucketlist_category is None: speedyio.error("Category {} does not exist!".format(optmap['c'])) return if 'completed' in optmap: bucketlist_items = Provider.get_items(bucketlist_category, completed=True) else: bucketlist_items = Provider.get_items(bucketlist_category, completed=False) count = optmap.get('count') if count is not None: count = convert_int(count) if count is None or count <= 0: speedyio.error("'count' should be a positive number.") return bucketlist_items = bucketlist_items[:count] for bucketlist_item in bucketlist_items: speedyio.bold_print(" - {}".format(bucketlist_item.message))
def execute(self, argv): Provider = get_current_provider() optlist, args = getopt.getopt(argv, 'c:', ['help']) optmap = {opt[0].lstrip('-'): opt[1] for opt in optlist} if 'help' in optmap: print("usage: bucket-list mark [options]", "\n options:", "\n -c category to which the item belongs", "\n --help prints help") print( "\nFor more details you can refer official documentation here:", "\nhttps://github.com/arpitbbhayani/bucket-list/wiki/mark") return if 'c' not in optmap: options = [ speedyio.Item(x.name, x) for x in Provider.get_categories() ] if not options: raise BucketlistError( "You have not added any item in your bucket list.") bucketlist_category = speedyio.chooseone( options, message="Select a category") else: bucketlist_category = Provider.get_category(optmap['c']) if bucketlist_category is None: speedyio.error("Category {} does not exist!".format( optmap['c'])) return bucketlist_items = Provider.get_items(bucketlist_category, completed=False) options = [ speedyio.Item(bucketlist_item.message, bucketlist_item) for bucketlist_item in bucketlist_items ] if not options: return bucketlist_item = speedyio.chooseone(options, message="Mark as complete") bucketlist_item = Provider.mark_as_complete(bucketlist_category, bucketlist_item) speedyio.success("Marked as completed \u2713")
def execute(self, argv): Provider = get_current_provider() optlist, args = getopt.getopt(argv, 'm:c:', ['help']) optmap = {opt[0].lstrip('-'): opt[1] for opt in optlist} if 'help' in optmap: print("usage: bucket-list add [options]", "\n options:", "\n -m message to be stored in your bucket list", "\n -c category to which the item should belong", "\n --help prints help") print( "\nFor more details you can refer official documentation here:", "\nhttps://github.com/arpitbbhayani/bucket-list/wiki/add") return if 'c' not in optmap: options = [ speedyio.Item(x.name, x) for x in Provider.get_categories() ] if not options: raise BucketlistError( "No categories found!" + "\nIf you want to add item to a new category use option -c" + "\n Example: bucket-list add -c animated-movies -m Bolt" ) bucketlist_category = speedyio.chooseone( options, message="Select a category") else: # Validating category name validate_cateogry_name(optmap['c']) bucketlist_category = Provider.get_category(optmap['c']) if bucketlist_category is None: bucketlist_category = Provider.create_category(optmap['c']) if 'm' not in optmap: optmap['m'] = speedyio.askfor('message', empty_allowed=False) bucketlist_item = Provider.add_item( bucketlist_category, BucketlistItem(None, optmap['m'], False)) speedyio.success("'{}' added successfully \u2713".format( bucketlist_item.message))
def execute(self, argv): Provider = get_current_provider() optlist, args = getopt.getopt(argv, '', ['help']) optmap = {opt[0].lstrip('-'): opt[1] for opt in optlist} if 'help' in optmap: print("usage: bucket-list clean [options]", "\n options:", "\n --help prints help") print( "\nFor more details you can refer official documentation here:", "\nhttps://github.com/arpitbbhayani/bucket-list/wiki/clean") return if speedyio.yesno('Do you really want to clean all data?', default=False): Provider.clean() speedyio.success("All data for provider cleaned.")
def execute(self, argv): Provider = get_current_provider() optlist, args = getopt.getopt(argv, '', ['help']) optmap = { opt[0].lstrip('-'): opt[1] for opt in optlist } if 'help' in optmap: print( "usage: bucket-list init [options]", "\n options:", "\n --help prints help" ) print( "\nFor more details you can refer official documentation here:", "\nhttps://github.com/arpitbbhayani/bucket-list/wiki/init" ) return old_config = appconfig.get_all('provider_config') appconfig.delete_section('provider_config') appconfig.create_section('provider_config') provider_name = appconfig.get_provider_name() provider_config = configio.get_provider_config(provider_name) if provider_config is None: speedyio.error("Unsupported provider '{}'".format(provider_name)) return for config_name in provider_config: default_value = old_config.get(config_name) value = speedyio.askfor(config_name, empty_allowed=False, default=default_value) appconfig.put('provider_config', config_name, value) Provider.init() speedyio.success("Provider {} initialized".format(provider_name))
def execute(self, argv): Provider = get_current_provider() optlist, args = getopt.getopt(argv, '', ['file=', 'help']) optmap = {opt[0].lstrip('-'): opt[1] for opt in optlist} if 'help' in optmap: print( "usage: bucket-list restore [options]", "\n options:", "\n --file absolute path of your backup file to be restored", "\n --help prints help") print( "\nFor more details you can refer official documentation here:", "\nhttps://github.com/arpitbbhayani/bucket-list/wiki/restore") return if 'file' not in optmap: optmap['file'] = speedyio.askfor('file', empty_allowed=False) provider_name = appconfig.get('provider', 'name') backedup_data = self.read(optmap['file']) try: Provider.clean() speedyio.info("Cleanup done") Provider.init() speedyio.info("Provider initialized") validate_backedup_data(backedup_data) for category_name, items in backedup_data.get('data').items(): speedyio.info( "Restoring data for category {}".format(category_name)) category = Provider.get_category(category_name) if category is None: category = Provider.create_category(category_name) for item in items: bucketlist_item = Provider.get_item(category, item['id']) if bucketlist_item is None: bucketlist_item = Provider.add_item( category, BucketlistItem(None, item['message'], False)) if bucketlist_item.is_completed is False and item[ 'is_completed'] is True: Provider.mark_as_complete(category, bucketlist_item) except BucketlistError as e: speedyio.error( "Data restored failed from {}.\nPlease try again.".format( optmap['file'])) speedyio.error(e.description) except Exception as e: logger.exception(e) speedyio.error( "Data restored failed from {}.\nPlease check logs ({}).". format(optmap['file'], appconfig.get('logging', 'file'))) else: speedyio.success("Data restored from {}".format(optmap['file']))