Skip to content

Commit 581fe24

Browse files
committed
First
0 parents  commit 581fe24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+5030
-0
lines changed

.gitignore

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
*.py[cod]
2+
3+
# C extensions
4+
*.so
5+
6+
# Packages
7+
*.egg
8+
*.egg-info
9+
dist
10+
build
11+
eggs
12+
parts
13+
bin
14+
var
15+
sdist
16+
develop-eggs
17+
.installed.cfg
18+
lib
19+
lib64
20+
21+
# Installer logs
22+
pip-log.txt
23+
24+
# Unit test / coverage reports
25+
.coverage
26+
.tox
27+
nosetests.xml
28+
29+
#Translations
30+
*.mo
31+
32+
#Mr Developer
33+
.mr.developer.cfg
34+
35+
gg.pid
36+
37+
#emacs poop
38+
*~
39+
40+
#pip poop
41+
src
42+
config
43+
44+
testcache/*

README.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Retrieve jobs queued by ruby in python, and perform the requested parsing work.
2+
3+
Installation
4+
===============
5+
6+
**TODO** - give commands to set up an acceptable directory structure, with config containing what is needed
7+
8+
Install the various requirements. PIL may require external libraries to be installed.
9+
10+
> $ pip install -r requirements.txt
11+
12+
Set up database configuration
13+
14+
**TODO** - describe how config/database.yml must be symlinked to the containing (esdb) directory.
15+
**TODO** - give steps to set up AWS for testing
16+
17+
18+
Set up your environment variables
19+
20+
* `GGFACTORY_CACHE_DIR` (required): Sets a directory to cache remote files used to load SC2 resources. Use full path.
21+
* `DJANGO_SECRETKEY` (required): Sets the SECRETKEY in the django settings.py file.
22+
23+
Run the tests to verify a successful setup:
24+
25+
> GGFACTORY_CACHE_DIR=testcache ./manage.py test sc2parse
26+
27+
Run specific tests like this:
28+
> GGFACTORY_CACHE_DIR=testcache ./manage.py test sc2parse.SC2ReaderToEsdbTestCase.test_close_replays
29+
30+
31+
Keeping up to Date
32+
=====================
33+
34+
When you pull down changes to the `requirements.txt` file:
35+
36+
> $ pip install --upgrade -r requirements.txt
37+
38+
39+
40+
Working on sc2reader
41+
========================
42+
43+
Development work on sc2reader requires a manual uninstall of the
44+
sc2reader version installed by the requirements file followed by
45+
an installation from a local copy of the ggtracker/sc2reader repo.
46+
47+
> $ pip uninstall sc2reader
48+
> $ cd path/to/ggtracker/sc2reader
49+
> $ python setup.py develop
50+
51+
When installed in develop mode sc2reader will automatically reflect
52+
changes to the code base it was installed from. Please note that
53+
a worker running as a daemon will *not* automatically reflect changes
54+
to the code made since the process began running. The worker must be
55+
shut down and restarted to pick up the code changes.
56+
57+
Git
58+
===
59+
Miserable.

__init__.py

Whitespace-only changes.

daemon.py

+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
'''
2+
***
3+
Modified generic daemon class
4+
***
5+
6+
Author: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
7+
www.boxedice.com
8+
9+
License: http://creativecommons.org/licenses/by-sa/3.0/
10+
11+
Changes: 23rd Jan 2009 (David Mytton <[email protected]>)
12+
- Replaced hard coded '/dev/null in __init__ with os.devnull
13+
- Added OS check to conditionally remove code that doesn't work on OS X
14+
- Added output to console on completion
15+
- Tidied up formatting
16+
11th Mar 2009 (David Mytton <[email protected]>)
17+
- Fixed problem with daemon exiting on Python 2.4 (before SystemExit was part of the Exception base)
18+
13th Aug 2010 (David Mytton <[email protected]>
19+
- Fixed unhandled exception if PID file is empty
20+
'''
21+
22+
# Core modules
23+
import atexit
24+
import os
25+
import sys
26+
import time
27+
import signal
28+
import errno
29+
30+
class Daemon(object):
31+
"""
32+
A generic daemon class.
33+
34+
Usage: subclass the Daemon class and override the run() method
35+
"""
36+
def __init__(self, pidfile, stdin=os.devnull, stdout=os.devnull, stderr=os.devnull, home_dir='.', umask=022, verbose=1):
37+
self.stdin = stdin
38+
self.stdout = stdout
39+
self.stderr = stderr
40+
self.pidfile = pidfile
41+
self.home_dir = home_dir
42+
self.verbose = verbose
43+
self.umask = umask
44+
self.daemon_alive = True
45+
46+
def daemonize(self):
47+
"""
48+
Do the UNIX double-fork magic, see Stevens' "Advanced
49+
Programming in the UNIX Environment" for details (ISBN 0201563177)
50+
http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
51+
"""
52+
try:
53+
pid = os.fork()
54+
if pid > 0:
55+
# Exit first parent
56+
sys.exit(0)
57+
except OSError, e:
58+
sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror))
59+
sys.exit(1)
60+
61+
# Decouple from parent environment
62+
os.chdir(self.home_dir)
63+
os.setsid()
64+
os.umask(self.umask)
65+
66+
# Do second fork
67+
try:
68+
pid = os.fork()
69+
if pid > 0:
70+
# Exit from second parent
71+
sys.exit(0)
72+
except OSError, e:
73+
sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror))
74+
sys.exit(1)
75+
76+
if sys.platform != 'darwin': # This block breaks on OS X
77+
# Redirect standard file descriptors
78+
sys.stdout.flush()
79+
sys.stderr.flush()
80+
si = file(self.stdin, 'r')
81+
so = file(self.stdout, 'a+')
82+
if self.stderr:
83+
se = file(self.stderr, 'a+', 0)
84+
else:
85+
se = so
86+
os.dup2(si.fileno(), sys.stdin.fileno())
87+
os.dup2(so.fileno(), sys.stdout.fileno())
88+
os.dup2(se.fileno(), sys.stderr.fileno())
89+
90+
def sigtermhandler(signum, frame):
91+
self.daemon_alive = False
92+
signal.signal(signal.SIGTERM, sigtermhandler)
93+
signal.signal(signal.SIGINT, sigtermhandler)
94+
95+
if self.verbose >= 1:
96+
print "Started"
97+
98+
# Write pidfile
99+
atexit.register(self.delpid) # Make sure pid file is removed if we quit
100+
pid = str(os.getpid())
101+
file(self.pidfile,'w+').write("%s\n" % pid)
102+
103+
def delpid(self):
104+
os.remove(self.pidfile)
105+
106+
def start(self, *args, **kwargs):
107+
"""
108+
Start the daemon
109+
"""
110+
111+
if self.verbose >= 1:
112+
print "Starting..."
113+
114+
# Check for a pidfile to see if the daemon already runs
115+
try:
116+
pf = file(self.pidfile,'r')
117+
pid = int(pf.read().strip())
118+
pf.close()
119+
except IOError:
120+
pid = None
121+
except SystemExit:
122+
pid = None
123+
124+
if pid:
125+
message = "pidfile %s already exists. Is the daemon already running?\n"
126+
sys.stderr.write(message % self.pidfile)
127+
128+
# Remove stale pid files
129+
try:
130+
os.kill(pid, 0)
131+
except OSError, why:
132+
if why[0] == errno.ESRCH:
133+
print('Removing stale pidfile %s' % self.pidfile)
134+
os.remove(self.pidfile)
135+
else:
136+
sys.exit("Can't check status of PID %s from pidfile %s: %s" %
137+
(pid, self.pidfile, why[1]))
138+
else:
139+
sys.exit("daemon is already running with PID %s\n" % pid)
140+
141+
# Start the daemon
142+
self.daemonize()
143+
self.run(*args, **kwargs)
144+
145+
def stop(self):
146+
"""
147+
Stop the daemon
148+
"""
149+
150+
if self.verbose >= 1:
151+
print "Stopping..."
152+
153+
# Get the pid from the pidfile
154+
try:
155+
pf = file(self.pidfile,'r')
156+
pid = int(pf.read().strip())
157+
pf.close()
158+
except IOError:
159+
pid = None
160+
except ValueError:
161+
pid = None
162+
163+
if not pid:
164+
message = "pidfile %s does not exist. Not running?\n"
165+
sys.stderr.write(message % self.pidfile)
166+
167+
# Just to be sure. A ValueError might occur if the PID file is empty but does actually exist
168+
if os.path.exists(self.pidfile):
169+
os.remove(self.pidfile)
170+
171+
return # Not an error in a restart
172+
173+
# Try killing the daemon process
174+
try:
175+
while 1:
176+
177+
# Note: kill -SIGTERM will work, doing it from python will not.
178+
# I don't feel like finding out why right now. FIXME
179+
180+
os.kill(pid, signal.SIGKILL)
181+
time.sleep(0.1)
182+
except OSError, err:
183+
err = str(err)
184+
if err.find("No such process") > 0:
185+
if os.path.exists(self.pidfile):
186+
os.remove(self.pidfile)
187+
else:
188+
print str(err)
189+
sys.exit(1)
190+
191+
if self.verbose >= 1:
192+
print "Stopped"
193+
194+
def restart(self):
195+
"""
196+
Restart the daemon
197+
"""
198+
self.stop()
199+
self.start()
200+
201+
def run(self):
202+
"""
203+
You should override this method when you subclass Daemon. It will be called after the process has been
204+
daemonized by start() or restart().
205+
"""
206+

engagement.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import sys
2+
import sc2reader
3+
from sc2parse import ggfactory
4+
5+
# usage GGFACTORY_CACHE_DIR=testcache python engagement.py <ggtracker match id>
6+
7+
replay = ggfactory.load_replay("http://ggtracker.com/matches/{}/replay".format(sys.argv[1]))

ggpyjobs_scan

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
NOT OK
2+
-rw-r--r-- 1 david staff 6392 Jun 16 2013 settings.py <--- AWS
3+
4+
FIXED
5+
-rw-r--r-- 1 david staff 1335 Jun 16 2013 ggtracker/__init__.py <--- exceptional api key
6+
7+
OK
8+
-rw-r--r-- 1 david staff 43 Jun 16 2013 .git
9+
-rw-r--r-- 1 david staff 336 Jun 16 2013 .gitignore
10+
-rw-r--r-- 1 david staff 1543 Dec 13 2013 README.md
11+
-rw-r--r-- 1 david staff 0 Jun 16 2013 __init__.py
12+
drwxr-xr-x 3 david staff 102 Jul 30 2013 config
13+
-rw-r--r-- 1 david staff 5581 Jun 16 2013 daemon.py
14+
-rw-r--r-- 1 david staff 234 Jun 16 2013 engagement.py
15+
-rw-r--r-- 1 david staff 12359 Jun 16 2013 etracker_fun.txt
16+
drwxr-xr-x 4 david staff 136 Jul 10 20:07 exceptional
17+
-rwxr-xr-x 1 david staff 503 Jun 16 2013 manage.py
18+
-rw-r--r-- 1 david staff 2342 Jun 16 2013 plugin_debug.py
19+
-rw-r--r-- 1 david staff 1251 Dec 13 2013 profile.py
20+
-rw-r--r-- 1 david staff 636 Jun 23 13:39 requirements.txt
21+
-rw-r--r-- 1 david staff 384 Jun 16 2013 resque_test.py
22+
-rw-r--r-- 1 david staff 137 Jun 16 2013 settings_dev.py
23+
-rwxr-xr-x 1 david staff 1966 Dec 13 2013 worker.py
24+
drwxr-xr-x 6 david staff 204 Jun 28 17:20 src
25+
drwxr-xr-x 10 david staff 340 Jun 28 17:20 testcache
26+
-rw-r--r-- 1 david staff 7149 Jun 18 15:01 jobs.py
27+
drwxr-xr-x 8 david staff 272 Jul 10 20:07 ggtracker
28+
-rw-r--r-- 1 david staff 2713 Jun 22 08:42 utils.py
29+
-rw-r--r-- 1 david staff 3127 Jun 21 19:53 ggfactory.py
30+
-rw-r--r-- 1 david staff 10972 Dec 13 2013 models.py
31+
-rw-r--r-- 1 david staff 70493 Jun 23 13:40 plugins.py
32+
-rw-r--r-- 1 david staff 52966 Jul 2 16:50 sc2reader_to_esdb.py
33+
-rw-r--r-- 1 david staff 226 Jun 16 2013 views.py
34+
-rw-r--r-- 1 david staff 33213 Dec 13 2013 tests.py
35+
drwxr-xr-x 15 david staff 510 Jul 10 20:07 sc2parse
36+
drwxr-xr-x 37 david staff 1258 Dec 13 2013 testfiles

ggtracker/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)