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]:
b'{\n    "Applications": [\n        {\n            "DateCreated": "2018-04-08T06:51:52.953Z",\n            "ConfigurationTemplates": [],\n            "Description": "testing",\n            "ApplicationName": "testing",\n            "DateUpdated": "2018-04-08T06:51:52.953Z"\n        },\n        {\n            "DateCreated": "2018-04-08T02:28:16.318Z",\n            "ConfigurationTemplates": [],\n            "Description": "my application",\n            "ApplicationName": "MyApp",\n            "DateUpdated": "2018-04-08T02:28:16.318Z"\n        },\n        {\n            "Versions": [\n                "Sample Application"\n            ],\n            "DateCreated": "2018-04-06T14:59:34.304Z",\n            "ConfigurationTemplates": [],\n            "ApplicationName": "lonesearch",\n            "DateUpdated": "2018-04-06T14:59:34.304Z"\n        }\n    ]\n}\n'
In [ ]:
 
In [9]:
devsite.nikinit('newtest')
In [ ]:
with open('/home/{}/sites/{}/conf.py'.format(myusr, ))
In [ ]:
 
In [3]:
devsite.infoapp()
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-3-0c87a5520995> in <module>()
----> 1 devsite.infoapp()

<ipython-input-2-8dbc3a253c7d> in infoapp()
     14     def infoapp():
     15         #subprocess.call('aws elasticbeanstalk describe-applications')
---> 16         return(subprocess.check_output('aws elasticbeanstalk describe-applications'))
     17 
     18     def listbucket():

/usr/lib/python3.5/subprocess.py in check_output(timeout, *popenargs, **kwargs)
    624 
    625     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 626                **kwargs).stdout
    627 
    628 

/usr/lib/python3.5/subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
    691         kwargs['stdin'] = PIPE
    692 
--> 693     with Popen(*popenargs, **kwargs) as process:
    694         try:
    695             stdout, stderr = process.communicate(input, timeout=timeout)

/usr/lib/python3.5/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds)
    945                                 c2pread, c2pwrite,
    946                                 errread, errwrite,
--> 947                                 restore_signals, start_new_session)
    948         except:
    949             # Cleanup if the child failed starting.

/usr/lib/python3.5/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1549                             else:
   1550                                 err_msg += ': ' + repr(orig_executable)
-> 1551                     raise child_exception_type(errno_num, err_msg)
   1552                 raise child_exception_type(err_msg)
   1553 

FileNotFoundError: [Errno 2] No such file or directory: 'aws elasticbeanstalk describe-applications'
In [4]:
devsite.deleteapp('MyApp')
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-4-2db2f960bca5> in <module>()
----> 1 devsite.deleteapp('MyApp')

<ipython-input-2-8dbc3a253c7d> in deleteapp(namebucket)
     10 
     11     def deleteapp(namebucket):
---> 12         subprocess.call('aws elasticbeanstalk delete-application --application-name {}'.format(namebucket))
     13 
     14     def infoapp():

