Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Working on deployment.

  • Loading branch information...
commit fdd87d5f3f64684f127c5953b39dd7e9aa7e36b8 1 parent b67aa1e
@svetlyak40wt authored
View
26 configs/etc/nginx/sites-enabled/cony.svetlyak.ru.development
@@ -0,0 +1,26 @@
+upstream dev_cony_server {
+ server 127.0.0.1:10001 fail_timeout=0;
+}
+
+server {
+ listen 8000;
+ server_name dev.cony.svetlyak.ru;
+ access_log /home/art/log/nginx/dev.cony.svetlyak.ru.log;
+
+ # path for static files
+ root /vagrant/cony;
+
+ location / {
+ # checks for static file, if not found proxy to app
+ try_files $uri @proxy_to_app;
+ }
+
+ location @proxy_to_app {
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header Host $http_host;
+ proxy_redirect off;
+
+ proxy_pass http://dev_cony_server;
+ }
+}
+
View
7 configs/home/art/etc/supervisor.d/cony.svetlyak.ru.conf.production
@@ -0,0 +1,7 @@
+[program:cony.svetlyak.ru]
+user = art
+command = /home/art/projects/cony/env/bin/gunicorn -b 127.0.0.1:40001 cony:wsgi
+autorestart = true
+redirect_stderr = true
+stdout_logfile = /home/ubuntu/log/supervisord/cony.svetlyak.ru.log
+
View
2  cony/__init__.py
@@ -19,7 +19,7 @@
DEBUG = True
# Stand-alone server running as a daemon on port 8080
SERVER_MODE = 'STANDALONE' # or 'WSGI', or 'CGI'
-SERVER_PORT = 8080
+SERVER_PORT = 10001
SERVER_HOST = 'localhost' # or '' to allow on all interfaces
HELP_TERMS = ('--help', '?', '-?')
View
15 cony/repo/lang.py
@@ -2,12 +2,15 @@
import datetime
import os.path
import urllib
+from requests.sessions import Session
from bottle import redirect
+from cony.utils import force_str
from xml.etree import ElementTree as ET
xhtml = '{http://www.w3.org/1999/xhtml}'
+
def cmd_translate(term):
"""Translates the text using Google Translate."""
if len(term) < len(term.encode('utf-8')):
@@ -80,11 +83,13 @@ def cmd_search_word(term):
variants = {}
+ internet = Session()
+
for i in reversed(range((len(term) + 1) / 2, len(term) + 1)):
url = 'http://suggest-slovari.yandex.ru/suggest-lingvo?v=2&lang=en&' + \
urllib.urlencode(dict(part=term[:i].encode('utf-8')))
- data = urllib.urlopen(url).read()
- data = simplejson.loads(data)
+ response = internet.get(url)
+ data = simplejson.loads(response.content)
if data[0]:
for trans, link in zip(*data[1:]):
@@ -95,10 +100,10 @@ def cmd_search_word(term):
def get_spelling(value):
- url = 'http://lingvo.yandex.ru/' + value['en'].replace(' ', '%20') + '/%D1%81%20%D0%B0%D0%BD%D0%B3%D0%BB%D0%B8%D0%B9%D1%81%D0%BA%D0%BE%D0%B3%D0%BE/'
- data = urllib.urlopen(url).read()
+ url = 'http://lingvo.yandex.ru/' + force_str(value['en']).replace(' ', '%20') + '/%D1%81%20%D0%B0%D0%BD%D0%B3%D0%BB%D0%B8%D0%B9%D1%81%D0%BA%D0%BE%D0%B3%D0%BE/'
+ data = internet.get(url).content
- xml = ET.fromstring(data)
+ xml = ET.fromstring(force_str(data))
transcript = xml.find('*//{x}span[@class="b-translate__tr"]'.format(x=xhtml))
if transcript is None:
View
6 cony/repo/search.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+import urllib
import urllib2
from bottle import redirect
from cony.utils import rich_help, HELP_TERMS
@@ -111,6 +112,7 @@ def cmd_wikipedia(term):
elif term[0] == '/' and len(term) == 3:
redirect('http://%s.wikipedia.org/' % term[1:])
else:
- redirect('http://www.wikipedia.org/w/index.php?search=%s'
- % term.replace(' ', '+'))
+ #redirect('http://www.wikipedia.org/w/index.php?' + query)
+ url = 'http://www.wikipedia.org/w/index.php?' + urllib.urlencode(dict(search=term.encode('utf-8')))
+ redirect(url)
View
4 cony/utils.py
@@ -32,3 +32,7 @@ def decorator(handler):
return decorator
+def force_str(value, enc='utf-8'):
+ if isinstance(value, unicode):
+ return value.encode(enc)
+ return value
View
53 fabfile.py
@@ -0,0 +1,53 @@
+from fabricant import *
+
+#env.project = 'cony.svetlyak.ru'
+
+def dev():
+ env.hosts = ['localhost']
+ env.environment = 'development'
+ env.project_dir = '/vagrant/cony'
+
+
+def production():
+ env.hosts = ['people']
+ env.environment = 'production'
+ env.project_dir = '/home/art/projects/cony'
+ env.repository = 'git@github.com:svetlyak40wt/cony.git'
+
+
+def _pull_sources():
+ if env.environment == 'production':
+
+ base_dir, relative_project_dir = os.path.split(env.project_dir)
+ with cd(base_dir):
+ if dir_exists(relative_project_dir):
+ with cd(relative_project_dir):
+ run('git pull')
+ else:
+ run('git clone %s %s' % (env.repository, relative_project_dir))
+
+
+def _create_env():
+ with cd(env.project_dir):
+ if not dir_exists('env'):
+ run('virtualenv env')
+ run('env/bin/pip install -r requirements/%s.txt' % env.environment)
+
+
+def deploy():
+ package_ensure([
+ 'nginx',
+ ])
+ dir_ensure('/home/art/log/backend')
+ dir_ensure('/home/art/log/nginx')
+
+ _pull_source()
+ _create_env()
+ make_symlinks()
+
+ upstart_ensure('nginx')
+
+
+def runserver():
+ local('./cony-server')
+
View
1  requirements/development.txt
@@ -0,0 +1 @@
+-r production.txt
View
3  requirements/production.txt
@@ -0,0 +1,3 @@
+requests
+simplejson
+gunicorn
View
3  wsgi.py
@@ -0,0 +1,3 @@
+from cony import wsgi
+
+app = wsgi()
Please sign in to comment.
Something went wrong with that request. Please try again.