Skip to main content

Cascade CMS Filename Rule Enforcer

This package was developed to automate the enforcement of file naming conventions in an enterprise instance of Cascade CMS 8 for the College of Charleston, but has been re-written in a way that allows you to set the configuration for your own Cascade CMS environment. With over 100 sites to manage, and each site containing improperly named resources that were allowed in the previous Cascade Server 7 from which we migrated, we needed a way of automatically detecting improper file names (file names with spaces and capitalized letters) and fixing them dynamically. This package handles that automation in an object-oriented way.

How To Use

You can refer to the test() method here if you want a more extensive example of usage, but here is the basic flow of using the package.

  • I recommend first creating and activating a virtual environment:
  • python3.6 -m venv venv && source venv/bin/activate
  • Next, install the package using pip
  • pip install py-cascade8-filename-enforcer
  • Create a python file, e.g. test.py
  • Inside the file, add the following content
from cascade8_filename_enforcer.enforcer import CascadeCMSFileNameRuleEnforcer

# specific to my example, I need quote to correctly parse 
# the password from the environment variable
from requests.utils import quote 
# Set your configuration variables
# I like to use os.environ.get() to pull from environment variables. 
import os
# There is a start-dev-template.sh script you can use to set the values for these.
cpass = quote(os.environ.get('CASCADE_CMS_PASS',''))
cuser = os.environ.get('CASCADE_CMS_USER','')
# The base URL of the Cascade 8 REST API. THIS SHOULD END WITH /api/v1
restapi= os.environ.get('CASCADE_CMS_REST_API_BASE','') 

# Create a rule enforcer 
rule_enforcer = CascadeCMSFileNameRuleEnforcer(
    cuser=cuser, cpass=cpass, restapi=restapi
)
site_name = "name_of_your_site"
site_id = "id_of_your_site"
# Call the recursive traversal function that will also 
# fix your improperly named assets as well as return a list of 
# the ones it fixes in the form of: 
[
    {
        "old": "old BAD name.png",
        "new": "old-bad-name.png"
    },
    {
        "old": "old BAD name 2.png",
        "new": "old-bad-name-2.png"
    },... 
] 
assets_fixed = rule_enforcer.traverse(
    current_parent_folder=f'{site_name}',
    site_full_assets_list=[], # initialize empty list 
    # sites for which you want to skip enforcement
    skip_sites=["_Auto-Migrated Global_", "_skeleton.cofc.edu"] 
)
print(assets_fixed) 
publish_result = rule_enforcer.publish_site(site_id)
print(publish_result)

The following is a more elaborate use of the package to iterate over many sites and keep a record of what was changed for each in JSON format.

def main(): 
    """ Production call - loop through all Cascade CMS sites and 
    fix improper filenames, keeping a record of the resources changed in 
    a local JSON file """ 
    # Create rule enforcer
    cpass = quote(os.environ.get('CASCADE_CMS_PASS',''))
    cuser = os.environ.get('CASCADE_CMS_USER','')
    restapi= os.environ.get('CASCADE_CMS_REST_API_BASE','')
    rule_enforcer = CascadeCMSFileNameRuleEnforcer(
        cpass=cpass, cuser=cuser, restapi=restapi
    ) 
    site_dicts = []
    for s in rule_enforcer.get_all_sites():
        site_name = s['path']['path']
        site_id = s['id'] 
        # Start with the base of site_name/content. initialize a
        print(f"Beginning scan for invalid filenames in site {site_name}")
        site_dictionary = {
            f'{site_name}': {
                'bad_assets': rule_enforcer.traverse(
                    current_parent_folder=f'{site_name}/content',
                    site_full_assets_list=[], # always empty initially
                    skip_sites=["_Auto-Migrated Global_", "_skeleton.cofc.edu"] # sites to skip enforcement
                )
            } 
        }
        site_dictionary[site_name]['publish_result'] = rule_enforcer.publish_site(site_id) 
        site_dicts.append(site_dictionary)
        with open('site_read.json', 'w') as f:
            json.dump(site_dicts, f)
        print(f"Completed scan of site {site_name}")

if __name__ == "__main__":
    # One site: redesign.cofc.edu 
    # test()
    # All sites!
    main()

Notes

  • If your site(s) does not have a root /content folder (e.g. sitename.edu/content in Cascade), be sure to remove the /content portion of the current_parent_folder argument.

Release files for py-cascade8-filename-enforcer 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-cascade8-filename-enforcer 0.0.3
File Size Uploaded
py-cascade8-filename-enforcer-0.0.3.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-cascade8-filename-enforcer 0.0.3
File Interpreter ABI Platform
py_cascade8_filename_enforcer-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 15.4 kB

Release files / py-cascade8-filename-enforcer-0.0.3.tar.gz

Download URL py-cascade8-filename-enforcer-0.0.3.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2b147c375242ebea99df983d7b5e33f421a7f517e1177f05a9fd2adbffec808a
BLAKE2b-256 checksum
How to use checksums
8fda423368439cafff68837292f3ce9593b77c79bca4d5983d19622e9bdd81c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.6.12

Release files / py_cascade8_filename_enforcer-0.0.3-py3-none-any.whl

Download URL py_cascade8_filename_enforcer-0.0.3-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76e1074decf7422b0a972fee9282072a2cd6942258d463fce3eb94ec1b994327
BLAKE2b-256 checksum
How to use checksums
f976b97cc778aee8ce5f7f6ea0955544d69e57095dadceec6a0863616fad90dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.6.12

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page