def status(): """ Drops {0} which is a json formatted file that contains a status message that will be displayed to all users on the on the courseware for a single course or for all courses if 'global' is set. Message(s) are entered or removed interactively on the console. Example usage: $ fab groups:prod_edx status """.format(status_file) with hide('running', 'stdout', 'stderr', 'warnings'): env_json = sudo("cat /opt/wwc/lms-xml.env.json") course_listings = json.loads(env_json)['COURSE_LISTINGS'] course_ids = [course_id for course_list in course_listings.itervalues() for course_id in course_list] course_ids = ['global'] + course_ids with no_ts(): course_status = None with settings(warn_only=True): cur_status = noopable(sudo)('cat {0}'.format(status_file)) try: course_status = json.loads(cur_status) # add empty entries for courses not in the list empty_entries = set(course_ids) - set(course_status.keys()) course_status.update({entry: '' for entry in list(empty_entries)}) except ValueError: fastprint(red("Not a valid json file, overwritting\n")) if course_status is None: course_status = {course: '' for course in course_ids} new_status = multi_choose_with_input( 'Set the status message, blank to disable:', course_status) if new_status is not None: # remove empty entries new_status = {entry: new_status[entry] for entry in new_status if len(new_status[entry]) > 1} with unsquelched(): if not console.confirm( 'Setting new status message:\n{0}'.format( blue(str(new_status), bold=True)), default=False): abort('Operation cancelled by user') with tempfile.NamedTemporaryFile(delete=True) as f: f.write(json.dumps(new_status)) f.flush() execute(update_status, f.name) else: abort('Operation cancelled by user')
def display_installed_packages(installed_packages): """ Print all installed packages collected by collect_installed_packages """ # FIXME: env.hosts loses the port information here, not sure why with no_ts(): for pkg in installed_packages['{0}:22'.format(env.host)]: notify("{pkg.name} = {pkg.revision}".format(pkg=pkg))
def display_installed_packages(installed_packages): """ Print all installed packages collected by collect_installed_packages """ # FIXME: env.hosts loses the port information here, not sure why with no_ts(): for pkg in installed_packages["{0}:22".format(env.host)]: notify("{pkg.name} = {pkg.revision}".format(pkg=pkg))
def status(): """ Drops {0} which is a json formatted file that contains a status message that will be displayed to all users on the on the courseware for a single course or for all courses if 'global' is set. Message(s) are entered or removed interactively on the console. Example usage: $ fab groups:prod_edx status """.format(status_file) with hide('running', 'stdout', 'stderr', 'warnings'): env_json = sudo("cat /opt/wwc/lms-xml.env.json") course_listings = json.loads(env_json)['COURSE_LISTINGS'] course_ids = [ course_id for course_list in course_listings.itervalues() for course_id in course_list ] course_ids = ['global'] + course_ids with no_ts(): course_status = None with settings(warn_only=True): cur_status = noopable(sudo)('cat {0}'.format(status_file)) try: course_status = json.loads(cur_status) # add empty entries for courses not in the list empty_entries = set(course_ids) - set(course_status.keys()) course_status.update({entry: '' for entry in list(empty_entries)}) except ValueError: fastprint(red("Not a valid json file, overwritting\n")) if course_status is None: course_status = {course: '' for course in course_ids} new_status = multi_choose_with_input( 'Set the status message, blank to disable:', course_status) if new_status is not None: # remove empty entries new_status = { entry: new_status[entry] for entry in new_status if len(new_status[entry]) > 1 } with unsquelched(): if not console.confirm( 'Setting new status message:\n{0}'.format( blue(str(new_status), bold=True)), default=False): abort('Operation cancelled by user') with tempfile.NamedTemporaryFile(delete=True) as f: f.write(json.dumps(new_status)) f.flush() execute(update_status, f.name) else: abort('Operation cancelled by user')