Skip to content

Commit 043f444

Browse files
committed
upload to pypi
1 parent f8ea686 commit 043f444

14 files changed

+355
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
__pycache__
22
*.pyc
3+
build/
4+
dist/

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include README.rst

examples/ef_services.py

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import ef
2+
import sys
3+
import time
4+
import math
5+
import random
6+
import threading
7+
import itertools
8+
9+
username, password, channel, sleep_s_str, name_csv = sys.argv[1:]
10+
sleep_s = int(sleep_s_str)
11+
names = [name.strip() for name in name_csv.split(",")]
12+
13+
print "starting with", username, password, channel, names
14+
c = ef.Client("http://localhost:8080/ef/api/", username, password)
15+
16+
print(c.login())
17+
18+
def now():
19+
return int(time.time() * 1000)
20+
21+
START = "start"
22+
STARTED = "started"
23+
ERROR = "error"
24+
ABORTED = "aborted"
25+
FINISHED = "finished"
26+
27+
STATES = {
28+
START: [STARTED],
29+
STARTED: [ERROR, ABORTED, FINISHED],
30+
ERROR: [START],
31+
ABORTED: [START],
32+
FINISHED: [START]
33+
}
34+
35+
MAX_SLEEP_BY_STATE = {
36+
START: int(sleep_s / 3.0) + 1,
37+
STARTED: sleep_s,
38+
ERROR: sleep_s,
39+
ABORTED: sleep_s,
40+
FINISHED: sleep_s
41+
}
42+
43+
ERROR_REASONS = [
44+
"request cannot be fulfilled due to bad syntax",
45+
"authentication is possible but has failed",
46+
"payment required, reserved for future use",
47+
"server refuses to respond to request",
48+
"requested resource could not be found",
49+
"request method not supported by that resource",
50+
"content not acceptable according to the Accept headers",
51+
"client must first authenticate itself with the proxy",
52+
"server timed out waiting for the request",
53+
"request could not be processed because of conflict",
54+
"resource is no longer available and will not be available again",
55+
"request did not specify the length of its content",
56+
"server does not meet request preconditions",
57+
"request is larger than the server is willing or able to process",
58+
"URI provided was too long for the server to process",
59+
"server does not support media type",
60+
"client has asked for unprovidable portion of the file",
61+
"server cannot meet requirements of Expect request-header field",
62+
"request unable to be followed due to semantic errors",
63+
"resource that is being accessed is locked",
64+
"request failed due to failure of a previous request",
65+
"client should switch to a different protocol",
66+
"origin server requires the request to be conditional",
67+
"user has sent too many requests in a given amount of time",
68+
"server is unwilling to process the request",
69+
"server returns no information and closes the connection",
70+
"request should be retried after performing action",
71+
"Windows Parental Controls blocking access to webpage",
72+
"The server cannot reach the client's mailbox.",
73+
"connection closed by client while HTTP server is processing",
74+
"server does not recognise method or lacks ability to fulfill",
75+
"server received an invalid response from upstream server",
76+
"server is currently unavailable",
77+
"gateway did not receive response from upstream server",
78+
"server does not support the HTTP protocol version",
79+
"content negotiation for the request results in a circular reference",
80+
"server is unable to store the representation",
81+
"server detected an infinite loop while processing the request",
82+
"bandwidth limit exceeded",
83+
"further extensions to the request are required",
84+
"client needs to authenticate to gain network access",
85+
"network read timeout behind the proxy",
86+
"network connect timeout behind the proxy"]
87+
88+
89+
class ServiceRunner(threading.Thread):
90+
def __init__(self, name):
91+
threading.Thread.__init__(self)
92+
self.name = name
93+
self.state = START
94+
self.started = None
95+
self.setDaemon(True)
96+
97+
def run(self):
98+
while True:
99+
next_state = random.choice(STATES[self.state])
100+
sleep_time = random.randint(1, MAX_SLEEP_BY_STATE[self.state])
101+
print "sleeping", sleep_time, "seconds"
102+
time.sleep(sleep_time)
103+
104+
value = {
105+
"name": self.name,
106+
"state": self.state,
107+
"started": self.started
108+
}
109+
110+
if self.state == ERROR:
111+
value["reason"] = random.choice(ERROR_REASONS)
112+
elif self.state == START:
113+
self.started = now()
114+
115+
if self.state in (ERROR, ABORTED, FINISHED):
116+
value["ended"] = now()
117+
118+
event = ef.Event(value, channel, username)
119+
120+
if self.state != START:
121+
print c.send_event(event)
122+
123+
self.state = next_state
124+
125+
if __name__ == "__main__":
126+
for name in names:
127+
service_runner = ServiceRunner(name)
128+
service_runner.start()
129+
130+
while True:
131+
try:
132+
time.sleep(1)
133+
except KeyboardInterrupt:
134+
print "closing"
135+
break

