zuroc avatar zuroc committed 3dd8232 Merge

fix

Comments (0)

Files changed (31)

config/nginx/vps.conf

+
+server  { 
+    listen          80;
+    server_name     index.istarsea.com;
+    proxy_pass      http://1.istarsea1.sinaapp.com/index.php\?doc-view-1 permanent;
+    charset         utf-8;
+} 
+
 server {
     listen          80;
     server_name     42qu.tk *.42qu.tk;
 # -*- coding: utf-8 -*-
 from _handler import Base
 from _urlmap import urlmap
-from model.vps_sell import VpsOrder , vps_order_count, vps_order_by_state, vps_one_list_by_vps_order, vps_one_open, vps_order_open, VPS_ORDER_STATE_PAY, vps_one_by_state, vps_order_cancel
+from model.vps_sell import VpsOrder , vps_order_count, vps_order_by_state, vps_one_list_by_vps_order, vps_one_open, vps_order_open, VPS_ORDER_STATE_PAY, vps_one_by_state, vps_order_cancel, VpsOne, VpsOneIp
 from zkit.page import page_limit_offset
+from zkit.ip import ip2int
+from model.user_mail import user_id_by_mail
+import re
+
 
 @urlmap('/vps/order/open/(\d+)')
 class OrderOpen(Base):
     def get(self, id):
         vps_order = self._vps_order(id)
-        if vps_order: 
+        if vps_order:
             self.render(vps_order=vps_order)
- 
+
     def _vps_order(self, id):
         vps_order = VpsOrder.get(id)
         if vps_order.state != VPS_ORDER_STATE_PAY:
-            self.redirect("/vps/order/%s"%id)
-            return 
+            self.redirect('/vps/order/%s'%id)
+            return
         return vps_order
 
 
     def post(self, id):
         vps_order = self._vps_order(id)
-        if vps_order: 
-            id_list = self.get_arguments("vps",())
+        if vps_order:
+            id_list = self.get_arguments('vps', ())
 
             for vps_id in id_list:
-                ip = self.get_argument("ip%s"%vps_id, "")
-                ip_inter = self.get_argument("ip_inter%s"%vps_id, "")
-                txt = self.get_argument("txt%s"%vps_id, None)
+                ip = self.get_argument('ip%s'%vps_id, '')
+                ip_inter = self.get_argument('ip_inter%s'%vps_id, '')
+                txt = self.get_argument('txt%s'%vps_id, None)
                 vps_one_open(vps_id, ip_inter, ip, txt)
 
 
             mail = self.get_argument('mail', False)
             vps_order_open(vps_order, mail)
 
-            return self.redirect("/vps/order/%s"%id)
+            return self.redirect('/vps/order/%s'%id)
 
 @urlmap('/vps/order/(\d+)')
 class Order(Base):
 class OrderCancel(Base):
     def get(self, id):
         vps_order_cancel(id)
-        self.redirect("/vps")
+        self.redirect('/vps')
 
 @urlmap('/vps')
 class Index(Base):
             20
         )
         self.render(
-            page = page,
-            ol = vps_order_by_state(
+            page=page,
+            ol=vps_order_by_state(
                 state,
                 limit,
                 offset
-            ) 
+            )
         )
 
 
             20
         )
         self.render(
-            page = page,
-            ol = vps_one_by_state(
+            page=page,
+            ol=vps_one_by_state(
                 state,
                 limit,
                 offset
-            ) 
+            )
         )
 
 
 
+@urlmap('/vps/search')
+class VpsSearch(Base):
+    def get(self):
+        q = keyword = self.get_argument('q', '')
+        vps_list = None 
 
+        if q:
+            if '@' in q:
+                user_id = user_id_by_mail(q)
+                if user_id:
+                    vps_list = VpsOne.where(user_id=user_id)
+            elif '.' in q:
+                ip = ip2int(q)
+                vps_list = VpsOne.mc_get_list(VpsOneIp.where(ip=ip).col_list(col='vps_one_id'))
+                vps = VpsOne.get(ip_inter=ip)
+                if vps:
+                    vps_list.append(vps)
+            else:
+                q = re.search('\d+', q)
+                if q:
+                    q = q.group()
+                    if q:
+                        vps = VpsOne.mc_get(q)
+                        vps_list = [vps]
+        if vps_list:
+            vps_list = set(vps_list)
 
