Begin addon reorganization
This commit is contained in:
parent
aa18d3904e
commit
7b13e6ff71
25 changed files with 29 additions and 1589 deletions
27
packages/zammad-addon-common/Makefile
Normal file
27
packages/zammad-addon-common/Makefile
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
.PHONY: prep clean
|
||||
|
||||
build: prep
|
||||
@./package.py
|
||||
@find dist/ -iname "*szpm"
|
||||
|
||||
prep:
|
||||
@mkdir -p dist
|
||||
|
||||
clean: prep
|
||||
@rm -rf dist/*
|
||||
|
||||
fmt:
|
||||
rufo src
|
||||
|
||||
new-migration:
|
||||
@./new-migration.py
|
||||
|
||||
init:
|
||||
@echo "Give your addon a name. No spaces."
|
||||
@echo "Addon name?: "; \
|
||||
read NAME; \
|
||||
mkdir -p "src/db/addon/$${NAME}"; \
|
||||
sed -i "s/NAME/$${NAME}/" base.szpm.template; \
|
||||
mv base.szpm.template "$${NAME}.szpm.template"
|
||||
|
||||
test: build
|
||||
28
packages/zammad-addon-common/common.zpm.template
Normal file
28
packages/zammad-addon-common/common.zpm.template
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"name": "PackageName",
|
||||
"version": "0.1.0",
|
||||
"vendor": "Center for Digital Resilience",
|
||||
"license": "AGPL-v3+",
|
||||
"url": "https://gitlab.com/digiresilience/link/zammad-addon-package-name",
|
||||
"buildhost": "",
|
||||
"builddate": "",
|
||||
"change_log": [
|
||||
{
|
||||
"version": "0.0.1",
|
||||
"date": "2020-02-11",
|
||||
"log": "First version with CDR secure defaults"
|
||||
},
|
||||
{
|
||||
"version": "0.0.2",
|
||||
"date": "2020-02-11",
|
||||
"log": "Fix bug when uninstalled"
|
||||
}
|
||||
],
|
||||
"description": [
|
||||
{
|
||||
"language": "en",
|
||||
"text": "Change me"
|
||||
}
|
||||
],
|
||||
"files": []
|
||||
}
|
||||
0
packages/zammad-addon-common/index.js
Normal file
0
packages/zammad-addon-common/index.js
Normal file
43
packages/zammad-addon-common/new-migration.py
Executable file
43
packages/zammad-addon-common/new-migration.py
Executable file
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python3
|
||||
import os
|
||||
import json
|
||||
import glob
|
||||
import inflection
|
||||
from datetime import datetime
|
||||
from collections import OrderedDict
|
||||
|
||||
migration_template = """class {} < ActiveRecord::Migration[5.2]
|
||||
def self.up
|
||||
# add your code here
|
||||
end
|
||||
|
||||
def self.down
|
||||
# add your code here
|
||||
end
|
||||
end
|
||||
"""
|
||||
|
||||
|
||||
def load_skeleton():
|
||||
t = glob.glob('*.szpm.template')
|
||||
if len(t) != 1:
|
||||
raise Exception("Cannot find szpm template")
|
||||
with open(t[0], 'r', encoding='utf-8') as f:
|
||||
skeleton = json.load(f, object_pairs_hook=OrderedDict)
|
||||
return skeleton
|
||||
|
||||
|
||||
def main():
|
||||
skeleton = load_skeleton()
|
||||
name = skeleton["name"].lower()
|
||||
raw_name = input("Enter migration name: ")
|
||||
migration_base_name = "{}_{}".format(name, inflection.underscore(raw_name))
|
||||
migration_name = inflection.camelize(migration_base_name, uppercase_first_letter=True)
|
||||
contents = migration_template.format(migration_name)
|
||||
time = datetime.utcnow().strftime("%Y%m%d%H%M%S")
|
||||
migration_file_name = "{}_{}.rb".format(time, migration_base_name)
|
||||
with open(os.path.join("src/db/addon/", skeleton["name"], migration_file_name), 'w') as f:
|
||||
f.write(contents)
|
||||
|
||||
|
||||
main()
|
||||
11
packages/zammad-addon-common/package.json
Normal file
11
packages/zammad-addon-common/package.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "zammad-addon-common",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
75
packages/zammad-addon-common/package.py
Executable file
75
packages/zammad-addon-common/package.py
Executable file
|
|
@ -0,0 +1,75 @@
|
|||
#!/usr/bin/env python3
|
||||
import os
|
||||
import base64
|
||||
import json
|
||||
import datetime
|
||||
import platform
|
||||
import glob
|
||||
import re
|
||||
from collections import OrderedDict
|
||||
|
||||
# files matching this pattern are not included in the package
|
||||
ignored_patterns = [
|
||||
"\.gitkeep"
|
||||
]
|
||||
|
||||
|
||||
def encode(fname):
|
||||
data = open(fname, "r", encoding='utf-8').read().encode('utf-8')
|
||||
return base64.b64encode(data).decode('utf-8')
|
||||
|
||||
|
||||
def read_perm(fname):
|
||||
return int(oct(os.stat(fname).st_mode & 0o777)[-3:])
|
||||
|
||||
|
||||
def format_file(content, pkg_path, permission):
|
||||
return OrderedDict(
|
||||
location=pkg_path,
|
||||
permission=permission,
|
||||
encode="base64",
|
||||
content=content)
|
||||
|
||||
|
||||
def pkg_file(actual_path):
|
||||
print(" Packaging: {}".format(actual_path))
|
||||
pkg_path = actual_path[6:]
|
||||
contents = encode(actual_path)
|
||||
res = format_file(contents, pkg_path, read_perm(actual_path))
|
||||
return res
|
||||
|
||||
|
||||
def pkg_files():
|
||||
pkged_files = []
|
||||
for root, dirs, files in os.walk("./src/"):
|
||||
for f in files:
|
||||
if any(re.search(r, f) for r in ignored_patterns):
|
||||
continue
|
||||
actual_path = os.path.join(root, f)
|
||||
pkged_files.append(pkg_file(actual_path))
|
||||
return pkged_files
|
||||
|
||||
|
||||
def load_skeleton():
|
||||
t = glob.glob('*.szpm.template')
|
||||
if len(t) != 1:
|
||||
raise Exception("Cannot find szpm template")
|
||||
with open(t[0], 'r', encoding='utf-8') as f:
|
||||
skeleton = json.load(f, object_pairs_hook=OrderedDict)
|
||||
return skeleton
|
||||
|
||||
|
||||
def main():
|
||||
files = pkg_files()
|
||||
skeleton = load_skeleton()
|
||||
skeleton["files"] = files
|
||||
skeleton["builddate"] = datetime.datetime.utcnow().isoformat()
|
||||
skeleton["buildhost"] = platform.node()
|
||||
name = skeleton["name"].lower()
|
||||
version = skeleton["version"]
|
||||
pkg = json.dumps(skeleton, indent=2)
|
||||
with open("dist/{}-v{}.szpm".format(name, version), "w", encoding='utf-8') as f:
|
||||
f.write(pkg)
|
||||
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue