一个简单的Snappy Ubuntu python webserver
来源:互联网 发布:mac版pscc2017已破解 编辑:程序博客网 时间:2024/04/28 21:13
在前面的文章中,我们已经介绍了如何使用golang来创建我们的webserver.在今天的文章中,我们来介绍如何使用python在Snappy Ubuntu上创建一个简单的webserver.如果大家对我们使用的snapcraft还不是很熟的话,请参考文章"利用snapcraft为我们的Snappy Ubuntu应用打包".如果大家对如何在arm的装置上打snap包的话,请参考文章"如何为我们的Snappy Ubuntu应用编译并打包Snap(2)".
1)创建我们的简单的python webserver
我们可以参考一些比较简单的python webserver代码.在网路上有很多的代码.今天我们就采用其中的一种方案:
server.py
#!/usr/bin/pythonfrom BaseHTTPServer import BaseHTTPRequestHandler,HTTPServerPORT_NUMBER = 8080#This class will handles any incoming request from#the browser class myHandler(BaseHTTPRequestHandler):#Handler for the GET requestsdef do_GET(self):self.send_response(200)self.send_header('Content-type','text/html')self.end_headers()# Send the html messageself.wfile.write("Hello World !")returntry:#Create a web server and define the handler to manage the#incoming requestserver = HTTPServer(('', PORT_NUMBER), myHandler)print 'Started httpserver on port ' , PORT_NUMBER#Wait forever for incoming htto requestsserver.serve_forever()except KeyboardInterrupt:print '^C received, shutting down the web server'server.socket.close()
我们可以直接在我们的terminal中打入如下的命令:
$ python server.py Started httpserver on port 8080
如果在我们的浏览器中,我们可以直接访问该地址:
显然我们的webserver是正在运行的.在接下来的章节中,我们来把该python服务器来打包成为我们的snap.
2)制作python webserver snap
在这一节中,我们来展示如何制作一个python webserver的snap.首先,我们来仿照在文章"利用snapcraft为我们的Snappy Ubuntu应用打包"介绍的那样来创建我们的snapcraft.yaml文件.我们的文件如下:
snapcraft.yaml
name: pythonserverversion: 1.0vendor: XiaoGuo, Liu <xiaoguo.liu@canonical.com>summary: a simple python serverdescription: This is the webserver API in python demoicon: icon.pngservices: mywebserver: description: "A webserver in python" start: bin/server caps: - network-client - network-serviceparts: server: plugin: python3 source: . source: plugin: copy files: ./server.py: bin/server
在这里,我们使用parts来安装我们所需要的python的运行环境,同时,我们也把我们的server.py考入到我们所需要的位置.我们的python webserver将会以一种service的方式来运行.我们的整个项目的源码在如下的地址可以找到:
https://github.com/liu-xiao-guo/pythonserver
我们在termial中打入如下的命令来进行打包:
$ snapcraft
这样我们就可以生产我们所需要的snap包.
liuxg@liuxg:~/snappy/examples/pythonserver$ ls icon.png parts pythonserver_1.0_amd64.snap server.py snap snapcraft.yaml stage
(amd64)ubuntu@localhost:~$ snappy list -vName Date Version Developer ubuntu-core 2015-11-13 10 ubuntu* ubuntu-core 2015-10-23 9 ubuntu config-example 2015-11-30 IGbdLSNDOROd sideload* hello-xiaoguo 2015-11-05 IEeNEfBRVYGe sideload hello-xiaoguo 2015-11-27 IGTcTdAICYOL sideload* pastebinit 2015-11-02 1.4.0.0.2 mvo* pythonserver 2015-12-09 IHQdDRKVUaJc sideload pythonserver 2015-12-09 IHQdJgYaaSYY sideload* restapi 2015-12-07 IHMFUOgUERWG sideload* snappy-debug 2015-12-07 0.7 canonical* webdm 2015-10-23 0.9.2 canonical* generic-amd64 2015-10-23 1.4 canonical* (amd64)ubuntu@localhost:~$ sudo snappy service statusSnapServiceStatepythonservermywebserverenabled; loaded; active (running)webdmsnappydenabled; loaded; active (running)
0 0
- 一个简单的Snappy Ubuntu python webserver
- python中一个简单的webserver
- ubuntu下使用nginx、mysql、python搭建一个简单的webserver
- 一个简单的webserver
- 写一个简单的webserver
- 简单的WebServer细节
- WebServer的简单实现
- python + django搭建简单webserver
- 一步步实现WebServer中间件——从一个最简单的WebServer开始
- 一个简单的eclipse + axis1.4 开发webserver
- 如何写一个简单的webserver(一):最简实现
- webserver的简单login系统
- 一个简易的WebServer程序
- 一个简易的WebServer实现
- 用java编写简单Webserver,理解webserver的功能。
- 用java编写简单Webserver,理解webserver的功能。
- Snappy Ubuntu 入门
- Ubuntu Snappy 学习心得 (1)
- Linphone-iOS-移植
- recording
- BHO开发浏览器插件-Adding Menu Items
- 关于android刷机PhoenixSuit遇到的检测不到设备的问题
- CocoaPods的安装
- 一个简单的Snappy Ubuntu python webserver
- 对于iOS的fram,bounds,center的理解
- 多按钮共享事件,对话框,Toast
- springMVC注解@ModelAttribute的用法
- 大话设计模式之面向对象基础篇(四)
- c++编写爱情诗歌
- No video mode large enough for
- 关于TI CC2540 BLE协议栈中数据传输的几个函数实现(草稿)
- android中Webview与javascript的交互(互相调用)