/usr/lib/python3.5/subprocess.py in call(timeout, *popenargs, **kwargs)
    555     retcode = call(["ls", "-l"])
    556     """
--> 557     with Popen(*popenargs, **kwargs) as p:
    558         try:
    559             return p.wait(timeout=timeout)

/usr/lib/python3.5/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds)
    945                                 c2pread, c2pwrite,
    946                                 errread, errwrite,
--> 947                                 restore_signals, start_new_session)
    948         except:
    949             # Cleanup if the child failed starting.

/usr/lib/python3.5/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1549                             else:
   1550                                 err_msg += ': ' + repr(orig_executable)
-> 1551                     raise child_exception_type(errno_num, err_msg)
   1552                 raise child_exception_type(err_msg)
   1553 

FileNotFoundError: [Errno 2] No such file or directory: 'aws elasticbeanstalk delete-application --application-name MyApp'
In [ ]:
 
In [5]:
devsite.createapp('testing')
In [6]:
myitems = devsite.listbucket()
In [7]:
myitems
Out[7]:
b'[\n    "artcontrol.me",\n    "artcontrolme",\n    "artcontrolstage.me",\n    "artctrl-stage",\n    "artctrl-staging",\n    "artctrl.com",\n    "artctrl.me",\n    "artctrlme.com",\n    "breakdownand.com",\n    "breakdownandcry.com",\n    "edlawlx",\n    "edlawlx.com",\n    "edugovtnzjobs",\n    "elasticbeanstalk-ap-southeast-2-457225832206",\n    "govhacknz.org.nz",\n    "grandmasparty",\n    "hellotesting",\n    "jobsgovtnz",\n    "kiwijamnowtest",\n    "lifedrawinghamilton",\n    "moejobs",\n    "moejobs-govthacknz16",\n    "wcmckee.tk",\n    "writersdenhamilton.org.nz",\n    "www.artctrl.me",\n    "www.artctrlme.com",\n    "www.breakdownand.com",\n    "www.breakdownandcry.com",\n    "www.wcmckee.tk",\n    "www.writersdenhamilton.org.nz"\n]\n'
In [19]:
myitems.replace('\n', '')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-4cf8d037f9e0> in <module>()
----> 1 myitems.replace('\n', '')

TypeError: a bytes-like object is required, not 'str'
In [ ]:
str(myitems)
In [7]:
type (myitems)
Out[7]:
bytes
In [28]:
myitems.capitalize()
Out[28]:
b'[\n    "artcontrol.me",\n    "artcontrolme",\n    "artcontrolstage.me",\n    "artctrl-stage",\n    "artctrl-staging",\n    "artctrl.com",\n    "artctrl.me",\n    "artctrlme.com",\n    "breakdownand.com",\n    "breakdownandcry.com",\n    "edlawlx",\n    "edlawlx.com",\n    "edugovtnzjobs",\n    "elasticbeanstalk-ap-southeast-2-457225832206",\n    "govhacknz.org.nz",\n    "grandmasparty",\n    "hellotesting",\n    "jobsgovtnz",\n    "kiwijamnowtest",\n    "lifedrawinghamilton",\n    "moejobs",\n    "moejobs-govthacknz16",\n    "wcmckee.tk",\n    "writersdenhamilton.org.nz",\n    "www.artctrl.me",\n    "www.artctrlme.com",\n    "www.breakdownand.com",\n    "www.breakdownandcry.com",\n    "www.wcmckee.tk",\n    "www.writersdenhamilton.org.nz"\n]\n'
In [31]:
for it in myitems:
    print(it.from_bytes{})
  File "<ipython-input-31-92ca706ce492>", line 2
    print(it.from_bytes{})
                       ^
SyntaxError: invalid syntax
In [8]:
mydecode = myitems.decode("utf-8")
In [9]:
mylis = mydecode.replace('\n', '')
In [10]:
type(mylis)
Out[10]:
str
In [11]:
myspli =  mylis.split('  ')
In [12]:
type(myspli)
Out[12]:
list
In [14]:
lenspi = len(myspli)
In [16]:
for mys in range(0, lenspi, 2):
    print(myspli[mys])
[
"artcontrol.me",
"artcontrolme",
"artcontrolstage.me",
"artctrl-stage",
"artctrl-staging",
"artctrl.com",
"artctrl.me",
"artctrlme.com",
"breakdownand.com",
"breakdownandcry.com",
"edlawlx",
"edlawlx.com",
"edugovtnzjobs",
"elasticbeanstalk-ap-southeast-2-457225832206",
"govhacknz.org.nz",
"grandmasparty",
"hellotesting",
"jobsgovtnz",
"kiwijamnowtest",
"lifedrawinghamilton",
"moejobs",
"moejobs-govthacknz16",
"wcmckee.tk",
"writersdenhamilton.org.nz",
"www.artctrl.me",
"www.artctrlme.com",
"www.breakdownand.com",
"www.breakdownandcry.com",
"www.wcmckee.tk",
"www.writersdenhamilton.org.nz"]
In [ ]:
 
In [13]:
print(myspli[8])
"artctrl-stage",
In [ ]:
range(0, 10, 2)
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [39]:
list(mydecode)
Out[39]:
['[',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 'o',
 'n',
 't',
 'r',
 'o',
 'l',
 '.',
 'm',
 'e',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 'o',
 'n',
 't',
 'r',
 'o',
 'l',
 'm',
 'e',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 'o',
 'n',
 't',
 'r',
 'o',
 'l',
 's',
 't',
 'a',
 'g',
 'e',
 '.',
 'm',
 'e',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 't',
 'r',
 'l',
 '-',
 's',
 't',
 'a',
 'g',
 'e',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 't',
 'r',
 'l',
 '-',
 's',
 't',
 'a',
 'g',
 'i',
 'n',
 'g',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 't',
 'r',
 'l',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 't',
 'r',
 'l',
 '.',
 'm',
 'e',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 't',
 'r',
 'l',
 'm',
 'e',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'b',
 'r',
 'e',
 'a',
 'k',
 'd',
 'o',
 'w',
 'n',
 'a',
 'n',
 'd',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'b',
 'r',
 'e',
 'a',
 'k',
 'd',
 'o',
 'w',
 'n',
 'a',
 'n',
 'd',
 'c',
 'r',
 'y',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'e',
 'd',
 'l',
 'a',
 'w',
 'l',
 'x',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'e',
 'd',
 'l',
 'a',
 'w',
 'l',
 'x',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'e',
 'd',
 'u',
 'g',
 'o',
 'v',
 't',
 'n',
 'z',
 'j',
 'o',
 'b',
 's',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'e',
 'l',
 'a',
 's',
 't',
 'i',
 'c',
 'b',
 'e',
 'a',
 'n',
 's',
 't',
 'a',
 'l',
 'k',
 '-',
 'a',
 'p',
 '-',
 's',
 'o',
 'u',
 't',
 'h',
 'e',
 'a',
 's',
 't',
 '-',
 '2',
 '-',
 '4',
 '5',
 '7',
 '2',
 '2',
 '5',
 '8',
 '3',
 '2',
 '2',
 '0',
 '6',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'g',
 'o',
 'v',
 'h',
 'a',
 'c',
 'k',
 'n',
 'z',
 '.',
 'o',
 'r',
 'g',
 '.',
 'n',
 'z',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'g',
 'r',
 'a',
 'n',
 'd',
 'm',
 'a',
 's',
 'p',
 'a',
 'r',
 't',
 'y',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'h',
 'e',
 'l',
 'l',
 'o',
 't',
 'e',
 's',
 't',
 'i',
 'n',
 'g',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'j',
 'o',
 'b',
 's',
 'g',
 'o',
 'v',
 't',
 'n',
 'z',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'k',
 'i',
 'w',
 'i',
 'j',
 'a',
 'm',
 'n',
 'o',
 'w',
 't',
 'e',
 's',
 't',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'l',
 'i',
 'f',
 'e',
 'd',
 'r',
 'a',
 'w',
 'i',
 'n',
 'g',
 'h',
 'a',
 'm',
 'i',
 'l',
 't',
 'o',
 'n',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'm',
 'o',
 'e',
 'j',
 'o',
 'b',
 's',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'm',
 'o',
 'e',
 'j',
 'o',
 'b',
 's',
 '-',
 'g',
 'o',
 'v',
 't',
 'h',
 'a',
 'c',
 'k',
 'n',
 'z',
 '1',
 '6',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'c',
 'm',
 'c',
 'k',
 'e',
 'e',
 '.',
 't',
 'k',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'r',
 'i',
 't',
 'e',
 'r',
 's',
 'd',
 'e',
 'n',
 'h',
 'a',
 'm',
 'i',
 'l',
 't',
 'o',
 'n',
 '.',
 'o',
 'r',
 'g',
 '.',
 'n',
 'z',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'w',
 'w',
 '.',
 'a',
 'r',
 't',
 'c',
 't',
 'r',
 'l',
 '.',
 'm',
 'e',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'w',
 'w',
 '.',
 'a',
 'r',
 't',
 'c',
 't',
 'r',
 'l',
 'm',
 'e',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'w',
 'w',
 '.',
 'b',
 'r',
 'e',
 'a',
 'k',
 'd',
 'o',
 'w',
 'n',
 'a',
 'n',
 'd',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'w',
 'w',
 '.',
 'b',
 'r',
 'e',
 'a',
 'k',
 'd',
 'o',
 'w',
 'n',
 'a',
 'n',
 'd',
 'c',
 'r',
 'y',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'w',
 'w',
 '.',
 'w',
 'c',
 'm',
 'c',
 'k',
 'e',
 'e',
 '.',
 't',
 'k',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'w',
 'w',
 '.',
 'w',
 'r',
 'i',
 't',
 'e',
 'r',
 's',
 'd',
 'e',
 'n',
 'h',
 'a',
 'm',
 'i',
 'l',
 't',
 'o',
 'n',
 '.',
 'o',
 'r',
 'g',
 '.',
 'n',
 'z',
 '"',
 '\n',
 ']',
 '\n']
In [ ]:
 
In [ ]:
 
In [36]:
for myit in myitems.decode("utf-8"):
    print(myit )
[


 
 
 
 
"
a
r
t
c
o
n
t
r
o
l
.
m
e
"
,


 
 
 
 
"
a
r
t
c
o
n
t
r
o
l
m
e
"
,


 
 
 
 
"
a
r
t
c
o
n
t
r
o
l
s
t
a
g
e
.
m
e
"
,


 
 
 
 
"
a
r
t
c
t
r
l
-
s
t
a
g
e
"
,


 
 
 
 
"
a
r
t
c
t
r
l
-
s
t
a
g
i
n
g
"
,


 
 
 
 
"
a
r
t
c
t
r
l
.
c
o
m
"
,


 
 
 
 
"
a
r
t
c
t
r
l
.
m
e
"
,


 
 
 
 
"
a
r
t
c
t
r
l
m
e
.
c
o
m
"
,


 
 
 
 
"
b
r
e
a
k
d
o
w
n
a
n
d
.
c
o
m
"
,


 
 
 
 
"
b
r
e
a
k
d
o
w
n
a
n
d
c
r
y
.
c
o
m
"
,


 
 
 
 
"
e
d
l
a
w
l
x
"
,


 
 
 
 
"
e
d
l
a
w
l
x
.
c
o
m
"
,


 
 
 
 
"
e
d
u
g
o
v
t
n
z
j
o
b
s
"
,


 
 
 
 
"
e
l
a
s
t
i
c
b
e
a
n
s
t
a
l
k
-
a
p
-
s
o
u
t
h
e
a
s
t
-
2
-
4
5
7
2
2
5
8
3
2
2
0
6
"
,


 
 
 
 
"
g
o
v
h
a
c
k
n
z
.
o
r
g
.
n
z
"
,


 
 
 
 
"
g
r
a
n
d
m
a
s
p
a
r
t
y
"
,


 
 
 
 
"
h
e
l
l
o
t
e
s
t
i
n
g
"
,


 
 
 
 
"
j
o
b
s
g
o
v
t
n
z
"
,


 
 
 
 
"
k
i
w
i
j
a
m
n
o
w
t
e
s
t
"
,


 
 
 
 
"
l
i
f
e
d
r
a
w
i
n
g
h
a
m
i
l
t
o
n
"
,


 
 
 
 
"
m
o
e
j
o
b
s
"
,


 
 
 
 
"
m
o
e
j
o
b
s
-
g
o
v
t
h
a
c
k
n
z
1
6
"
,


 
 
 
 
"
w
c
m
c
k
e
e
.
t
k
"
,


 
 
 
 
"
w
r
i
t
e
r
s
d
e
n
h
a
m
i
l
t
o
n
.
o
r
g
.
n
z
"
,


 
 
 
 
"
w
w
w
.
a
r
t
c
t
r
l
.
m
e
"
,


 
 
 
 
"
w
w
w
.
a
r
t
c
t
r
l
m
e
.
c
o
m
"
,


 
 
 
 
"
w
w
w
.
b
r
e
a
k
d
o
w
n
a
n
d
.
c
o
m
"
,


 
 
 
 
"
w
w
w
.
b
r
e
a
k
d
o
w
n
a
n
d
c
r
y
.
c
o
m
"
,


 
 
 
 
"
w
w
w
.
w
c
m
c
k
e
e
.
t
k
"
,


 
 
 
 
"
w
w
w
.
w
r
i
t
e
r
s
d
e
n
h
a
m
i
l
t
o
n
.
o
r
g
.
n
z
"


]


In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [12]:
for devs in devsite.listbucket():
    print(devs)
91
10
32
32
32
32
34
97
114
116
99
111
110
116
114
111
108
46
109
101
34
44
10
32
32
32
32
34
97
114
116
99
111
110
116
114
111
108
109
101
34
44
10
32
32
32
32
34
97
114
116
99
111
110
116
114
111
108
115
116
97
103
101
46
109
101
34
44
10
32
32
32
32
34
97
114
116
99
116
114
108
45
115
116
97
103
101
34
44
10
32
32
32
32
34
97
114
116
99
116
114
108
45
115
116
97
103
105
110
103
34
44
10
32
32
32
32
34
97
114
116
99
116
114
108
46
99
111
109
34
44
10
32
32
32
32
34
97
114
116
99
116
114
108
46
109
101
34
44
10
32
32
32
32
34
97
114
116
99
116
114
108
109
101
46
99
111
109
34
44
10
32
32
32
32
34
98
114
101
97
107
100
111
119
110
97
110
100
46
99
111
109
34
44
10
32
32
32
32
34
98
114
101
97
107
100
111
119
110
97
110
100
99
114
121
46
99
111
109
34
44
10
32
32
32
32
34
101
100
108
97
119
108
120
34
44
10
32
32
32
32
34
101
100
108
97
119
108
120
46
99
111
109
34
44
10
32
32
32
32
34
101
100
117
103
111
118
116
110
122
106
111
98
115
34
44
10
32
32
32
32
34
101
108
97
115
116
105
99
98
101
97
110
115
116
97
108
107
45
97
112
45
115
111
117
116
104
101
97
115
116
45
50
45
52
53
55
50
50
53
56
51
50
50
48
54
34
44
10
32
32
32
32
34
103
111
118
104
97
99
107
110
122
46
111
114
103
46
110
122
34
44
10
32
32
32
32
34
103
114
97
110
100
109
97
115
112
97
114
116
121
34
44
10
32
32
32
32
34
104
101
108
108
111
116
101
115
116
105
110
103
34
44
10
32
32
32
32
34
106
111
98
115
103
111
118
116
110
122
34
44
10
32
32
32
32
34
107
105
119
105
106
97
109
110
111
119
116
101
115
116
34
44
10
32
32
32
32
34
108
105
102
101
100
114
97
119
105
110
103
104
97
109
105
108
116
111
110
34
44
10
32
32
32
32
34
109
111
101
106
111
98
115
34
44
10
32
32
32
32
34
109
111
101
106
111
98
115
45
103
111
118
116
104
97
99
107
110
122
49
54
34
44
10
32
32
32
32
34
119
99
109
99
107
101
101
46
116
107
34
44
10
32
32
32
32
34
119
114
105
116
101
114
115
100
101
110
104
97
109
105
108
116
111
110
46
111
114
103
46
110
122
34
44
10
32
32
32
32
34
119
119
119
46
97
114
116
99
116
114
108
46
109
101
34
44
10
32
32
32
32
34
119
119
119
46
97
114
116
99
116
114
108
109
101
46
99
111
109
34
44
10
32
32
32
32
34
119
119
119
46
98
114
101
97
107
100
111
119
110
97
110
100
46
99
111
109
34
44
10
32
32
32
32
34
119
119
119
46
98
114
101
97
107
100
111
119
110
97
110
100
99
114
121
46
99
111
109
34
44
10
32
32
32
32
34
119
119
119
46
119
99
109
99
107
101
101
46
116
107
34
44
10
32
32
32
32
34
119
119
119
46
119
114
105
116
101
114
115
100
101
110
104
97
109
105
108
116
111
110
46
111
114
103
46
110
122
34
10
93
10
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)
        
---------------------------------------------------------------------------
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 [11]:
with open('permission.json', 'r+') as permj:
    permrd = (permj.read())
In [12]:
anperz = permrd.replace('examplebucket', retusome('breakdownand.com'))
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-12-5e15dc492438> in <module>()
----> 1 anperz = permrd.replace('examplebucket', retusome('breakdownand.com'))

NameError: name 'retusome' is not defined
In [13]:
jslo = json.loads(anperz)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-13-47bc08ee43e6> in <module>()
----> 1 jslo = json.loads(anperz)

NameError: name 'anperz' is not defined
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