diff --git a/letsencrypt/client/apache/parser.py b/letsencrypt/client/apache/parser.py index 792257b5a..efc692d97 100644 --- a/letsencrypt/client/apache/parser.py +++ b/letsencrypt/client/apache/parser.py @@ -240,27 +240,47 @@ class ApacheParser(object): regex = regex + letter return regex - def _parse_file(self, file_path): + def _parse_file(self, filepath): """Parse file with Augeas Checks to see if file_path is parsed by Augeas - If file_path isn't parsed, the file is added and Augeas is reloaded + If filepath isn't parsed, the file is added and Augeas is reloaded - :param str file_path: Apache config file path + :param str filepath: Apache config file path """ # Test if augeas included file for Httpd.lens # Note: This works for augeas globs, ie. *.conf inc_test = self.aug.match( - "/augeas/load/Httpd/incl [. ='%s']" % file_path) + "/augeas/load/Httpd/incl [. ='%s']" % filepath) if not inc_test: # Load up files - # self.httpd_incl.append(file_path) - # self.aug.add_transform("Httpd.lns", - # self.httpd_incl, None, self.httpd_excl) - self._add_httpd_transform(file_path) + # This doesn't seem to work on TravisCI + # self.aug.add_transform("Httpd.lns", [filepath]) + self._add_httpd_transform(filepath) self.aug.load() + def _add_httpd_transform(self, incl): + """Add a transform to Augeas. + + This function will correctly add a transform to augeas + The existing augeas.add_transform in python doesn't seem to work for + Travis CI as it loads in libaugeas.so.0.10.0 + + :param str incl: filepath to include for transform + + """ + last_include = self.aug.match("/augeas/load/Httpd/incl [last()]") + if last_include: + # Insert a new node immediately after the last incl + self.aug.insert(last_include[0], "incl", False) + self.aug.set("/augeas/load/Httpd/incl[last()]", incl) + # On first use... must load lens and add file to incl + else: + # Augeas uses base 1 indexing... insert at beginning... + self.aug.set("/augeas/load/Httpd/lens", "Httpd.lns") + self.aug.set("/augeas/load/Httpd/incl", incl) + def standardize_excl(self): """Standardize the excl arguments for the Httpd lens in Augeas. @@ -293,19 +313,6 @@ class ApacheParser(object): self.aug.load() - def _add_httpd_transform(self, incl): - """Add a transform to Augeas. - - This function will correctly add a transform to augeas - The existing augeas.add_transform in python is broken. - - :param str incl: TODO - - """ - last_include = self.aug.match("/augeas/load/Httpd/incl [last()]") - self.aug.insert(last_include[0], "incl", False) - self.aug.set("/augeas/load/Httpd/incl[last()]", incl) - def _set_locations(self, ssl_options): """Set default location for directives. diff --git a/letsencrypt/client/augeas_configurator.py b/letsencrypt/client/augeas_configurator.py index 1c366c60e..793b141d6 100644 --- a/letsencrypt/client/augeas_configurator.py +++ b/letsencrypt/client/augeas_configurator.py @@ -36,10 +36,11 @@ class AugeasConfigurator(object): "progress": CONFIG.IN_PROGRESS_DIR} self.direc = direc - # TODO: this instantiation can be optimized to only load - # relevant files - I believe -> NO_MODL_AUTOLOAD - # Set Augeas flags to save backup - self.aug = augeas.Augeas(flags=augeas.Augeas.NONE) + + # Set Augeas flags to not save backup (we do it ourselves) + # Set Augeas to not load anything by default + my_flags = augeas.Augeas.NONE | augeas.Augeas.NO_MODL_AUTOLOAD + self.aug = augeas.Augeas(flags=my_flags) self.save_notes = "" def check_parsing_errors(self, lens): @@ -187,7 +188,7 @@ class AugeasConfigurator(object): self.aug.load() - def show_config_changes(self): + def view_config_changes(self): """Displays all saved checkpoints. All checkpoints are printed to the console.