Skip to content

Commit 74b70fd

Browse files
committed
add setup.py
update Readme
1 parent 96e655e commit 74b70fd

File tree

6 files changed

+151
-2
lines changed

6 files changed

+151
-2
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Takazumi-Shirayanagi
3+
Copyright (c) 2014 Takazumi Shirayanagi
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
1-
wandbox-api
1+
Wandbox Python API
22
===========
3+
4+
[Wandbox](http://melpon.org/wandbox/) is a social compilation service.
5+
This project is a Pythonic binding to the Wandbox API.
6+
7+
Installation
8+
--------------------------------------------------
9+
10+
git clone https://github.com/srz-zumix/wandbox-api.git
11+
cd wandbox-api
12+
python setup.py install
13+
14+
15+
Getting Started
16+
--------------------------------------------------
17+
18+
from wandbox import Wandbox
19+
20+
w = Wandbox()
21+
w.compiler('gcc-head')
22+
w.options('warning,gnu++1y')
23+
w.compiler_options('-Dx=hogefuga\n-O3')
24+
w.code('#include <iostream>\nint main() { int x = 0; std::cout << "hoge" << std::endl; }')
25+
print w.run()

sample/sample.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python
2+
3+
from wandbox import Wandbox
4+
5+
if __name__ == '__main__':
6+
w = Wandbox()
7+
w.compiler('gcc-head')
8+
w.options('warning,gnu++1y')
9+
w.compiler_options('-Dx=hogefuga\n-O3')
10+
w.code('#include <iostream>\nint main() { int x = 0; std::cout << "hoge" << std::endl; }')
11+
print w.run()
12+

setup.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
from setuptools import setup
3+
4+
f = open(os.path.join(os.path.dirname(__file__), 'README.md'))
5+
readme = f.read()
6+
f.close()
7+
8+
VERSION = "0.1.0"
9+
10+
setup(
11+
name = "wandbox-api"
12+
, version = VERSION
13+
, author = "Takazumi Shirayanagi"
14+
, author_email = "[email protected]"
15+
, url = "https://github.com/srz-zumix/wandbox-api/"
16+
, description = "A Python binding to the Wandbox API."
17+
, license = "MIT"
18+
, platforms = ["any"]
19+
, keywords = "API, Wandbox"
20+
, packages = ['wandbox']
21+
, long_description = readme
22+
, classifiers = [
23+
"Development Status :: 3 - Alpha"
24+
, "Topic :: Utilities"
25+
, "License :: OSI Approved :: MIT License"
26+
]
27+
, install_requires=['requests']
28+
)
29+

wandbox/__init__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
__author__ = 'Takazumi Shirayanagi'
2+
__version__ = '0.1.0'
3+
4+
__copyright__ = '2014 %s ' % __author__
5+
__license__ = """
6+
The MIT License (MIT)
7+
8+
Copyright (c) %s
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in all
18+
copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
SOFTWARE.
27+
""" % __copyright__
28+
29+
30+
from wandbox import Wandbox

wandbox/wandbox.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python
2+
#
3+
# wandbox.py
4+
#
5+
6+
import requests
7+
import json
8+
9+
#
10+
#
11+
#
12+
class Wandbox:
13+
"""wandbox api class"""
14+
api_url = 'http://melpon.org/wandbox/api'
15+
parameter = { 'code':'' }
16+
def get_compiler_list(self):
17+
r = requests.get(self.api_url + '/list.json')
18+
r.raise_for_status()
19+
return r.json()
20+
def run(self):
21+
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
22+
payload = json.dumps(self.parameter)
23+
r = requests.post(self.api_url + '/compile.json', data=payload, headers=headers)
24+
r.raise_for_status()
25+
return r.json()
26+
def get_permlink(self, link):
27+
r = requests.get(self.api_url + '/permlink/' + link )
28+
r.raise_for_status()
29+
return r.json()
30+
31+
def code(self, str):
32+
self.parameter.update({'code':str})
33+
def compiler(self, str):
34+
self.parameter.update({'compiler':str})
35+
def options(self, str):
36+
self.parameter.update({'options':str})
37+
def stdin(self, str):
38+
self.parameter.update({'stdin':str})
39+
def compiler_options(self, str):
40+
self.parameter.update({'compiler-option-raw':str})
41+
def runtime_options(self, str):
42+
self.parameter.update({'runtime-option-raw':str})
43+
def permanent_link(self, b):
44+
self.parameter.update({'save':b})
45+
def dump(self):
46+
print self.parameter
47+
48+
if __name__ == '__main__':
49+
w = Wandbox()
50+
w.compiler('gcc-head')
51+
w.options('warning,gnu++1y')
52+
w.compiler_options('-Dx=hogefuga\n-O3')
53+
w.code('#include <iostream>\nint main() { int x = 0; std::cout << "hoge" << std::endl; }')
54+
print w.run()
55+

0 commit comments

Comments
 (0)