Skip to content

Commit 248d4b0

Browse files
committed
Clean up old -fs targets in Makefile.
Use instance-local.yaml instead to override for example the data storage layer of the backend from relstoraeg to file/blobstorage.
1 parent b6beaf5 commit 248d4b0

File tree

4 files changed

+159
-12
lines changed

4 files changed

+159
-12
lines changed

backend/Makefile

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ bin/pip:
9494
config: bin/pip ## Create instance configuration
9595
@echo "$(GREEN)==> Create instance configuration$(RESET)"
9696
bin/cookiecutter -f --no-input --config-file instance.yaml --checkout 2.1.0 gh:plone/cookiecutter-zope-instance
97-
98-
.PHONY: config-fs
99-
config-fs: bin/pip ## Create instance configuration
100-
@echo "$(GREEN)==> Create instance configuration$(RESET)"
101-
bin/cookiecutter -f --no-input --config-file instance-filestorage.yaml --checkout 2.1.0 gh:plone/cookiecutter-zope-instance
97+
if [[ -s instance-local.yaml ]]; then \
98+
echo ">>> Using instance-local.yaml"; \
99+
bin/cookiecutter -f --no-input --config-file instance-local.yaml --checkout 2.1.0 gh:plone/cookiecutter-zope-instance ;\
100+
else \
101+
bin/cookiecutter -f --no-input --config-file instance.yaml --checkout 2.1.0 gh:plone/cookiecutter-zope-instance ;\
102+
fi
102103

103104
# i18n
104105
bin/i18ndude: bin/pip
@@ -120,13 +121,6 @@ build-dev: config ## pip install Plone packages
120121
@bin/mxdev -c mx.ini
121122
bin/pip install -r requirements-mxdev.txt
122123

123-
.PHONY: build-dev-fs
124-
build-dev-fs: config-fs ## pip install Plone packages
125-
@echo "$(GREEN)==> Setup Build$(RESET)"
126-
sed "s/PLONE_VERSION/$(PLONE_VERSION)/g" constraints-template.txt > constraints.txt
127-
@bin/mxdev -c mx.ini
128-
bin/pip install -r requirements-mxdev.txt
129-
130124
.PHONY: format
131125
format: ## Format the codebase according to our standards
132126
@echo "$(GREEN)==> Format codebase$(RESET)"

backend/instance-filestorage.yaml renamed to backend/instance-local.yaml.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# If you rename this file to instance-local.yaml, the Makefile config/build commands
2+
# will use this file for local development
3+
# In it you can override the backend setup to use for example file/blobstorage
4+
# instead of the relstorage connection used in testing/production deployment
5+
16
default_context:
27
initial_user_name: 'admin'
38
initial_user_password: 'adminadmin'
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Run this from the backend directory with:
2+
# bin/zconsole run instance/etc/zope.conf scripts/catalog_clear_rebuild.py
3+
# or with extra options: --site=nl
4+
5+
from plone import api
6+
from zope.component import getUtility
7+
from zope.component.hooks import setSite
8+
9+
import argparse
10+
import sys
11+
import transaction
12+
13+
parser = argparse.ArgumentParser()
14+
parser.add_argument(
15+
"--site",
16+
default="",
17+
dest="site",
18+
help="Single site id to work on. Default is to work on all.",
19+
)
20+
# sys.argv will be something like:
21+
# ['.../parts/instance/bin/interpreter', '-c',
22+
# 'scripts/fix_related_items_and_intids.py', '--site=nl']
23+
# Ignore the first three.
24+
options = parser.parse_args(args=sys.argv[3:])
25+
26+
# 'app' is the Zope root.
27+
# Get Plone Sites to work on.
28+
if options.site:
29+
# Get single Plone Site.
30+
plones = [getattr(app, options.site)]
31+
else:
32+
# Get all Plone Sites.
33+
plones = [
34+
obj
35+
for obj in app.objectValues() # noqa
36+
if getattr(obj, "portal_type", "") == "Plone Site"
37+
]
38+
39+
40+
def commit(note):
41+
print(note)
42+
# Commit transaction and add note.
43+
tr = transaction.get()
44+
tr.note(note)
45+
transaction.commit()
46+
47+
48+
for site in plones:
49+
print("")
50+
print("Handling Plone Site %s." % site.id)
51+
setSite(site)
52+
catalog = api.portal.get_tool(name="portal_catalog")
53+
catalog.manage_catalogRebuild()
54+
print("Catalog is rebuilt, now doing a search to empty the indexing queue. This may take long.")
55+
catalog.unrestrictedSearchResults(SearchableText="Maro 1:3")
56+
note = (
57+
"Cleared and rebuilt the catalog for %s." % site.id
58+
)
59+
commit(note)
60+
print("Done.")
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Run this with:
2+
# bin/zconsole run instance/etc/zope.conf scripts/purge_image_scales.py
3+
#
4+
# Add --dry-run to change nothing and only get a report.
5+
6+
import sys
7+
import transaction
8+
from Products.CMFCore.utils import getToolByName
9+
from plone.scale.storage import AnnotationStorage
10+
from zope.component.hooks import setSite
11+
12+
# Keep scales of at most X days older than their context:
13+
DAYS = -1
14+
# Commit after these many changes:
15+
LIMIT = 1000
16+
17+
if '--dry-run' in sys.argv:
18+
dry_run = True
19+
print('Dry run selected, will not commit changes.')
20+
else:
21+
dry_run = False
22+
23+
# Get all Plone Sites. 'app' is the Zope root.
24+
plones = [obj for obj in app.objectValues()
25+
if getattr(obj, 'portal_type', '') == 'Plone Site']
26+
27+
28+
def commit(note):
29+
print(note)
30+
if dry_run:
31+
print('Dry run selected, not committing.')
32+
return
33+
# Commit transaction and add note.
34+
tr = transaction.get()
35+
tr.note(note)
36+
transaction.commit()
37+
38+
39+
for site in plones:
40+
print('')
41+
print('Handling Plone Site %s.' % site.id)
42+
setSite(site)
43+
catalog = getToolByName(site, 'portal_catalog')
44+
count = 0
45+
purged = 0
46+
for brain in catalog.getAllBrains():
47+
try:
48+
obj = brain.getObject()
49+
except:
50+
continue
51+
savepoint = transaction.savepoint()
52+
ann = AnnotationStorage(obj)
53+
try:
54+
ann.storage
55+
except TypeError:
56+
# This happens when the context cannot be annotated, for
57+
# example for a plone.app.discussion comment.
58+
continue
59+
# We want to remove all scales that are X days older than the
60+
# last modification date of the object.
61+
final_date = obj.modified() - DAYS
62+
changed = False
63+
to_delete = []
64+
for key, value in ann.items():
65+
if value['modified'] < final_date.millis():
66+
to_delete.append(key)
67+
for key in to_delete:
68+
# This may easily give an error, as it tries to remove
69+
# two keys: del ann[key]
70+
del ann.storage[key]
71+
purged += 1
72+
changed = True
73+
if not changed:
74+
# This avoids adding an empty annotation for items that
75+
# will never store scales.
76+
savepoint.rollback()
77+
else:
78+
count += 1
79+
if count % LIMIT == 0:
80+
note = ('Purged %d outdated image scales for %d items in '
81+
'Plone Site %s.' % (purged, count, site.id))
82+
commit(note)
83+
84+
note = ('Finished purging %d outdated image scales for %d items in '
85+
'Plone Site %s.' % (purged, count, site.id))
86+
commit(note)
87+
88+
print('Done.')

0 commit comments

Comments
 (0)