creates3site
creates3site
Python script to ask for bucket name, creates a aws s3 bucket, config for static site, uploads permissions, creates a nikola site, uploads site.
In [1]:
import subprocess
import json
import os
In [2]:
import getpass
In [3]:
myusr = getpass.getuser()
In [ ]:
In [4]:
class devsite():
def makebucket(namebucket):
subprocess.call('aws s3 mb s3://{}'.format(namebucket), shell=True)
def makewwwbucket(namebucket):
subprocess.call('aws s3 mb s3://www.{}'.format(namebucket), shell=True)
def createapp(namebucket):
subprocess.call('aws elasticbeanstalk create-application --application-name {} --description "{}"'.format(namebucket, namebucket), shell=True)
def deleteapp(namebucket):
subprocess.call('aws elasticbeanstalk delete-application --application-name {}'.format(namebucket))
def infoapp():
#subprocess.call('aws elasticbeanstalk describe-applications')
return(subprocess.check_output(["aws", "elasticbeanstalk", "describe-applications"]))
def listbucket():
return(subprocess.check_output('aws s3api list-buckets --query "Buckets[].Name" --output "json"', shell=True))
def wsconf(namebucket):
subprocess.call('aws s3api put-bucket-website --bucket {} --website-configuration file://website.json'.format(namebucket), shell=True)
def nikinit(namebucket):
subprocess.call('nikola init -q /home/{}/sites/{}'.format(myusr, namebucket), shell=True)
In [5]:
devsite.infoapp()
Out[5]:
In [ ]:
In [9]:
devsite.nikinit('newtest')
In [ ]:
with open('/home/{}/sites/{}/conf.py'.format(myusr, ))
In [ ]:
In [3]:
devsite.infoapp()
In [4]:
devsite.deleteapp('MyApp')
In [ ]:
In [5]:
devsite.createapp('testing')
In [6]:
myitems = devsite.listbucket()
In [7]:
myitems
Out[7]:
In [19]:
myitems.replace('\n', '')
In [ ]:
str(myitems)
In [7]:
type (myitems)
Out[7]:
In [28]:
myitems.capitalize()
Out[28]:
In [31]:
for it in myitems:
print(it.from_bytes{})
In [8]:
mydecode = myitems.decode("utf-8")
In [9]:
mylis = mydecode.replace('\n', '')
In [10]:
type(mylis)
Out[10]:
In [11]:
myspli = mylis.split(' ')
In [12]:
type(myspli)
Out[12]:
In [14]:
lenspi = len(myspli)
In [16]:
for mys in range(0, lenspi, 2):
print(myspli[mys])
In [ ]:
In [13]:
print(myspli[8])
In [ ]:
range(0, 10, 2)
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [39]:
list(mydecode)
Out[39]:
In [ ]:
In [ ]:
In [36]:
for myit in myitems.decode("utf-8"):
print(myit )
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [12]:
for devs in devsite.listbucket():
print(devs)
In [ ]:
In [ ]:
In [3]:
devSite.makebucket('lonewill')
In [ ]:
In [2]:
def makebucket(namebucket):
subprocess.call('aws s3 mb s3://{}'.format(namebucket), shell=True)
In [3]:
def makewwwbucket(namebucket):
subprocess.call('aws s3 mb s3://www.{}'.format(namebucket), shell=True)
In [4]:
def wsconf(namebucket):
subprocess.call('aws s3api put-bucket-website --bucket {} --website-configuration file://website.json'.format(namebucket), shell=True)
In [5]:
def wsindex(namebucket):
subprocess.call('aws s3 website s3://{} --index-document index.html --error-document error.html'.format(namebucket), shell=True)
In [6]:
def nikinit(namebucket):
subprocess.call('nikola init -q {}'.format(namebucket), shell=True)
In [7]:
makebucket('breakdownand.com')
In [8]:
makewwwbucket('breakdownand.com')
In [9]:
wsconf('breakdownand.com')
In [11]:
wsindex('breakdownand.com')
In [13]:
nikinit('breakdownand.com')
In [43]:
def permop(namebucket):
with open('permission.json', 'r') as permj:
permrd = (permj.read())
editjs = permrd.replace('editthis', namebucket)
with open('permission.json', 'w') as permwrit:
permwrit.write(editjs)
subprocess.call('aws s3api put-bucket-policy --bucket {} --policy file://permission.json'.format(namebucket), shell=True)
In [45]:
with open('permission.json', 'r') as permj:
permrd = (permj.read())
editjs = permrd.replace('editthis', namebucket)
with open('permission.json', 'w') as permwrit:
permwrit.write(editjs)
In [ ]:
In [44]:
permop('breakdownand.com')
In [39]:
permop('breakdown.com')
Out[39]:
In [47]:
def retusome(namebucket):
return namebucket
In [48]:
retusome('breakdownand.com')
Out[48]:
In [ ]:
In [11]:
with open('permission.json', 'r+') as permj:
permrd = (permj.read())
In [12]:
anperz = permrd.replace('examplebucket', retusome('breakdownand.com'))
In [13]:
jslo = json.loads(anperz)
In [63]:
editjs = json.dumps(jslo)
In [66]:
with open('permission.json', 'w') as permwrit:
permwrit.write(editjs)
In [69]:
def sstact(namebucket):
subprocess.call('aws s3api put-bucket-policy --bucket {} --policy file://permission.json'.format(namebucket), shell=True)
In [70]:
sstact('breakdownand.com')
In [105]:
with open('{}/conf.py'.format(inputnam), 'r+') as configz:
confrd = (configz.read())
In [110]:
confiza = confrd.replace("Demo Site", inputnam.replace('.com', ''))
In [112]:
with open('{}/conf.py'.format(inputnam), 'w') as confix:
confix.write(confiza)
In [114]:
os.chdir('breakdownandcry.com/')
In [116]:
subprocess.call('nikola build', shell= True)
Out[116]:
In [119]:
os.chdir('output')
In [121]:
subprocess.call('aws s3 sync . s3://{}'.format(inputnam), shell=True)
Out[121]:
Comments
Comments powered by Disqus