First release 0.1.0
authorThierry Florac <thierry.florac@onf.fr>
Tue, 06 Jun 2017 15:09:45 +0200
changeset 0 10812b2ba33a
child 1 a05d4ccf5441
First release
.hgignore
cookiecutter.json
hooks/post_gen_project.py
{{cookiecutter.project_slug}}/bootstrap.py
{{cookiecutter.project_slug}}/buildout.cfg
{{cookiecutter.project_slug}}/etc/cron.d/README.txt
{{cookiecutter.project_slug}}/etc/init.d/README.txt
{{cookiecutter.project_slug}}/etc/logrotate.d/README.txt
{{cookiecutter.project_slug}}/etc/systemd/README.txt
{{cookiecutter.project_slug}}/etc/systemd/zeo-{{cookiecutter.project_slug}}.service
{{cookiecutter.project_slug}}/var/db/README.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Tue Jun 06 15:09:45 2017 +0200
@@ -0,0 +1,19 @@
+
+syntax: regexp
+^develop-eggs$
+syntax: regexp
+^parts$
+syntax: regexp
+^bin$
+syntax: regexp
+^\.installed\.cfg$
+syntax: regexp
+^\.settings$
+syntax: regexp
+^build$
+syntax: regexp
+^dist$
+syntax: regexp
+^\.idea$
+syntax: regexp
+.*\.pyc$
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cookiecutter.json	Tue Jun 06 15:09:45 2017 +0200
@@ -0,0 +1,16 @@
+{
+  "pyams_release": "0.1.4",
+  "project_name": "ZEO_server",
+  "project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}",
+  "eggs_directory": "eggs",
+  "run_user": "zeoadm",
+  "run_group": "zeo",
+  "zeo_server_port": 8100,
+  "zeo_monitor_port": 8101,
+  "zeo_storage": "{{ cookiecutter.project_slug }}",
+  "use_zeo_auth": true,
+  "zeo_auth_user": "zeouser",
+  "zeo_auth_password": "",
+  "zeo_pack_report": "root@localhost",
+  "logs_directory": "/var/log/zeo/{{ cookiecutter.project_slug }}"
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hooks/post_gen_project.py	Tue Jun 06 15:09:45 2017 +0200
@@ -0,0 +1,103 @@
+#!/usr/bin/env python3.5
+# -*- coding: utf-8 -*-
+
+import os
+
+from grp import getgrnam
+from pwd import getpwnam
+
+
+#
+# Replace "$((INSTALL))" by install directory for all files
+#
+
+TARGET = os.getcwd()
+
+for root, dirs, files in os.walk(TARGET):
+    for filename in files:
+        # read file content
+        with open(os.path.join(root, filename)) as f:
+            content = f.read()
+        # replace tag by install path
+        content = content.replace('$((INSTALL))', TARGET)
+        # replace file content
+        with open(os.path.join(root, filename), 'w') as f:
+            f.write(content)
+
+
+#
+# Check for logs directory
+#
+
+user = '{{ cookiecutter.run_user }}'
+user_id = getpwnam(user).pw_uid
+
+group = '{{ cookiecutter.run_group }}'
+group_id = getgrnam(group).gr_gid
+
+
+LOGS_DIRECTORY = '{{ cookiecutter.logs_directory }}'
+
+if not os.path.exists(LOGS_DIRECTORY):
+    try:
+        os.makedirs(LOGS_DIRECTORY, mode=0o775, exist_ok=True)
+    except PermissionError:
+        print("WARNING: Can't create logs directory {0}".format(LOGS_DIRECTORY))
+    else:
+        os.chown(LOGS_DIRECTORY, user_id, group_id)
+
+
+#
+# Check for var directory
+#
+
+VAR_DIRECTORY = os.path.join(TARGET, 'var')
+
+os.chown(VAR_DIRECTORY, user_id, group_id)
+for root, dirs, files in os.walk(VAR_DIRECTORY):
+    for dirname in dirs:
+        try:
+            target = os.path.join(VAR_DIRECTORY, root, dirname)
+            os.chown(target, user_id, group_id)
+        except PermissionError:
+            print("WARNING: Can't set permissions for directory {0}".format(target))
+    for filename in files:
+        try:
+            target = os.path.join(VAR_DIRECTORY, root, filename)
+            os.chown(target, user_id, group_id)
+        except PermissionError:
+            print("WARNING: Can't set permissions for file {0}".format(target))
+
+
+#
+# Make binary scripts executable
+#
+
+BIN_DIRECTORY = os.path.join(TARGET, 'bin')
+
+for root, dirs, files in os.walk(VAR_DIRECTORY):
+    for filename in files:
+        try:
+            target = os.path.join(BIN_DIRECTORY, root, filename)
+            os.chmod(target, 0o775)
+        except PermissionError:
+            print("WARNING: Can't set permissions for file {0}".format(target))
+
+
+print("\nYour ZEO environment is initialized.")
+print("To finalize it's creation, just type:")
+print("- cd {{ cookiecutter.project_slug }}")
+print("- python3.5 bootstrap.py")
+print("- ./bin/buildout")
+
+{%- if cookiecutter.use_zeo_auth %}
+#
+# Initialize ZEO authentication file
+#
+
+cmd = os.path.join(TARGET, 'bin', 'zeopasswd')
+target = os.path.join(TARGET, 'etc', 'auth.db')
+print("\nTo initialize authentication database, please run following command after buildout:")
+print('{cmd} -f {target} -p digest -r "{{ cookiecutter.project_name }}" {{ cookiecutter.zeo_auth_user }} '
+      '{{ cookiecutter.zeo_auth_password }}'.format(cmd=cmd, target=target))
+{%- endif %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/{{cookiecutter.project_slug}}/bootstrap.py	Tue Jun 06 15:09:45 2017 +0200
@@ -0,0 +1,178 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+"""
+
+import os
+import shutil
+import sys
+import tempfile
+
+from optparse import OptionParser
+
+tmpeggs = tempfile.mkdtemp()
+
+usage = '''\
+[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
+
+Bootstraps a buildout-based project.
+
+Simply run this script in a directory containing a buildout.cfg, using the
+Python that you want bin/buildout to use.
+
+Note that by using --find-links to point to local resources, you can keep 
+this script from going over the network.
+'''
+
+parser = OptionParser(usage=usage)
+parser.add_option("-v", "--version", help="use a specific zc.buildout version")
+
+parser.add_option("-t", "--accept-buildout-test-releases",
+                  dest='accept_buildout_test_releases',
+                  action="store_true", default=False,
+                  help=("Normally, if you do not specify a --version, the "
+                        "bootstrap script and buildout gets the newest "
+                        "*final* versions of zc.buildout and its recipes and "
+                        "extensions for you.  If you use this flag, "
+                        "bootstrap and buildout will get the newest releases "
+                        "even if they are alphas or betas."))
+parser.add_option("-c", "--config-file",
+                  help=("Specify the path to the buildout configuration "
+                        "file to be used."))
+parser.add_option("-f", "--find-links",
+                  help=("Specify a URL to search for buildout releases"))
+parser.add_option("--allow-site-packages",
+                  action="store_true", default=False,
+                  help=("Let bootstrap.py use existing site packages"))
+
+
+options, args = parser.parse_args()
+
+######################################################################
+# load/install setuptools
+
+try:
+    if options.allow_site_packages:
+        import setuptools
+        import pkg_resources
+    from urllib.request import urlopen
+except ImportError:
+    from urllib2 import urlopen
+
+ez = {}
+exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez)
+
+if not options.allow_site_packages:
+    # ez_setup imports site, which adds site packages
+    # this will remove them from the path to ensure that incompatible versions 
+    # of setuptools are not in the path
+    import site
+    # inside a virtualenv, there is no 'getsitepackages'. 
+    # We can't remove these reliably
+    if hasattr(site, 'getsitepackages'):
+        for sitepackage_path in site.getsitepackages():
+            sys.path[:] = [x for x in sys.path if sitepackage_path not in x]
+
+setup_args = dict(to_dir=tmpeggs, download_delay=0)
+ez['use_setuptools'](**setup_args)
+import setuptools
+import pkg_resources
+
+# This does not (always?) update the default working set.  We will
+# do it.
+for path in sys.path:
+    if path not in pkg_resources.working_set.entries:
+        pkg_resources.working_set.add_entry(path)
+
+######################################################################
+# Install buildout
+
+ws = pkg_resources.working_set
+
+cmd = [sys.executable, '-c',
+       'from setuptools.command.easy_install import main; main()',
+       '-mZqNxd', tmpeggs]
+
+find_links = os.environ.get(
+    'bootstrap-testing-find-links',
+    options.find_links or
+    ('http://downloads.buildout.org/'
+     if options.accept_buildout_test_releases else None)
+    )
+if find_links:
+    cmd.extend(['-f', find_links])
+
+setuptools_path = ws.find(
+    pkg_resources.Requirement.parse('setuptools')).location
+
+requirement = 'zc.buildout'
+version = options.version
+if version is None and not options.accept_buildout_test_releases:
+    # Figure out the most recent final version of zc.buildout.
+    import setuptools.package_index
+    _final_parts = '*final-', '*final'
+
+    def _final_version(parsed_version):
+        for part in parsed_version:
+            if (part[:1] == '*') and (part not in _final_parts):
+                return False
+        return True
+    index = setuptools.package_index.PackageIndex(
+        search_path=[setuptools_path])
+    if find_links:
+        index.add_find_links((find_links,))
+    req = pkg_resources.Requirement.parse(requirement)
+    if index.obtain(req) is not None:
+        best = []
+        bestv = None
+        for dist in index[req.project_name]:
+            distv = dist.parsed_version
+            if _final_version(distv):
+                if bestv is None or distv > bestv:
+                    best = [dist]
+                    bestv = distv
+                elif distv == bestv:
+                    best.append(dist)
+        if best:
+            best.sort()
+            version = best[-1].version
+if version:
+    requirement = '=='.join((requirement, version))
+cmd.append(requirement)
+
+import subprocess
+if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0:
+    raise Exception(
+        "Failed to execute command:\n%s" % repr(cmd)[1:-1])
+
+######################################################################
+# Import and run buildout
+
+ws.add_entry(tmpeggs)
+ws.require(requirement)
+import zc.buildout.buildout
+
+if not [a for a in args if '=' not in a]:
+    args.append('bootstrap')
+
+# if -c was provided, we push it back into args for buildout' main function
+if options.config_file is not None:
+    args[0:0] = ['-c', options.config_file]
+
+zc.buildout.buildout.main(args)
+shutil.rmtree(tmpeggs)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/{{cookiecutter.project_slug}}/buildout.cfg	Tue Jun 06 15:09:45 2017 +0200
@@ -0,0 +1,73 @@
+[buildout]
+extends = http://download.ztfy.org/pyams/pyams-{{ cookiecutter.pyams_release }}.cfg
+find-links = http://download.ztfy.org/eggs/
+
+socket-timeout = 3
+show-picked-versions = true
+newest = false
+
+allow-hosts =
+    *.python.org
+    *.sourceforge.net
+    github.com
+    bitbucket.org
+    download.ztfy.org
+
+versions = versions
+eggs-directory = {{ cookiecutter.eggs_directory }}
+
+parts =
+    zodb
+    zdaemon
+    {{ cookiecutter.project_slug }}
+
+[zodb]
+recipe = zc.recipe.egg:script
+eggs = ZEO
+
+[zdaemon]
+recipe = zc.recipe.egg:script
+eggs = zdaemon
+
+[{{ cookiecutter.project_slug }}]
+name = {{ cookiecutter.project_slug }}
+recipe = zc.zodbrecipes:server
+zeo.conf =
+  <zeo>
+    address {{ cookiecutter.zeo_server_port }}
+{%- if cookiecutter.zeo_monitor_port != 0 %}
+    monitor-address 8101
+{%- endif %}
+    read-only false
+    invalidation-queue-size 100
+    transaction-timeout 300
+    authentication-protocol digest
+    authentication-database $((INSTALL))/etc/auth.db
+    authentication-realm {{ cookiecutter.project_name }}
+  </zeo>
+  <blobstorage {{ cookiecutter.project_slug }}>
+    blob-dir $((INSTALL))/var/db/blobs
+    <filestorage {{ cookiecutter.project_slug }}>
+      path $((INSTALL))/var/db/Data.fs
+    </filestorage>
+  </blobstorage>
+  <eventlog>
+    level info
+    <logfile>
+      path {{ cookiecutter.logs_directory }}/{{ cookiecutter.project_slug }}-zeo.log
+    </logfile>
+  </eventlog>
+deployment = zeo
+pack = 10 4 * * * 0 {{ cookiecutter.zeo_pack_report }}
+shell-script = true
+
+[zeo]
+etc-directory = $((INSTALL))/etc
+crontab-directory = $((INSTALL))/etc/cron.d
+log-directory = {{ cookiecutter.logs_directory }}
+logrotate-directory = $((INSTALL))/etc/logrotate.d
+rc-directory = $((INSTALL))/etc/init.d
+run-directory = $((INSTALL))/var
+user = {{ cookiecutter.run_user }}
+
+[versions]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/{{cookiecutter.project_slug}}/etc/cron.d/README.txt	Tue Jun 06 15:09:45 2017 +0200
@@ -0,0 +1,5 @@
+This directory contains ZEO service packing script.
+
+To include this cron command (on Debian), just:
+- cd /etc/cron.d
+- ln -s $((INSTALL))/etc/cron.d/pack-zeo-{{ cookiecutter.project_slug }}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/{{cookiecutter.project_slug}}/etc/init.d/README.txt	Tue Jun 06 15:09:45 2017 +0200
@@ -0,0 +1,6 @@
+This directory contains "classic" initialization script for ZEO.
+
+To setup service (on Debian), just:
+- cd /etc/init.d
+- ln -s $((INSTALL))/etc/init.d/zeo-{{ cookiecutter.project_slug }}
+- update-rc.d defaults  zeo-{{ cookiecutter.project_slug }} defaults
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/{{cookiecutter.project_slug}}/etc/logrotate.d/README.txt	Tue Jun 06 15:09:45 2017 +0200
@@ -0,0 +1,5 @@
+This directory contains logrotate configuration file for ZEO.
+
+To setup configuration, just:
+- cd /etc/logrotate.d
+- ln -s $((INSTALL))/etc/logrotate.d/zeo-{{ cookiecutter.project_slug }}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/{{cookiecutter.project_slug}}/etc/systemd/README.txt	Tue Jun 06 15:09:45 2017 +0200
@@ -0,0 +1,5 @@
+This directory contains SystemD configuration file for ZEO service.
+
+To init ZEO service, just:
+- cd /etc/systemd/system
+- ln -s $((INSTALL}}/etc/systemd/zeo-{{ cookiecutter.project_slug }}.service
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/{{cookiecutter.project_slug}}/etc/systemd/zeo-{{cookiecutter.project_slug}}.service	Tue Jun 06 15:09:45 2017 +0200
@@ -0,0 +1,18 @@
+[Unit]
+Description = ZEO daemon for {{ cookiecutter.project_name }} service
+After = network.target
+After = syslog.target
+
+[Service]
+PermissionsStartOnly = true
+PIDFile = $((INSTALL))/var/run/{{ cookiecutter.project_slug }}.pid
+User = {{ cookiecutter.run_user }}
+Group = {{ cookiecutter.run_group }}
+WorkingDirectory = $((INSTALL))
+ExecStart = $((INSTALL))/etc/init.d/zeo-{{ cookiecutter.project_slug }} start
+ExecReload = $((INSTALL))/etc/init.d/zeo-{{ cookiecutter.project_slug }} logreopen
+ExecStop = $((INSTALL))/etc/init.d/zeo-{{ cookiecutter.project_slug }} stop
+PrivateTmp = true
+
+[Install]
+WantedBy = multiuser.target
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/{{cookiecutter.project_slug}}/var/db/README.txt	Tue Jun 06 15:09:45 2017 +0200
@@ -0,0 +1,1 @@
+This directory will contain ZEO data files