| 1037 | |
| 1038 | |
| 1039 | class Builder: |
| 1040 | def __init__(self, pad, destination_path, buildstate_path=None, extra_flags=None): |
| 1041 | self.extra_flags = process_extra_flags(extra_flags) |
| 1042 | self.pad = pad |
| 1043 | self.destination_path = os.path.abspath( |
| 1044 | os.path.join(pad.db.env.root_path, destination_path) |
| 1045 | ) |
| 1046 | if buildstate_path: |
| 1047 | self.meta_path = buildstate_path |
| 1048 | else: |
| 1049 | self.meta_path = os.path.join(self.destination_path, ".lektor") |
| 1050 | self.failure_controller = FailureController(pad, self.destination_path) |
| 1051 | |
| 1052 | try: |
| 1053 | os.makedirs(self.meta_path) |
| 1054 | if os.listdir(self.destination_path) != [".lektor"]: |
| 1055 | if not click.confirm( |
| 1056 | click.style( |
| 1057 | "The build dir %s hasn't been used before, and other " |
| 1058 | "files or folders already exist there. If you prune " |
| 1059 | "(which normally follows the build step), " |
| 1060 | "they will be deleted. Proceed with building?" |
| 1061 | % self.destination_path, |
| 1062 | fg="yellow", |
| 1063 | ) |
| 1064 | ): |
| 1065 | os.rmdir(self.meta_path) |
| 1066 | raise click.Abort() |
| 1067 | except OSError: |
| 1068 | pass |
| 1069 | |
| 1070 | con = self.connect_to_database() |
| 1071 | try: |
| 1072 | create_tables(con) |
| 1073 | finally: |
| 1074 | con.close() |
| 1075 | |
| 1076 | @property |
| 1077 | def env(self): |
| 1078 | """The environment backing this generator.""" |
| 1079 | return self.pad.db.env |
| 1080 | |
| 1081 | @property |
| 1082 | def buildstate_database_filename(self): |
| 1083 | """The filename for the build state database.""" |
| 1084 | return os.path.join(self.meta_path, "buildstate") |
| 1085 | |
| 1086 | def connect_to_database(self): |
| 1087 | con = sqlite3.connect( |
| 1088 | self.buildstate_database_filename, |
| 1089 | isolation_level=None, |
| 1090 | timeout=10, |
| 1091 | check_same_thread=False, |
| 1092 | ) |
| 1093 | cur = con.cursor() |
| 1094 | cur.execute("pragma journal_mode=WAL") |
| 1095 | cur.execute("pragma synchronous=NORMAL") |
| 1096 | con.commit() |
no outgoing calls