Skip to content

Commit

Permalink
Update _cp_examples_from_src in mkworkspace.py
Browse files Browse the repository at this point in the history
Merge pull request #37
  • Loading branch information
gwenblum authored Oct 11, 2024
2 parents 5df2d27 + de1e3f9 commit ebb0d28
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ From here you can start to use the SteelScript framework. You can try some scrip

.. code:: shell
python examples/appresponse-examples/print_hostgroups-formatted.py {appresponse fqdn or IP address} -u {admin account} -p {password}
python examples/steelscript-appresponse/print_hostgroups-formatted.py {appresponse fqdn or IP address} -u {admin account} -p {password}
2. Get the licenses and services of a Client Accelerator Controller appliance:

.. code:: shell
python examples/cacontroller-examples/cacontroller-rest_api.py {client accelerator controller fqdn or IP address} --access_code {access_code}
python examples/steelscript-cacontroller/cacontroller-rest_api.py {client accelerator controller fqdn or IP address} --access_code {access_code}
3. List the devices from NetIM Core:

.. code:: shell
python examples/netim-examples/print-netim-devices-raw.py {netim core fqdn or IP address} --username {account} --password {password}
python examples/steelscript-netim/print-netim-devices-raw.py {netim core fqdn or IP address} --username {account} --password {password}
Run examples with Jupyter Notebook
Expand All @@ -67,7 +67,7 @@ Run the container with Jupyter Notebook server, by default on port 8888
In the output, grab the url containing the *token*, for example *http://127.0.0.1:8888/tree?token=123456* ,
and open it in your browser to log into the Jupyter web-console.

From there, in the *Notebooks* folder you can find some notebook examples based on SteelScript.
From there, in the *Notebooks* folder you can find some notebook based on SteelScript.

Guide
-------------------------
Expand Down Expand Up @@ -139,7 +139,7 @@ The repos of SteelScript modules have a common structure
├── CHANGELOG
├── .gitignore
├── docs
├── examples
├──
├── steelscript
│ ├── __init__.py
│ └── module-name # for example: appresponse
Expand All @@ -160,7 +160,7 @@ Mandatory:
- LICENSE: Riverbed Technology copyright, terms and conditions based on MIT
- CHANGELOG: Simple text file tracking major changes
- /docs: Documentation using reStructured Text (rst) file format.
- /examples: Python scripts samples showing how to use the module.
- /: Python scripts samples showing how to use the module.
- /steelscript: The actual code, written in Python. Must be Python3 only.
- /tests: Test plans and unit test. Can be organized in subfolders. Test plan are ideally documented and easy to run scripts but can be anything defining a test plan (script, text, ...), for example a python script based on pytest.
- setup.py: Python setup file containing meta descriptions and requirements. Based on setuptools, distutils, gitpy-versioning (custom versioning tool https://github.com/riverbed/gitpy-versioning) and pytest. Should NOT contain unit test (use Tox and put unit test inside /tests folder instead)
Expand Down
28 changes: 18 additions & 10 deletions steelscript/commands/mkworkspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,27 @@ def _cp_examples_from_docs(cls, dirpath, overwrite):
@classmethod
def _cp_examples_from_src(cls, dirpath, overwrite):
"""Copy all examples and notebooks from steelscript root dirs."""
# Get the dir of src for steelscript. ex. /src/steelscript/steelscript
# Remove suffix to get the root path of the packages, ex. /src
steelscript_src_path = os.path.dirname(steelscript.__file__)
suffix = "steelscript/steelscript"
pkgs_src_root_path="src"
if steelscript_src_path.endswith(suffix):
pkgs_src_root_path = steelscript_src_path[:-len(suffix)].rstrip('/')

# Get package names with prefix steel (ex. steelscript.netshark)
# Replace '.' with '-' in case 'steelscript.' is a prefix
# Get the paths of installed packages (ex /src/steelscript-netprofiler)
pkg_paths = [os.path.dirname(p) for p in steelscript.__path__]
all_distributions = list(distributions())
steel_pkg_names = [dist.name.replace("steelscript.","steelscript-") for dist in all_distributions if dist.name.startswith('steel')]

for kind in ('examples', 'notebooks'):
paths = [os.path.join(p, kind) for p in pkg_paths
if os.path.exists(os.path.join(p, kind))]

mkname = lambda x: (cls.path_leaf(x) + '-' + kind).split('-', 1)[1]
dst_paths = [os.path.join(dirpath, kind,
mkname(os.path.dirname(p)))
for p in paths]

cls._cp_files(kind, paths, dst_paths, overwrite)
for pkg_name in steel_pkg_names:
steel_pkg_src_path = os.path.join(pkgs_src_root_path,pkg_name)
content_path = os.path.join(steel_pkg_src_path, kind)
if os.path.exists(content_path):
destination_path = os.path.join(dirpath, kind, pkg_name)
cls._cp_files(kind, [content_path], [destination_path], overwrite)

@classmethod
def _cp_files(cls, kind, src_paths, dst_paths, overwrite):
Expand Down

0 comments on commit ebb0d28

Please sign in to comment.