def __build_find_cmd(self): # create a find command expression audio_ext = ['mp3', 'ogg', 'wma'] video_ext = [ 'mpg', 'mpeg', 'avi', 'mov', 'm4v', 'mp4', 'wmv', 'flv', 'mkv' ] audio = "\( %s \)" % " -o ".join( ["-iname '*.%s'" % ext for ext in audio_ext]) video = "\( %s \)" % " -o ".join( ["-iname '*.%s'" % ext for ext in video_ext]) if self.first_find: log.info("audio extensions: %s" % color.bold(str(audio_ext))) log.info("video extensions: %s" % color.bold(str(video_ext))) video = "\( %s -and -size +5M -not -iwholename '*sample*' \)" % video findstring = "-type f -and \( %s -or %s \)" % (video, audio) find_cmd = "/usr/bin/find -L '%(where)s' %(find)s" % { 'where': "' '".join(self.dirs), 'find': findstring } if self.first_find: log.debug(color.gray(find_cmd)) self.first_find = False return find_cmd
def report(worklog, config): lines = [] total = timedelta(seconds=0) rollup = dict() lines.append('{} {}'.format( color.bold('Worklog Report for'), color.purple(worklog.when.strftime('%F'), bold=True))) if len(worklog) == 0: lines.append(' no entries') else: for task, next_task in worklog.pairwise(): if isinstance(task, GoHome): continue if isinstance(next_task, DummyRightNow): colorize_end_time = color.yellow else: colorize_end_time = color.green delta = next_task.start - task.start if task.include_in_rollup(): total += delta if task.description not in rollup: rollup[task.description] = delta else: rollup[task.description] += delta if delta > timedelta(): if not task.logged: task.logged = False lines.append(' {:5s} {} {:5s} {}{!s:>7}{} {} {} {}'.format( color.green(task.start.strftime('%H:%M')), color.black('-', intense=True), colorize_end_time(next_task.start.strftime('%H:%M')), color.black('(', intense=True), Duration(delta).colorized(), color.black(')', intense=True), { True: color.green('*'), False: color.red('*') }[task.logged], task.ticket, task.description)) lines.append('\n {!s:>7} {}'.format( Duration(total).colorized(underline=True), color.colorize('TOTAL', bold=True, underline=True))) for key in sorted(rollup.keys()): lines.append(' {!s:>7} {}'.format( Duration(rollup[key]).colorized(), color.bold(key))) print('\n'.join(lines))
def system_checking(install_mode=False, chorus_path=None, user=None): logger.info(bold(text.get("step_msg", "health_check"))) for func in _load_configure_func().values(): if func[0] == "b_check_running_user": func[1](install_mode=install_mode) elif func[0] == "c_check_java_version": func[1](install_mode=install_mode, user=user) elif func[0] == "d_check_disk_space": if install_mode: func[1](chorus_path) else: func[1]()
def health_check(args=''): executor = ChorusExecutor() if args == '' or args == None: args = "checkos" if "help" not in args: logger.info(bold("Running \"atk %s\" Command:" % args)) command = "source ~/.bashrc && %s %s" % (os.path.join(os.path.dirname(os.path.abspath(__file__)), "health_lib/atk"), args) ret, stdout, stderr = executor.run(command + " 2>&1") if "Warning" in stdout: logger.warning(stdout) logger.warning(warning("You have warning during health_check which might cause\n"\ + "problem when you use alpine chorus, we recommand you\n"\ + "resolve these problem before using alpine chorus.")) return ret, stdout, stderr
def health_check(args=''): executor = ChorusExecutor() if args == '' or args == None: args = "checkos" if "help" not in args: logger.info(bold("Running \"atk %s\" Command:" % args)) command = "source ~/.bashrc && %s %s" % (os.path.join( os.path.dirname(os.path.abspath(__file__)), "health_lib/atk"), args) ret, stdout, stderr = executor.run(command + " 2>&1") if "Warning" in stdout: logger.warning(stdout) logger.warning(warning("You have warning during health_check which might cause\n"\ + "problem when you use alpine chorus, we recommand you\n"\ + "resolve these problem before using alpine chorus.")) return ret, stdout, stderr
def setup(self, options, is_upgrade): self.set_path(options) # if not io.require_confirmation("Do you want to set up the chorus, " # + "please make sure you have installed chorus before setting up?"): # logger.fatal("Setup aborted, Cancelled by user") # quit() # if not self.options.disable_spec: # health_check() # self.prompt_for_eula() # pre step: passphrase = self.get_passphrase() logger.debug("Construct Chorus and Data Directory:") self.construct_shared_structure() self.construct_data_structure() self.link_shared_config() self.link_data_folder() self.generate_paths_file() self.configure_secret_key(passphrase) self.configure_secret_token() if is_upgrade: logger.info(bold(text.get("step_msg", "update_database"))) else: logger.info(bold(text.get("step_msg", "create_database"))) self.extract_postgres() if is_upgrade: self.validate_data_sources() self.stop_previous_release() self.upgrade_database() else: self.create_database_config() self.generate_chorus_psql_files() self.generate_chorus_rails_console_file() self.setup_database() # self.enqueue_solr_reindex() # self.clean_up_old_releases() self.link_current_to_release("current", self.release_path) if self.is_alpine_exits() and self.options.chorus_only is False: logger.info(bold(text.get("step_msg", "install_alpine"))) self.configure_alpine() self.link_current_to_release("alpine-current", self.alpine_release_path) self.source_chorus_path() print "*" * 60 print text.get("status_msg", "success_install") % ( self.options.chorus_path, self.options.data_path, self.chorus_version, self.alpine_version, ) print "*" * 60 # disable it, health check is not good # if self.io.require_confirmation(text.get("interview_question", "do_health_check"), default="no"): # health_check() if self.io.require_confirmation(text.get("interview_question", "do_configure"), default="no"): configure.config(self.options, is_upgrade) print bold(text.get("status_msg", "setup_complete")) if is_upgrade: print text.get("status_msg", "upgrade") print "*" * 60 print text.get("status_msg", "setup_post_step") % pwd.getpwuid(os.getuid()).pw_name print "*" * 60
def setup(self, options, is_upgrade): self.set_path(options) #if not io.require_confirmation("Do you want to set up the chorus, " # + "please make sure you have installed chorus before setting up?"): # logger.fatal("Setup aborted, Cancelled by user") # quit() #if not self.options.disable_spec: # health_check() #self.prompt_for_eula() #pre step: passphrase = self.get_passphrase() logger.debug("Construct Chorus and Data Directory:") self.construct_shared_structure() self.construct_data_structure() self.link_shared_config() self.link_data_folder() self.generate_paths_file() self.configure_secret_key(passphrase) self.configure_secret_token() if is_upgrade: logger.info(bold(text.get("step_msg", "update_database"))) else: logger.info(bold(text.get("step_msg", "create_database"))) self.extract_postgres() if is_upgrade: self.validate_data_sources() self.stop_previous_release() self.upgrade_database() self.clear_tmp_directory() else: self.create_database_config() self.generate_chorus_psql_files() self.setup_database() #self.enqueue_solr_reindex() self.generate_chorus_rails_console_file() #self.clean_up_old_releases() self.link_current_to_release("current", self.release_path) if self.is_alpine_exits() and self.options.chorus_only is False: logger.info(bold(text.get("step_msg", "install_alpine"))) self.configure_alpine() self.link_current_to_release("alpine-current", self.alpine_release_path) self.source_chorus_path() print "*" * 60 print text.get("status_msg", "success_install") % \ (self.options.chorus_path, self.options.data_path, self.chorus_version, self.alpine_version) print "*" * 60 #disable it, health check is not good #if self.io.require_confirmation(text.get("interview_question", "do_health_check"), default="no"): # health_check() if self.io.require_confirmation(text.get("interview_question", "do_configure"), default="no"): configure.config(self.options, is_upgrade) print bold(text.get("status_msg", "setup_complete")) if is_upgrade: print text.get("status_msg", "upgrade") print "*" * 60 print text.get("status_msg", "setup_post_step") % pwd.getpwuid( os.getuid()).pw_name print "*" * 60
import color print(color.blue("Blue like the sky")) print(color.blue("Nice blue text")+" and "+color.bold(' a lovely bold')+color.red("!"))