+        self.render(q=keyword, vps_list=vps_list)
 
 
 
 
 
+
+
+
+
+
+

htm/god/vps/_base.htm

 
 <%def name="col2()">
 
-<a class="cola tc" href="/">返回后台</a>
+<a style="border-top:0" class="cola tc" href="/">返回后台</a>
+
+<form action="/vps/search" class="search">\
+<input autocomplete="off" type="text" id="search" name="q" placeholder="IP / 编号 / 用户邮箱" value="${q or ''}">\
+<input type="submit" value="" class="search_btn">\
+</form>
+
+
 <a class="cola tc" href="/vps">信息汇总</a>
 
 <p class="coltitle">订单</p>

htm/god/vps/_util.htm

 
 </%def>
 
+<%def name="vps_one_edit_render(vps)">
+<%
+user = vps.user
+%>
+<div class="vps_one">
+<div>
+<a href="${user.link}" target="_blank">${user.name}</a>
+%if vps.txt:
+ : ${vps.txt}
+%endif
+</div>
+${_mail_by_namcard_and_reg(user.id)}
+<div>VPS ${vps.id}</div>
+<div>CPU ${vps.cpu}</div>
+${vps_one_render(vps)}
+<div>外网 : ${" / ".join(vps.ip_list)}</div>
+<div>内网 : ${vps.ip_inter_str}</div>
+<div>
+<a href="/vps/one/edit/${vps.id}">TODO 编辑</a>
+</div>
+</div>
+</%def>
 
 <%def name="_mail_by_namcard_and_reg(user_id)">
 <%

htm/god/vps/one_state.htm

 <%inherit file="_base.htm" />
-<%namespace file="_util.htm" import="vps_one_render, _mail_by_namcard_and_reg"/>
+<%namespace file="_util.htm" import="vps_one_edit_render"/>
 <%!
 %>
 
 %for vps in ol:
-<%
-user = vps.user
-%>
-<div class="vps_one">
-<div>
-<a href="${user.link}" target="_blank">${user.name}</a>
-%if vps.txt:
- : ${vps.txt}
-%endif
-</div>
-${_mail_by_namcard_and_reg(user.id)}
-<div>VPS ${vps.id}</div>
-<div>CPU ${vps.cpu}</div>
-${vps_one_render(vps)}
-<div>外网 : ${" / ".join(vps.ip_list)}</div>
-<div>内网 : ${vps.ip_inter_str}</div>
-<div>
-<a href="/vps/one/edit/${vps.id}">TODO 编辑</a>
-</div>
-</div>
+${vps_one_edit_render(vps)}
 %endfor
 
 ${page|str,n}

htm/god/vps/vps_search.htm

+<%inherit file="_base.htm" />
+<%namespace file="_util.htm" import="vps_one_edit_render"/>
+
+
+
+
+%if q:
+    %if vps_list:
+%for vps in vps_list:
+${vps_one_edit_render(vps)}
+%endfor
+
+    %else:
+<div class="tc" style="border:1px dotted #ccc;margin-top:27px;padding:14px">\
+${q} 查无结果\
+</div>
+    %endif
+%endif
Add a comment to this file

misc/thrift/DoubanService/doubanservice/__init__.py

Empty file added.

misc/thrift/DoubanService/doubanservice/templates/__init__.py

