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]:
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)
        
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-45-8ebf0f6de56c> in <module>()
      1 with open('permission.json', 'r') as permj:
      2         permrd = (permj.read())
----> 3         editjs = permrd.replace('editthis', namebucket)
      4 with open('permission.json', 'w') as permwrit:
      5     permwrit.write(editjs)

NameError: name 'namebucket' is not defined
In [ ]:
 
In [44]:
permop('breakdownand.com')
In [39]:
permop('breakdown.com')
Out[39]:
'{"Version": "2012-10-17", "Statement": [{"Sid": "PublicReadGetObject", "Action": ["s3:GetObject"], "Principal": "*", "Resource": ["arn:aws:s3:::breakdownandcry.com/*"], "Effect": "Allow"}]}'
In [47]:
def retusome(namebucket):
    return namebucket 
In [48]:
retusome('breakdownand.com')
Out[48]:
'breakdownand.com'
In [ ]:
 
In [58]:
with open('/home/pi/permission.json', 'r+') as permj:
    permrd = (permj.read())
In [61]:
anperz = permrd.replace('editthis', retusome('breakdownand.com'))
In [62]:
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]:
0
In [119]:
os.chdir('output')
In [121]:
subprocess.call('aws s3 sync . s3://{}'.format(inputnam), shell=True)
Out[121]:
0

Comments

Comments powered by Disqus