Skip to content

Commit dadb35a

Browse files
committed
Add making canned client rules
1 parent 8e7e320 commit dadb35a

File tree

4 files changed

+95
-12
lines changed

4 files changed

+95
-12
lines changed

Makefile

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,54 @@
11
PRODUCT=metacat
22
BUILD_DIR=$(HOME)/build/$(PRODUCT)
3-
TARDIR=/tmp
3+
TARDIR=/tmp/$(USER)
44
LIBDIR=$(BUILD_DIR)/lib
55
MODULEDIR=$(LIBDIR)/metacat
66
SERVER_DIR=$(BUILD_DIR)/server
77
DOCSDIR=$(BUILD_DIR)/docs
88
DOCSREL=$(BUILD_DIR)/docs
99
UI_DIR=$(BUILD_DIR)/ui
10+
DEPS_DIR=$(BUILD_DIR)/dependencies
1011
SERVER_TAR=$(TARDIR)/$(PRODUCT)_server_$(VERSION).tar
12+
CLIENT_TAR=$(TARDIR)/$(PRODUCT)_client_$(VERSION).tar
1113

12-
all:
14+
CANNED_MODULES=pythreader jwt requests
15+
CANNED_PIP_MODULES="pythreader>=2.8.0" "pyjwt" "requests"
16+
17+
all:
1318
echo Use "make dune" or "make generic"
14-
19+
1520
dune:
1621
make VERSION=`python metacat/version.py`_dune dune_with_version_defined
1722

1823
generic:
1924
make VERSION=`python metacat/version.py` generic_with_version_defined
2025

21-
dune_with_version_defined: build dune_specifics
22-
make VERSION=$(VERSION) tars
23-
24-
generic_with_version_defined: build
25-
make VERSION=$(VERSION) tars
26+
dune_with_version_defined: dune_specifics tars
2627

27-
tars: $(TARDIR)
28+
generic_with_version_defined: tars
29+
30+
tars: build $(TARDIR)
2831
cd $(BUILD_DIR); tar cf $(SERVER_TAR) lib server docs
2932
@echo \|
30-
@echo \| tarfile is created: $(SERVER_TAR)
33+
@echo \| Server tarfile is created: $(SERVER_TAR)
3134
@echo \|
3235

36+
client:
37+
make VERSION=`python metacat/version.py` client_with_version_defined
38+
39+
client_with_version_defined: canned_client $(TARDIR)
40+
cd $(BUILD_DIR); tar cf $(CLIENT_TAR) lib dependencies docs ui canned_client_setup.sh
41+
@echo \|
42+
@echo \| Canned client tarfile is created: $(CLIENT_TAR)
43+
@echo \|
44+
45+
canned_client: build $(DEPS_DIR)
46+
pip install $(CANNED_PIP_MODULES)
47+
python tools/copy_modules.py -c $(CANNED_MODULES) $(DEPS_DIR)
48+
rm -rf $(DEPS_DIR)/*/__pycache__
49+
find $(DEPS_DIR) -type f -name \*.pyc -exec rm -f {} \;
50+
cp canned_client_setup.sh $(BUILD_DIR)
51+
3352
dune_specifics:
3453
cd DUNE_specials; make SERVER_DIR=$(SERVER_DIR) build
3554

@@ -38,13 +57,17 @@ build: clean $(BUILD_DIR)
3857
cd metacat; make LIBDIR=$(LIBDIR) VERSION=$(VERSION) BINDIR=$(UI_DIR) build
3958
cd webserver; make SERVER_DIR=$(SERVER_DIR) LIBDIR=$(LIBDIR) VERSION=$(VERSION) build
4059
cd docs; make SERVER_DIR=$(SERVER_DIR) DOCSDIR=$(DOCSDIR) -f Makefile-product build
41-
60+
find $(BUILD_DIR) -type d -name __pycache__ -print | xargs rm -rf
61+
find $(BUILD_DIR) -type f -name \*.pyc -print -exec rm {} \;
62+
4263
clean:
4364
rm -rf $(BUILD_DIR) $(SERVER_TAR)
4465

4566
$(TARDIR):
4667
mkdir -p $@
4768

69+
$(DEPS_DIR):
70+
mkdir -p $@
4871

4972
$(BUILD_DIR):
5073
mkdir -p $@

canned_client_setup.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# edit and soutrce this file
2+
3+
export METACAT_SERVER_URL=...
4+
export METACAT_AUTH_SERVER_URL=...
5+
6+
METACAT_CLIENT_ROOT=... # where you untared the metacat_client_...tar
7+
8+
# to use dependencies installed with pip or otherwise
9+
export PYTHONPATH=${METACAT_CLIENT_ROOT}/lib
10+
11+
# to use canned dependencies, add dependencies subdirectory
12+
# export PYTHONPATH=${METACAT_CLIENT_ROOT}/lib:${METACAT_CLIENT_ROOT}/dependencies
13+
14+
export PATH=${METACAT_CLIENT_ROOT}/ui

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get_version():
2020
keywords = "metadata, data management, database, web service",
2121
url = "https://github.com/ivmfnal/metacat",
2222
packages=['metacat', 'metacat.db', 'metacat.util', 'metacat.webapi', 'metacat.ui', 'metacat.auth', 'metacat.ui.cli'],
23-
install_requires=["pyjwt", "requests"],
23+
install_requires=["pyjwt", "requests", "pythreader>=2.8.0"],
2424
zip_safe = False,
2525
classifiers=[
2626
],

tools/copy_modules.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import sys, importlib, os.path, getopt
2+
from pythreader import ShellCommand
3+
4+
Usage = """
5+
python copy_modules.py [options] <module> [...] <out_dir>"
6+
options:
7+
-q - quiet, do not print status information
8+
-c - create output directory if does not exist. Raise an error otherwise.
9+
"""
10+
11+
def copy_module(mod_name, out_dir):
12+
mod = importlib.import_module(mod_name)
13+
mod_file = mod.__file__
14+
mod_dir, mod_file_name = os.path.split(mod.__file__)
15+
if mod_file_name.startswith("__init__"):
16+
cmd = f"/bin/cp -R {mod_dir} {out_dir}"
17+
else:
18+
cmd = f"/bin/cp {mod_file} {out_dir}"
19+
status, out, error = ShellCommand.execute(cmd)
20+
if status != 0:
21+
raise RuntimeError(f"Error copying module {mod_name}: {out}\n{error}")
22+
23+
opts, args = getopt.getopt(sys.argv[1:], "qch?")
24+
opts = dict(opts)
25+
26+
if not args or "-?" in opts or "-h" in opts:
27+
print(Usage)
28+
sys.exit(2)
29+
30+
modules, out_dir = args[:-1], args[-1]
31+
32+
if not os.path.isdir(out_dir):
33+
if "-c" in opts:
34+
os.makedirs(out_dir, mode=0o744)
35+
else:
36+
print(f"Output directory {out_dir} does not exist. Use -c to create", file=sys.stderr)
37+
sys.exit(1)
38+
39+
for mod in modules:
40+
try:
41+
copy_module(mod, out_dir)
42+
except Exception as e:
43+
print(e, file=sys.stderr)
44+
sys.exit(1)
45+
if "-q" not in opts:
46+
print("copied:", mod)

0 commit comments

Comments
 (0)