+import os
+from subprocess import call
+import re
+
+from paste.script.templates import Template, var
+import mako.template
+
+_bad_chars_re = re.compile('[^a-zA-Z0-9_]')
+
+def render_mako(content, vars, filename=None):
+    return mako.template.Template(text=content, filename=filename) \
+            .render(**vars)
+
+class MyTemplate(Template):
+    template_renderer = staticmethod(render_mako)
+
+class DoubanServiceTemplate(MyTemplate):
+    _template_dir = 'doubanservice'
+    summary = "A DoubanService project"
+    vars = [
+        var('port', "Port the server listen to, register at http://goo.gl/eGndq", "9090"),
+    ]
+
+    def pre(self, command, output_dir, vars):
+        vars['service'] = _bad_chars_re.sub('',
+                            vars['project'].lower().replace('-', '_'))
+
+    def post(self, command, output_dir, vars):
+        for filename in ['gen', 'create-server', 'create-client']:
+            os.chmod(os.path.join(output_dir, filename), 0755)
+
+
+class ServerPyTemplate(MyTemplate):
+    _template_dir = 'server-py'
+    summary = "DoubanService Python Server"
+    vars = [
+        var('service', "Service name"),
+        var('port', "Port the server listen to, register at http://goo.gl/eGndq", "9090"),
+    ]
+
+    def pre(self, command, output_dir, vars):
+        vars['package'] = _bad_chars_re.sub('', vars['service'].lower()) + "_server"
+
+    def post(self, command, output_dir, vars):
+        for filename in ['gen', 'remote', 'serve']:
+            os.chmod(os.path.join(output_dir, filename), 0755)
+
+
+class ClientPyTemplate(MyTemplate):
+    _template_dir = 'client-py'
+    summary = "DoubanService Python Client"
+    vars = [
+        var('service', "Service name"),
+        var('port', "Port the server listen to, register at http://goo.gl/eGndq", "9090"),
+    ]
+
+    def pre(self, command, output_dir, vars):
+        vars['package'] = _bad_chars_re.sub('', vars['service'].lower()) + '_client'
+
+    def post(self, command, output_dir, vars):
+        for filename in ['gen']:
+            os.chmod(os.path.join(output_dir, filename), 0755)
+
+
+class DeployTemplate(MyTemplate):
+    _template_dir = 'deploy'
+    summary = "DoubanService Deploy Configurations"
+    vars = [
+        var('service', "Service name"),
+    ]
+
+    def post(self, command, output_dir, vars):
+        for dirpath, dirnames, filenames in os.walk(output_dir):
+            for filename in filenames:
+                if filename.endswith('.ebuild'):
+                    call(['ebuild',
+                          os.path.join(dirpath, filename),
+                          'manifest'])

misc/thrift/DoubanService/doubanservice/templates/client-py/+package+/__init__.py_tmpl

+from .client import Client, ${service.lower()}
+from .gen import ttypes as _ttypes, constants as _constants
+from .gen.ttypes import *
+from .gen.constants import *
+
+__all__ = ['Client', '${service}'] + \
+	  [name for name in dir(_ttypes) + dir(_constants)
+           if not name.startswith('_')]
+
+del _ttypes, _constants

misc/thrift/DoubanService/doubanservice/templates/client-py/+package+/client.py_tmpl

+import logging
+
+from doubanservice.client import BaseClient, ClientMetaClass
+
+from .gen import ${service} as ${service}_genmod
+
+logger = logging.getLogger('${service}.client')
+
+class Client(BaseClient):
+    __metaclass__ = ClientMetaClass
+    service_name = '${service}'
+    thrift_module = ${service}_genmod
+    port = ${port}
+
+    # The following parameters are customizable
+
+    # Connection timeout, in seconds
+    #connect_timeout = 1
+
+    # Read timeout, in seconds
+    #read_timeout = 5
+
+    # Additional timeout on a per-method basis, in seconds.
+    # Use method names as keys.
+    #read_timeout_overrides = {}
+
+    # How many seconds to wait before trying to reconnect to a dead server.
+    #fail_timeout = 10
+
+    # How many times to retry a request.  Caution: This may cause multiple
+    # submission.
+    #retries = 0
+
+    # How many times to retry a request on a per-method basis.
+    # Use method names as keys.
+    #retry_overrides = {}
+
+    # How many requests to perform before moving on to the next server in the
+    # pool, regardless of error status. Defaults to `None` (no limit).
+    #server_max_requests = None
+
+    # Specify the value to return when all servers are dead, on a per-method
+    # basis.
+    # Use method names as keys.
+    #defaults = {}
+
+
+
+${service.lower()} = Client()

misc/thrift/DoubanService/doubanservice/templates/client-py/gen_tmpl

+#!/bin/sh
+
+doubanservice-gen "${service}" py "../${service}.thrift" "${package}/gen/"

misc/thrift/DoubanService/doubanservice/templates/client-py/setup.py_tmpl

