def DoStatResetTriggers(self): """Reset stat caches if a glob evaluates differently from earlier. More precisely, if a path of a glob comes in or out of existence or has a new stamp, then reset stat caches.""" trigger_map = self.stat_reset_triggers old_paths = [ path for glob_expr in trigger_map for path in trigger_map[glob_expr] ] for glob_expr in trigger_map: for path in glob.glob(glob_expr): try: old_paths.remove(path) except ValueError: pass new_stamp = basics.Stamp(path) if path in trigger_map[glob_expr]: if new_stamp != trigger_map[glob_expr][path]: Debug(basics.DEBUG_WARNING, "Path '%s' changed. Clearing caches.", path) trigger_map[glob_expr][path] = new_stamp self.ClearStatCaches() return else: Debug(basics.DEBUG_WARNING, "Path '%s' came into existence. Clearing caches.", path) trigger_map[glob_expr][path] = basics.Stamp(path) self.ClearStatCaches() return if old_paths: path = old_paths[0] Debug(basics.DEBUG_WARNING, "Path '%s' no longer exists. Clearing caches.", path) self.ClearStatCaches()
def _ParseCommandLineOptions(): """Parse arguments and options for the include server command. Returns: (include_server_port, pid_file), where include_server_port is a string and pid_file is a string or None Modifies: option variables in module basics """ try: opts, args = getopt.getopt(sys.argv[1:], "d:estvwx", [ "port=", "pid_file=", "debug_pattern=", "email", "no-email", "email_bound=", "exact_analysis", "path_observation_re=", "stat_reset_triggers=", "simple_algorithm", "statistics", "time", "unsafe_absolute_includes", "no_force_dirs", "verify", "write_include_closure" ]) except getopt.GetoptError: # Print help information and exit. Usage() sys.exit(1) pid_file = None include_server_port = None for opt, arg in opts: try: if opt in ("-d", "--debug_pattern"): basics.opt_debug_pattern = int(arg) if opt in ("--port", ): include_server_port = arg if opt in ("--pid_file", ): pid_file = arg if opt in ("-e", "--email"): basics.opt_send_email = True if opt in ("--no-email", ): basics.opt_send_email = False if opt in ("--email_bound", ): basics.opt_email_bound = int(arg) if opt in ("--path_observation_re", ): basics.opt_path_observation_re = re.compile(arg) if opt in ("--stat_reset_triggers", ): basics.opt_stat_reset_triggers = (dict([ (glob_expr, dict([(path, basics.Stamp(path)) for path in glob.glob(glob_expr)])) for glob_expr in arg.split(':') ])) if opt in ("--simple_algorithm", ): basics.opt_simple_algorithm = True sys.exit("Not implemented") if opt in ("--unsafe_absolute_includes", ): basics.opt_unsafe_absolute_includes = True if opt in ("--no_force_dirs", ): basics.opt_no_force_dirs = True if opt in ("-s", "--statistics"): basics.opt_statistics = True if opt in ("-t", "--time"): basics.opt_print_times = True if opt in ("-v", "--verify"): basics.opt_verify = True if opt in ("-w", "--write_include_closure"): basics.opt_write_include_closure = True if opt in ("-x", "--exact_analysis"): basics.opt_exact_include_analysis = True except ValueError: Usage() sys.exit(1) # We must have a port! if not include_server_port: print("INCLUDE_SERVER_PORT not provided. Aborting.", file=sys.stderr) print("-------------------------------------------", "\n", file=sys.stderr) Usage() sys.exit(1) return (include_server_port, pid_file)