Skip to content

Commit

Permalink
Merge pull request #9 from Smithsonian/OP1835_newscripts
Browse files Browse the repository at this point in the history
Op1835 newscripts
  • Loading branch information
PaulKGrimes authored Apr 18, 2023
2 parents e032637 + d4d9b34 commit f61ba5b
Show file tree
Hide file tree
Showing 11 changed files with 422 additions and 86 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/python_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
strategy:
max-parallel: 9
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.7, 3.8, 3.9]
redis-version: [5.0.3, latest]
os: [ubuntu-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
redis-version: [latest]

steps:
- name: Git checkout
Expand All @@ -32,13 +32,18 @@ jobs:
with:
redis-version: ${{ matrix.redis-version }}
auto-start: "true"
redis-conf: |
bind 127.0.0.1
protected-mode no
- name: Load LUA scripts
run: |
cd redis_config_files
./initscripts.sh
sudo ./install.sh
./smax-init.sh
- name: Test with pytest
run: |
cd ..
pytest
pytest -v -x --log-level=DEBUG
7 changes: 5 additions & 2 deletions pyproject.toml_bak → pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ build-backend = "setuptools.build_meta"
[tool.setuptools.packages.find]
# All the following settings are optional:
where = ["."] # ["."] by default
include = ["smax/"] # ["*"] by default
include = ["smax"] # ["*"] by default
exclude = ["redis_config_files*"] # empty by default

[project]
name = "smax-python"
name = "smax"
description = "Python code for interfacing to SMA-X"
readme = "README.md"
requires-python = ">=3.7"
license = {text = "MIT License"}
dependencies = [
"numpy",
"redis",
"psutil",
"hiredis",
"pytest"
]
dynamic = ["version"]

Expand Down
32 changes: 0 additions & 32 deletions redis_config_files/initscripts.sh

This file was deleted.

48 changes: 48 additions & 0 deletions redis_config_files/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
#
# Install, enable and run the smax-scripts.service with systemd
#
# This installer should be run as root/with sudo permissions
#
# Paul Grimes
# 04/18/2023
#
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit 1
fi

SMAX="/usr/share/smax"
LUA="/usr/share/smax/lua"

mkdir -p $SMAX
mkdir -p $LUA

cp -R "./lua" $SMAX
cp "./smax-init.sh" $SMAX
cp "./smax-scripts.service" $SMAX

chmod -R 755 $SMAX

ln -s "$SMAX/smax-scripts.service" "/etc/systemd/system/smax-scripts.service"

read -p "Configure redis for SMA-X at this time? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
cp "./redis.conf" "/etc/"
systemctl daemon-reload
systemctl enable redis
systemctl restart redis
fi

read -p "Enable smax-scripts at this time? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
systemctl daemon-reload
systemctl enable smax-scripts
systemctl restart smax-scripts
fi

exit
20 changes: 20 additions & 0 deletions redis_config_files/lua/ListLowerThan.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Returns all fields names that have a numerical value higher then the supplied lower bound
-- Author: Attila Kovacs
-- Keys: [1] table/meta/struct name
-- Arguments: <lower-bound>
-- Return: field names with numerical values higher than the argument
local result = {}
local k = 1
local upperbound = tonumber(ARGV[1])

local list = redis.call('hgetall', KEYS[1])
for i,v in pairs(list) do
if i%2 == 0 then
if tonumber(v) < upperbound then
result[k] = list[i-1]
k = k+1
end
end
end

return result
2 changes: 1 addition & 1 deletion redis_config_files/lua/Purge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local n = 0
for i,key in pairs(redis.call('keys', ARGV[1])) do

-- If key is a hash table the interate through elements to remove associated metadata
if redis.call('type', key) == 'hash' do
if redis.call('type', key) == 'hash' then
for j,field in pairs(redis.call('hkeys', key)) do
local id = key .. ':' .. field
redis.call('hdel', '<types>', id)
Expand Down
14 changes: 14 additions & 0 deletions redis_config_files/smax-init.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,27 @@ load_script() {
redis-cli hset scripts $NAME $SHA1
}

# Core SMA-X scripts
load_script HSet
load_script HGetWithMeta
load_script HSetWithMeta
load_script HMGetWithMeta
load_script HMSetWithMeta
load_script GetStruct
load_script DSMGetTable

# Utility scripts
load_script ListHigherThan
load_script ListLowerThan
load_script ListNewerThan
load_script ListOlderThan

# Removal and cleanup SMA-X scripts
load_script DelStruct
load_script PurgeVolatile
load_script Purge


exit 0


File renamed without changes.
Loading

0 comments on commit f61ba5b

Please sign in to comment.