+from setuptools import setup, find_packages
+import sys, os
+
+version = "0.1"
+
+setup(name='${project}',
+      version=version,
+      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=[
+          "DoubanService"
+      ],
+      entry_points="""
+      """,
+      tests_require=['nose', 'mock'],
+      test_suite='nose.collector',
+)

misc/thrift/DoubanService/doubanservice/templates/deploy/portage/douban-service/+service+-client-py/+service+-client-py-9999.ebuild_tmpl

+# Copyright 1999-2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+DSERVICE_NAME="${service}"
+
+inherit douban-service-client-py

misc/thrift/DoubanService/doubanservice/templates/deploy/portage/douban-service/+service+-server-py/+service+-server-py-9999.ebuild_tmpl

+# Copyright 1999-2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+DSERVICE_NAME="${service}"
+
+inherit douban-service-server-py

misc/thrift/DoubanService/doubanservice/templates/doubanservice/+service+.thrift_tmpl

+include "doubanservice.thrift"
+
+service ${service} extends doubanservice.common {
+	// Your interface here.
+	// eg.
+	//   i32 add(1:i32 a, 2:i32 b);
+	// ref: http://wiki.apache.org/thrift/Tutorial
+}

misc/thrift/DoubanService/doubanservice/templates/doubanservice/create-client_tmpl

+#!/bin/sh
+
+lang=$1
+
+doubanservice-create-client-$lang --port=${port} ${service}

misc/thrift/DoubanService/doubanservice/templates/doubanservice/create-server_tmpl

+#!/bin/sh
+
+lang=$1
+
+doubanservice-create-server-$lang --port=${port} ${service}

misc/thrift/DoubanService/doubanservice/templates/doubanservice/gen_tmpl

+#!/bin/sh
+
+PROJ="${package}"
+
+here=`dirname $0`
+cd $here
+
+die() {
+    echo $1
+    exit 1
+}
+
+for d in *-*; do
+        if [ -x $d/gen ]; then
+                echo "generate for $d..."
+		curdir="`pwd`"
+                cd $d
+                ./gen
+		cd "$curdir"
+        fi
+done

misc/thrift/DoubanService/doubanservice/templates/server-py/+package+/__init__.py

+__version__ = '0.1'

misc/thrift/DoubanService/doubanservice/templates/server-py/+package+/app.py_tmpl

+# encoding: UTF-8
+
+import logging
+
+from doubanservice.common.handler import Handler as CommonHandler
+
+from . import __version__
+from . import types
+from .gen.${service} import Iface
+
+logger = logging.getLogger('${service}')
+
+class Handler(CommonHandler, Iface):
+    def __init__(self, **conf):
+        CommonHandler.__init__(self)
+        self.conf = conf
+
+    def version(self):
+        return __version__
+
+    def selftest(self):
+        """ Do some self-test.
+
+        This function should return None if no error detected.  If there is
+        error, return a string or raise an exception to describe it.
+
+        """
+
+    # Add your implementation below.  You can copy the interface code from 
+    # .gen.${service}.Iface
+
+
+## vim:set ft=python:

misc/thrift/DoubanService/doubanservice/templates/server-py/+package+/makeapp.py_tmpl

+import doubanservice.server
+
+from .gen.${service} import Iface, Processor
+from .app import Handler
+
+Processor.process = doubanservice.server.process
+
+def make_app(global_config, **local_conf):
+    handler = Handler(**local_conf)
+    processor = Processor(handler)
+    return processor

misc/thrift/DoubanService/doubanservice/templates/server-py/+package+/types.py_tmpl

+from .gen.ttypes import *

misc/thrift/DoubanService/doubanservice/templates/server-py/development.ini_tmpl

