Skip to content

Usage improvements for S3 bucket weblinks generation #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.venv
index
index.html
**/.idea
**/*.tgz
**/*.tar.gz
30 changes: 23 additions & 7 deletions index.py → generate_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,24 @@ def uploadIndexFile(strBucket,strPrefix,strIndexFile):
s3 = boto3.resource('s3')
bucket = s3.Bucket(strBucket)
bucket.upload_file(strIndexFile, strPrefix + strIndexFile,
ExtraArgs={'ACL': 'public-read', 'ContentType': 'text/html'})
ExtraArgs={'ContentType': 'text/html'})

def generateIndexFile(strBucket,strPrefix,strIndexFile,vecFiles,vecFolders,strTemplate):
with open(strTemplate) as inf:
txt = inf.read()
soup = bs4.BeautifulSoup(txt)
soup = bs4.BeautifulSoup(txt, "html.parser")

tagKeysList = soup.find("ul", {"id": "listkeys"})

tagKeysList.append(generateHeader(soup, strBucket, strPrefix))

if (strPrefix.count('/') > 0):
strAncestors = strPrefix.split('/')[:-2]
if len(strAncestors) > 0:
tagKeysList.append(generateElement(soup, True, '..', '/' + '/'.join(strAncestors) + '/index.html'))
else:
tagKeysList.append(generateElement(soup, True, '..', '/index.html'))

for strFolder in vecFolders:
strFolderLast = strFolder.split('/')[-2]
tagKeysList.append(generateElement(soup, True, strFolderLast, '/' + strFolder + 'index.html'))
Expand Down Expand Up @@ -71,9 +78,18 @@ def generateHeader(soup,strBucket,strPrefix):
tagHeader.append(tagH)
return tagHeader

strBucket = ''
strPrefix = ''
strIndexFile = 'index.html'
strTemplate = 'index_template.html'
if __name__ == '__main__':
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('-b', '--bucket', type=str, default='my-binaries', required=True)
parser.add_argument('-p', '--prefix', type=str, default='', required=False)
parser.add_argument('-i', '--indexFile', type=str, default='index.html', required=False)
parser.add_argument('-t', '--template', type=str, default='index_template.html', required=False)
args = parser.parse_args()

recPopulateIndexFiles(strBucket,strPrefix,strTemplate)
strBucket = args.bucket
strPrefix = args.prefix
strIndexFile = args.indexFile
strTemplate = args.template
recPopulateIndexFiles(strBucket,strPrefix,strTemplate)
44 changes: 5 additions & 39 deletions index_template.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>MapLarge.Server Support Binaries</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
Expand Down Expand Up @@ -28,54 +29,19 @@
</head>
<body>
<nav>
<div class="nav-wrapper yellow darken-4">
<div class="nav-wrapper light-blue">
<!-- <a href="#" class="brand-logo">Logo</a> -->
<!-- <i class="large material-icons">insert_chart</i> -->
<ul class="left">
<li><i class="material-icons iconnav">cloud_download</i></li>
<li class="topnav">AWS S3</li>
<li class="topnav">MapLarge.Server Support Binaries</li>
</ul>
</div>
</nav>
<ul id='listkeys' class="collection with-header collist">
<!-- <li class="collection-header">
<h4>Folder</h4>
</li>
<li class="collection-item">
<div class="valign-wrapper">
<i class="material-icons iconitem">folder_open</i>
<a href="/test/index.html" >test</a>
</div>
</li>
<li class="collection-item">
<div class="valign-wrapper">
<i class="material-icons iconitem">insert_drive_file</i>
<a href="/data1.txt" >data1.txt</a>
</div>
</li>
<li class="collection-item">
<div class="valign-wrapper">
<i class="material-icons iconitem">insert_drive_file</i>
<a href="/index.html" >index.htm</a>
</div>
</li> -->

</ul>
<!-- <div class="collection collist">
<a href="#!" class="collection-item yellow-text text-darken-4">Alvin</a>
<a href="#!" class="collection-item yellow-text text-darken-4">Alvin</a>
<a href="#!" class="collection-item yellow-text text-darken-4">Alvin</a>
<a href="#!" class="collection-item yellow-text text-darken-4">Alvin</a>
</div> -->
<!--
<div class="wrapper">
<ul class="collection">
<li class="collection-item"><i class="material-icons circle">folder</i>Alvin</li>
<li class="collection-item">Alvin</li>
<li class="collection-item">Alvin</li>
<li class="collection-item">Alvin</li>
</ul>
</div> -->
<!--JavaScript at end of body for optimized loading-->

<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
boto3
bs4