examples/sendjson.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""example using eventfabric api client library to send an arbitrary json
2+
file as an event"""
3+
from __future__ import print_function
4+
5+
import sys
6+
import json
7+
8+
import eventfabric as ef
9+
10+
def main():
11+
username, password, channel, path = sys.argv[1:]
12+
13+
print("Config:", username, channel, path, api_root)
14+
15+
c = ef.Client(username, password, "http://localhost:8080/ef/api/")
16+
17+
print("Login:", c.login())
18+
value = json.load(open(path))
19+
event = ef.Event(value, channel, username)
20+
print("Send Event:", c.send_event(event))
21+
22+
if __name__ == "__main__":
23+
main()

notes.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
PyPi Notes
2+
==========
3+
4+
To Register
5+
-----------
6+
7+
python setup.py register
8+
9+
To build and upload to pypi
10+
---------------------------
11+
12+
python setup.py sdist upload
13+

setup.py

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'''setup.py for eventfabric'''
2+
try:
3+
from setuptools import setup
4+
except ImportError:
5+
from distutils.core import setup
6+
7+
8+
try:
9+
with open('README.rest') as f:
10+
README = f.read()
11+
except IOError:
12+
README = None
13+
14+
setup(
15+
name='eventfabric',
16+
version='0.1.0',
17+
py_modules=['eventfabric'],
18+
package_dir={'': 'src'},
19+
data_files=[
20+
('', ['README.rest'])
21+
],
22+
zip_safe=False,
23+
description='Event Fabric API client library',
24+
long_description=README,
25+
license='MIT License',
26+
author='Mariano Guerra',
27+
author_email='mariano' '@' 'marianoguerra.org',
28+
url='https://github.com/EventFabric/python-api',
29+
install_requires=['requests'],
30+
classifiers=[
31+
'Development Status :: 4 - Beta',
32+
'Environment :: Console',
33+
'Environment :: MacOS X',
34+
'Environment :: No Input/Output (Daemon)',
35+
'Environment :: Other Environment',
36+
'Environment :: Win32 (MS Windows)',
37+
'Intended Audience :: Developers',
38+
'Intended Audience :: Information Technology',
39+
'Intended Audience :: System Administrators',
40+
'License :: OSI Approved :: MIT License',
41+
'Operating System :: MacOS :: MacOS X',
42+
'Operating System :: Microsoft',
43+
'Operating System :: Microsoft :: Windows',
44+
'Operating System :: OS Independent',
45+
'Operating System :: Other OS',
46+
'Operating System :: POSIX',
47+
'Operating System :: POSIX :: BSD',
48+
'Operating System :: POSIX :: Linux',
49+
'Operating System :: POSIX :: Other',
50+
'Operating System :: POSIX :: SunOS/Solaris',
51+
'Operating System :: Unix',
52+
'Programming Language :: Python',
53+
'Programming Language :: Python :: 2',
54+
'Programming Language :: Python :: 3',
55+
'Topic :: Communications',
56+
'Topic :: Internet',
57+
'Topic :: Internet :: Log Analysis',
58+
'Topic :: Internet :: WWW/HTTP',
59+
'Topic :: Software Development',
60+
'Topic :: Software Development :: Libraries',
61+
'Topic :: Software Development :: Libraries :: Python Modules',
62+
'Topic :: System :: Monitoring',
63+
'Topic :: System :: Networking',
64+
'Topic :: System :: Networking :: Monitoring'
65+
]
66+
)

src/eventfabric.egg-info/PKG-INFO

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
Metadata-Version: 1.1
2+
Name: eventfabric
3+
Version: 0.1.0
4+
Summary: Event Fabric API client library
5+
Home-page: https://github.com/EventFabric/python-api
6+
Author: Mariano Guerra
7+
Author-email: [email protected]
8+
License: MIT License
9+
Description: Event Fabric API Client
10+
=======================
11+
12+
Python 2 and 3 implementation of Event Fabric API to send events.
13+
14+
Setup
15+
-----
16+
17+
The library dependes on the `Requests <http://docs.python-requests.org/en/latest/>`_ HTTP library, install it with::
18+
19+
pip install requests
20+
21+
Usage
22+
-----
23+
24+
see the examples folder for more usage examples
25+
26+
::
27+
28+
# import the library
29+
>>> import eventfabric as ef
30+
31+
# create a client instance specifying username and password
32+
>>> client = ef.Client("username", "password")
33+
34+
# authenticate, should return True and 200, if not there was an error
35+
>>> client.login()
36+
(True, <Response [200]>)
37+
38+
# create an event instance
39+
40+
# the first parameter is a free form JSON
41+
# value that contains information about the event
42+
43+
# the second is the name of the channel where that event will go to
44+
45+
# the channel is used to subscribe to a stream of events with the same
46+
# channel id
47+
>>> event1 = ef.Event({"name": "Bob", "count": 10}, "my.channel")
48+
49+
# send the event, it should return True and 201, if not there was an error,
50+
# make sure to check for authentication errors on long running agents to
51+
# reauthenticate in case your credentials expire
52+
>>> client.send_event(event1)
53+
(True, <Response [201]>)
54+
55+
Test
56+
----
57+
58+
::
59+
60+
python tests/eventfabric_tests.py
61+
62+
License
63+
-------
64+
65+
MIT
66+
67+
Platform: UNKNOWN
68+
Classifier: Development Status :: 4 - Beta
69+
Classifier: Environment :: Console
70+
Classifier: Environment :: MacOS X
71+
Classifier: Environment :: No Input/Output (Daemon)
72+
Classifier: Environment :: Other Environment
73+
Classifier: Environment :: Win32 (MS Windows)
74+
Classifier: Intended Audience :: Developers
75+
Classifier: Intended Audience :: Information Technology
76+
Classifier: Intended Audience :: System Administrators
77+
Classifier: License :: OSI Approved :: MIT License
78+
Classifier: Operating System :: MacOS :: MacOS X
79+
Classifier: Operating System :: Microsoft
80+
Classifier: Operating System :: Microsoft :: Windows
81+
Classifier: Operating System :: OS Independent
82+
Classifier: Operating System :: Other OS
83+
Classifier: Operating System :: POSIX
84+
Classifier: Operating System :: POSIX :: BSD
85+
Classifier: Operating System :: POSIX :: Linux
86+
Classifier: Operating System :: POSIX :: Other
87+
Classifier: Operating System :: POSIX :: SunOS/Solaris
88+
Classifier: Operating System :: Unix
89+
Classifier: Programming Language :: Python
90+
Classifier: Programming Language :: Python :: 2
91+
Classifier: Programming Language :: Python :: 3
92+
Classifier: Topic :: Communications
93+
Classifier: Topic :: Internet
94+
Classifier: Topic :: Internet :: Log Analysis
95+
Classifier: Topic :: Internet :: WWW/HTTP
96+
Classifier: Topic :: Software Development
97+
Classifier: Topic :: Software Development :: Libraries
98+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
99+
Classifier: Topic :: System :: Monitoring
100+
Classifier: Topic :: System :: Networking
101+
Classifier: Topic :: System :: Networking :: Monitoring

src/eventfabric.egg-info/SOURCES.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MANIFEST.in
2+
setup.py
3+
src/eventfabric.py
4+
src/eventfabric.egg-info/PKG-INFO
5+
src/eventfabric.egg-info/SOURCES.txt
6+
src/eventfabric.egg-info/dependency_links.txt
7+
src/eventfabric.egg-info/not-zip-safe
8+
src/eventfabric.egg-info/requires.txt
9+
src/eventfabric.egg-info/top_level.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/eventfabric.egg-info/not-zip-safe

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/eventfabric.egg-info/requires.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
eventfabric

eventfabric.py src/eventfabric.py

File renamed without changes.

tests/eventfabric_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import unittest
66

77
TEST_DIR = os.path.dirname(__file__)
8-
BASE_DIR = os.path.join(TEST_DIR, '..')
8+
BASE_DIR = os.path.join(TEST_DIR, '..', 'src')
99
sys.path.append(BASE_DIR)
1010

1111
import eventfabric as ef

0 commit comments

Comments
 (0)