+[server:main]
+# Choose a server
+use = egg:DoubanService#process_pool
+#use = egg:DoubanService#thread_pool
+
+# Server listen port
+port = ${port}
+
+# Default value of pool_size:
+#   process_pool: the number of cpu
+#   thread_pool:  10
+#pool_size = 10
+
+# Report request count slower than specified milliseconds in stats():
+# e.g.
+#   latency_thresholds = 10, 100, 1000
+# will report request count slower than 10ms, 100ms and 1s respectively.
+latency_thresholds = 10, 100
+
+[app:main]
+use = egg:${project}
+
+
+# Logging configuration
+[loggers]
+keys = root, access_log
+
+[handlers]
+keys = console, access_log
+
+[formatters]
+keys = generic, access_log
+
+[logger_root]
+level = NOTSET
+handlers = console
+
+[logger_access_log]
+level = INFO
+handlers = access_log
+qualname = access_log
+propagate = 0
+
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+
+[handler_access_log]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = access_log
+
+[formatter_generic]
+format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
+datefmt = %H:%M:%S
+
+[formatter_access_log]
+format = %(asctime)s %(message)s
+datefmt = %Y-%m-%d %H:%M:%S

misc/thrift/DoubanService/doubanservice/templates/server-py/gen_tmpl

+#!/bin/sh
+
+doubanservice-gen "${service}" py "../${service}.thrift" "${package}/gen/"

misc/thrift/DoubanService/doubanservice/templates/server-py/production.ini_tmpl

+[server:main]
+# Available servers:
+#   use = egg:DoubanService#process_pool
+#   use = egg:DoubanService#thread_pool
+use = egg:DoubanService#process_pool
+port = ${port}
+# Default value of pool_size:
+#   process_pool: the number of cpu
+#   thread_pool:  10
+#pool_size = 10
+
+[app:main]
+use = egg:${project}
+
+
+# Logging configuration
+[loggers]
+keys = root, access_log
+
+[handlers]
+keys = console, access_log
+
+[formatters]
+keys = generic, access_log
+
+[logger_root]
+level = WARN
+handlers = console
+
+[logger_access_log]
+level = INFO
+handlers = access_log
+qualname = access_log
+propagate = 0
+
+[handler_console]
+class = FileHandler
+args = ('/log/services/${service}/error.log', )
+level = NOTSET
+formatter = generic
+
+[handler_access_log]
+class = FileHandler
+args = ('/log/services/${service}/access.log', )
+level = NOTSET
+formatter = access_log
+
+[formatter_generic]
+format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
+datefmt = %Y-%m-%d %H:%M:%S
+
+[formatter_access_log]
+format = %(asctime)s %(message)s
+datefmt = %Y-%m-%d %H:%M:%S

misc/thrift/DoubanService/doubanservice/templates/server-py/remote_tmpl

+#!/bin/sh
+
+doubanservice-remote --thrift-remote="${package}/gen/${service}-remote" --port=${port} "$@"

misc/thrift/DoubanService/doubanservice/templates/server-py/scripts/+service+-server-py

+#!/bin/sh
+
+exec paster serve "$@"

misc/thrift/DoubanService/doubanservice/templates/server-py/serve

+#!/bin/sh
+
+paster serve --reload --monitor-restart development.ini

misc/thrift/DoubanService/doubanservice/templates/server-py/setup.cfg

+[egg_info]
+tag_build = dev
+tag_svn_revision = true

misc/thrift/DoubanService/doubanservice/templates/server-py/setup.py_tmpl

+from setuptools import setup, find_packages
+
+from ${package} import __version__
+
+setup(name='${project}',
+      version=__version__,
+      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=[
+          "DoubanService",
+      ],
+      paster_plugins=['DoubanService'],
+      entry_points="""
+      [paste.app_factory]
+      main = ${package}.makeapp:make_app
+      """,
+      scripts=['scripts/${service}-server-py'],
+      tests_require=['nose'],
+      test_suite='nose.collector',
+)
+
+## vim:set ft=python:

misc/thrift/DoubanService/setup.py

+
+from setuptools import setup, find_packages
+from Cython.Distutils import build_ext
+
+setup(
+    name='doubanservice',
+    packages=find_packages(),
+    include_package_data=True,
+    zip_safe=False,
+    author_email='',
+    version='0.001',
+    description='doubanservice',
+    entry_points = """
+[paste.server_runner]
+thread_pool = doubanservice.server:thread_pool_server_runner
+
+[paste.paster_create_template]
+doubanservice = doubanservice.templates:DoubanServiceTemplate 
+doubanservice_server_py = doubanservice.templates:ServerPyTemplate 
+doubanservice_client_py = doubanservice.templates:ClientPyTemplate 
+
+    """
+)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.