Permalink
Browse files

FEATURE: Move setup-src.py to use_the_source in a tools package.

This file can be imported as a module to allow other tools to access the source-to-installed mappings

Make integration test `--use-src` flag use the new `use_the_source.py`.

`stacki-cluster-up` will also be updated to use this tool.
  • Loading branch information...
bsanders authored and masonkatz committed Nov 15, 2018
1 parent 327542c commit bae560c776096e99266d24a5432d42103a2df5db
@@ -59,7 +59,7 @@ Vagrant.configure("2") do |config|
end

if USE_SRC == "1"
config.vm.synced_folder "../common/src", "/export/src", type: "virtualbox"
config.vm.synced_folder "../", "/export/src/stacki", type: "virtualbox"
end
end

@@ -1,9 +1,3 @@
---
- name: Copy over setup-src.py script
copy:
src: files/setup-src.py
dest: /root/
mode: 0744

- name: Run the setup-src.py script
command: /root/setup-src.py
- name: Run the use_the_source.py script
command: /opt/stack/bin/python3 /export/src/stacki/tools/use_the_source/use_the_source.py /export/src/stacki
@@ -0,0 +1,17 @@
# @Copyright@
# @Copyright@

PKGROOT = /opt/stack
ROLLROOT = ../..
DEPENDS.FILES = use_the_source.py

include $(STACKBUILD)/etc/CCRules.mk


build:
echo "Building ... "

install::
mkdir -p -m 550 $(ROOT)/$(PKGROOT)/bin/
$(INSTALL) -m 0550 use_the_source.py $(ROOT)/$(PKGROOT)/bin/use_the_source

@@ -1,7 +1,7 @@
#!/opt/stack/bin/python3
import sys
from pathlib import Path

src_base = Path("/export/src/stack")
dest_base = Path("/opt/stack/lib/python3.6/site-packages")

grafts_to_site_packages = (
@@ -20,21 +20,6 @@
("ws-client/pylib", "")
)

for src, dest in grafts_to_site_packages:
src_directory = src_base / src
dest_directory = dest_base / dest

# Find all our Python files
for src_filename in src_directory.glob("**/*.py"):
dest_filename = dest_directory / src_filename.relative_to(src_directory)

# First blow away the old one, if it exists
if dest_filename.exists():
dest_filename.unlink()

# Now symlink over our src version
dest_filename.symlink_to(src_filename)

bin_file_grafts = (
("command/stack.py", "/opt/stack/bin/stack"),
("discovery/bin/discover-nodes.py", "/opt/stack/sbin/discover-nodes"),
@@ -51,13 +36,36 @@
("ws-client/bin/wsclient.py", "/opt/stack/bin/wsclient")
)

for src, dest in bin_file_grafts:
src_filename = src_base / src
dest_filename = Path(dest)
if __name__ == '__main__':
if len(sys.argv) != 2:
print(f'{Path(__file__).name} <path_to_stacki_source_tree>')
sys.exit(1)

# get the absolute path, expanding shell stuff
src_base = Path(sys.argv[1]).expanduser().resolve() / 'common/src/stack/'

# Blow away the old one, if it exists
if dest_filename.exists():
dest_filename.unlink()
for src, dest in grafts_to_site_packages:
src_directory = src_base / src
dest_directory = dest_base / dest

# Now symlink over our src version
dest_filename.symlink_to(src_filename)
# Find all our Python files
for src_filename in src_directory.glob("**/*.py"):
dest_filename = dest_directory / src_filename.relative_to(src_directory)

# First blow away the old one, if it exists
if dest_filename.exists() or dest_filename.is_symlink():
dest_filename.unlink()

# Now symlink over our src version
dest_filename.symlink_to(src_filename)

for src, dest in bin_file_grafts:
src_filename = src_base / src
dest_filename = Path(dest)

# Blow away the old one, if it exists
if dest_filename.exists() or dest_filename.is_symlink():
dest_filename.unlink()

# Now symlink over our src version
dest_filename.symlink_to(src_filename)
@@ -0,0 +1,2 @@
NAME=stacki-use-the-source
RELEASE=all

0 comments on commit bae560c

Please sign in to comment.