Commit c3f66128 authored by Marco Mariani's avatar Marco Mariani

further comments

parent 8eadcdc0
...@@ -50,7 +50,7 @@ class Recipe(GenericBaseRecipe): ...@@ -50,7 +50,7 @@ class Recipe(GenericBaseRecipe):
""" """
def fetch_ipv6_host(self, options): def fetch_ipv6_host(self, options):
""" """\
Returns a string represtation of ipv6_host. Returns a string represtation of ipv6_host.
May receive a regular string, a set or a string serialized by buildout. May receive a regular string, a set or a string serialized by buildout.
""" """
...@@ -70,6 +70,8 @@ class Recipe(GenericBaseRecipe): ...@@ -70,6 +70,8 @@ class Recipe(GenericBaseRecipe):
def install(self): def install(self):
pgdata = self.options['pgdata-directory'] pgdata = self.options['pgdata-directory']
# if the pgdata already exists, skip all steps, we don't need to do anything.
if not os.path.exists(pgdata): if not os.path.exists(pgdata):
self.createCluster() self.createCluster()
self.createConfig() self.createConfig()
...@@ -77,10 +79,12 @@ class Recipe(GenericBaseRecipe): ...@@ -77,10 +79,12 @@ class Recipe(GenericBaseRecipe):
self.createSuperuser() self.createSuperuser()
self.createRunScript() self.createRunScript()
return [ # install() methods usually return the pathnames of managed files.
# XXX should we really return something here? # If they are missing, they will be rebuilt.
# os.path.join(pgdata, 'postgresql.conf') # In this case, we already check for the existence of pgdata,
] # so we don't need to return anything here.
return []
def check_exists(self, path): def check_exists(self, path):
...@@ -89,6 +93,13 @@ class Recipe(GenericBaseRecipe): ...@@ -89,6 +93,13 @@ class Recipe(GenericBaseRecipe):
def createCluster(self): def createCluster(self):
"""\
A Postgres cluster is "a collection of databases that is managed
by a single instance of a running database server".
Here we create an empty cluster. The authentication for this
command is through the unix socket.
"""
initdb_binary = os.path.join(self.options['bin'], 'initdb') initdb_binary = os.path.join(self.options['bin'], 'initdb')
self.check_exists(initdb_binary) self.check_exists(initdb_binary)
...@@ -150,7 +161,7 @@ class Recipe(GenericBaseRecipe): ...@@ -150,7 +161,7 @@ class Recipe(GenericBaseRecipe):
def createSuperuser(self): def createSuperuser(self):
""" """\
Creates a Postgres superuser - other than "slapuser#" for use by the application. Creates a Postgres superuser - other than "slapuser#" for use by the application.
""" """
...@@ -166,7 +177,7 @@ class Recipe(GenericBaseRecipe): ...@@ -166,7 +177,7 @@ class Recipe(GenericBaseRecipe):
def runPostgresCommand(self, cmd): def runPostgresCommand(self, cmd):
""" """\
Executes a command in single-user mode, with no daemon running. Executes a command in single-user mode, with no daemon running.
Multiple commands can be executed by providing newlines, Multiple commands can be executed by providing newlines,
...@@ -190,7 +201,7 @@ class Recipe(GenericBaseRecipe): ...@@ -190,7 +201,7 @@ class Recipe(GenericBaseRecipe):
def createRunScript(self): def createRunScript(self):
""" """\
Creates a script that runs postgres in the foreground. Creates a script that runs postgres in the foreground.
'exec' is used to allow easy control by supervisor. 'exec' is used to allow easy control by supervisor.
""" """
...@@ -207,14 +218,13 @@ class Recipe(GenericBaseRecipe): ...@@ -207,14 +218,13 @@ class Recipe(GenericBaseRecipe):
class ExportRecipe(GenericBaseRecipe): class ExportRecipe(GenericBaseRecipe):
def install(self): def install(self):
pgdata = self.options['pgdata-directory']
wrapper = self.options['wrapper'] wrapper = self.options['wrapper']
self.createBackupScript(wrapper) self.createBackupScript(wrapper)
return [wrapper] return [wrapper]
def createBackupScript(self, wrapper): def createBackupScript(self, wrapper):
""" """\
Create a script to backup the database in 'custom' format. Create a script to backup the database in 'custom' format.
""" """
content = textwrap.dedent("""\ content = textwrap.dedent("""\
...@@ -233,14 +243,13 @@ class ExportRecipe(GenericBaseRecipe): ...@@ -233,14 +243,13 @@ class ExportRecipe(GenericBaseRecipe):
class ImportRecipe(GenericBaseRecipe): class ImportRecipe(GenericBaseRecipe):
def install(self): def install(self):
pgdata = self.options['pgdata-directory']
wrapper = self.options['wrapper'] wrapper = self.options['wrapper']
self.createRestoreScript(wrapper) self.createRestoreScript(wrapper)
return [wrapper] return [wrapper]
def createRestoreScript(self, wrapper): def createRestoreScript(self, wrapper):
""" """\
Create a script to restore the database from 'custom' format. Create a script to restore the database from 'custom' format.
""" """
content = textwrap.dedent("""\ content = textwrap.dedent("""\
...@@ -256,5 +265,3 @@ class ImportRecipe(GenericBaseRecipe): ...@@ -256,5 +265,3 @@ class ImportRecipe(GenericBaseRecipe):
self.createExecutable(wrapper, content=content) self.createExecutable(wrapper, content=content)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment