| 45 | |
| 46 | |
| 47 | class Pelican: |
| 48 | def __init__(self, settings): |
| 49 | """Pelican initialization |
| 50 | |
| 51 | Performs some checks on the environment before doing anything else. |
| 52 | """ |
| 53 | |
| 54 | # define the default settings |
| 55 | self.settings = settings |
| 56 | |
| 57 | self.path = settings["PATH"] |
| 58 | self.theme = settings["THEME"] |
| 59 | self.output_path = settings["OUTPUT_PATH"] |
| 60 | self.ignore_files = settings["IGNORE_FILES"] |
| 61 | self.delete_outputdir = settings["DELETE_OUTPUT_DIRECTORY"] |
| 62 | self.output_retention = settings["OUTPUT_RETENTION"] |
| 63 | |
| 64 | self.init_path() |
| 65 | self.init_plugins() |
| 66 | signals.initialized.send(self) |
| 67 | |
| 68 | def init_path(self): |
| 69 | if not any(p in sys.path for p in ["", os.curdir]): |
| 70 | logger.debug("Adding current directory to system path") |
| 71 | sys.path.insert(0, "") |
| 72 | |
| 73 | def init_plugins(self): |
| 74 | self.plugins = [] |
| 75 | for plugin in load_plugins(self.settings): |
| 76 | name = get_plugin_name(plugin) |
| 77 | logger.debug("Registering plugin `%s`", name) |
| 78 | try: |
| 79 | plugin.register() |
| 80 | self.plugins.append(plugin) |
| 81 | except Exception: |
| 82 | logger.exception( |
| 83 | "Cannot register plugin `%s`", |
| 84 | name, |
| 85 | stacklevel=2, |
| 86 | ) |
| 87 | if self.settings.get("DEBUG", False): |
| 88 | console.print_exception() |
| 89 | |
| 90 | self.settings["PLUGINS"] = [get_plugin_name(p) for p in self.plugins] |
| 91 | |
| 92 | def run(self): |
| 93 | """Run the generators and return""" |
| 94 | start_time = time.time() |
| 95 | |
| 96 | context = self.settings.copy() |
| 97 | # Share these among all the generators and content objects |
| 98 | # They map source paths to Content objects or None |
| 99 | context["generated_content"] = {} |
| 100 | context["static_links"] = set() |
| 101 | context["static_content"] = {} |
| 102 | context["localsiteurl"] = self.settings["SITEURL"] |
| 103 | |
| 104 | generators = [ |
no outgoing calls
searching dependent graphs…