Last active
September 9, 2016 11:43
-
-
Save obihann/86f47c4e66b9a70a0f1445a0bb6fdfca to your computer and use it in GitHub Desktop.
List all folders in a directory as subdomains and store as a index.html file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| PATH = os.getenv('WWW', '/var/www') | |
| ENV = os.getenv('ENV', 'DEV') | |
| DOMAINS = {'DEV': 'develop', 'QA': 'testing'} | |
| def buildURL(folder): | |
| return "http://{env}.{domain}.example.com/".format(env=folder, domain=DOMAINS[ENV]) | |
| def cleanBranch(branch): | |
| rgx = re.compile('^((feature|hotfix|bugfix)[-](.+))$') | |
| match = rgx.match(branch) | |
| if (match and len(match.groups()) >= 3): | |
| return "{feat}/{name}".format(feat=match.group(2).upper(), name=match.group(3)) | |
| else: | |
| return branch | |
| dirs = [name for name in os.listdir(PATH) if os.path.isdir(os.path.join(PATH, name))] | |
| links = [buildURL(dir) for dir in dirs] | |
| page = """ | |
| <html> | |
| <body> | |
| <ul> | |
| """ | |
| for pos, dir in enumerate(dirs): | |
| page += "<li><a href={link}>{folder}</a> (last modified {lm})</li>\n".format(link=links[pos], folder=cleanBranch(dir), lm=time.ctime(os.path.getmtime(os.path.join(PATH, dir)))) | |
| page += """ | |
| </ul> | |
| </body> | |
| </html> | |
| """ | |
| f = open(PATH + '/index.html', 'w') | |
| f.write(page) | |
| f.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment