Skip to content

Commit 5aaa430

Browse files
authored
Merge pull request #1 from FRReinert/dev
Dev
2 parents 9bc0a86 + ed4fa50 commit 5aaa430

12 files changed

Lines changed: 425 additions & 0 deletions

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>PySSRS</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.python.pydev.PyDevBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.python.pydev.pythonNature</nature>
16+
</natures>
17+
</projectDescription>

.pydevproject

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?eclipse-pydev version="1.0"?><pydev_project>
3+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
4+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
5+
</pydev_project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
eclipse.preferences.version=1
2+
encoding//SSRS/__init__.py=utf-8
3+
encoding//samples/FindItem.py=utf-8
4+
encoding//samples/GetParameters.py=utf-8
5+
encoding//samples/ListDir.py=utf-8
6+
encoding//samples/ListMethods.py=utf-8
7+
encoding//samples/__init__.py=utf-8
8+
encoding//samples/connection_data.py=utf-8
9+
encoding//samples/context.py=utf-8

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,80 @@
11
# PySSRS
22
Microsoft Reporting Services (SSRS) RPC trough SOAP
3+
4+
## Installation
5+
You just need to run ```pip install PySSRS```
6+
7+
### Connecting to SSRS
8+
You can use it as a facilitator to make SOAP RPCs.
9+
For example:
10+
```python
11+
12+
From SSRS import SSRS
13+
14+
RS = SSRS('localhost', 'user@domain.com', '@paswd2017')
15+
result = RS.client.service.ListChildren(dir, recursive)
16+
17+
for item in result.CatalogItem:
18+
print(item['Name'])
19+
```
20+
21+
### Available Functions
22+
We implemented some functions to make it easy to use. Feel free to check their usage on the **samples** folder.
23+
24+
These functions are available by now:
25+
26+
Function | Objective | Return Type
27+
--------------|--------------------------------|------------
28+
ListMethods() | List all SOAP procedures | List []
29+
DirItems() | List all objects in a directory | Dictionary {}
30+
Find() | Find for a item by it's name | Dictionary {}
31+
GetParameters() | Return all parameters from a Report object | Dictionary {}
32+
33+
### Snippet
34+
35+
Check this small code, it's an sample of usage
36+
37+
```python
38+
# Conneting to SSRS SOAP server
39+
40+
wsdl = 'http://localhost/ReportinServices/ReportService2010.asmx?wsdl'
41+
user = 'user@domain.com
42+
psw = '@password2017'
43+
44+
RS = SSRS(wsdl, user, psw)
45+
46+
'''
47+
Return a LIST with all available SOAP procedures
48+
so you can iterate over them...
49+
'''
50+
Methods = RS.ListMethods()
51+
52+
'''
53+
Return a DICTIONARY with all items in a specific folder
54+
you can also use the <recursive> parameter to scan subfolders.
55+
If you don't specify the <dir> parameter it'll take the root ('/') as default
56+
'''
57+
DirItems = RS.ListDirItems(dir='/MyReports', recursive=True)
58+
59+
'''
60+
Find() will retrieve a list of items which the name matches with the <text> parameter.
61+
It's recursive, you don't need to specify any folder and you can also specify the object type that you want
62+
by using the <objtype> parameter.
63+
64+
Those are the accepted types of objects
65+
-> Component
66+
-> DataSource
67+
-> Folder
68+
-> Model
69+
-> LinkedReport
70+
-> Report
71+
-> Resource
72+
-> DataSet
73+
-> Site
74+
-> Unknown
75+
'''
76+
ItemsFound = RS.Find(text="Sales", objtype="Report")
77+
78+
#GetParameters() will retrieve a list of paremeters for the report on the specific path
79+
Parameters = RS.GetParameters(path='/MyReports/SalesOrder')
80+
```

SSRS/__init__.py

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from suds.client import Client
4+
from suds.sax.text import Text
5+
from suds.transport.http import HttpAuthenticated
6+
import logging as log
7+
import sys
8+
9+
class SSRS():
10+
'''
11+
Create a SOAP connection to a SSRS (Microsoft Reporting Services)
12+
13+
Example of usage on SSRS 2008:
14+
RS = SSRS(host='http://localhost/ReportinServices/ReportService2010.asmx?wsdl', user:'user@domain.com', key_password='myfreakingpassword')
15+
16+
'''
17+
18+
def __init__(self, host='http://localhost/reportserver/ReportService2010.asmx?wsdl', user='SEPTODONT\admin', key_password='admin', verbose=True):
19+
20+
self.verbose = verbose
21+
credentials = dict(username=user, password=key_password)
22+
credentials = HttpAuthenticated(**credentials)
23+
log.basicConfig(filename='SSRS.log', level=log.INFO)
24+
25+
try:
26+
self.client = Client(host, transport=credentials)
27+
28+
except BaseException as e:
29+
30+
msg = "Could not connect to %s with user %s: %s" % (host, user, str(e))
31+
log.error(msg)
32+
33+
if self.verbose:
34+
print(msg)
35+
36+
exit()
37+
38+
39+
def ListMethods(self):
40+
'''
41+
Return the list of methods available for your SSRS version
42+
'''
43+
try:
44+
list_of_methods = [method for method in self.client.wsdl.services[0].ports[0].methods]
45+
return list_of_methods
46+
47+
except BaseException as e:
48+
49+
msg = "ListMethod() Could not retrieve the methods: %s" % (str(e))
50+
log.error(msg)
51+
52+
if self.verbose:
53+
print(msg)
54+
55+
return False
56+
57+
58+
def ListDirItems(self, dir=r'/', recursive=False):
59+
'''
60+
List all itens in a folder.
61+
if specified the <recursive> parameter, subfolders will be scanned too
62+
'''
63+
64+
try:
65+
it = self.client.service.ListChildren(dir, recursive)
66+
it = it.CatalogItem
67+
68+
except BaseException as e:
69+
msg = "ListDirItems() Could not retrieve the Objects: %s" % (str(e))
70+
log.error(msg)
71+
72+
if self.verbose:
73+
print(msg)
74+
75+
return False
76+
77+
catalog_dict = {}
78+
79+
for item in it:
80+
catalog_dict[item['ID']] = {
81+
'Name' : item['Name'],
82+
'Path' : item['Path'],
83+
'TypeName' : item['TypeName'],
84+
'CreationDate' : item['CreationDate'],
85+
'ModifiedDate' : item['ModifiedDate'],
86+
'CreatedBy' : item['CreatedBy'],
87+
'ModifiedBy' : item['ModifiedBy'],
88+
'ItemMetadata' : item['ItemMetadata'],
89+
}
90+
91+
return catalog_dict
92+
93+
94+
def Find(self, text, objtype=None):
95+
'''
96+
Find objects on SSRS
97+
'''
98+
99+
try:
100+
it = self.ListDirItems(recursive=True)
101+
if isinstance(it, Text):
102+
return dict(it)
103+
104+
105+
except BaseException as e:
106+
msg = "Find() Could not retrieve the Objects: %s" % (str(e))
107+
log.error(msg)
108+
109+
if self.verbose:
110+
print(msg)
111+
112+
return False
113+
114+
catalog_dict = {}
115+
for key, value in it.items() :
116+
for word in value.values():
117+
if text in str(word):
118+
if objtype == None:
119+
catalog_dict[key] = value
120+
121+
else:
122+
if it[key]['TypeName'] == objtype:
123+
catalog_dict[key] = value
124+
125+
return catalog_dict
126+
127+
128+
def GetParameters(self, path):
129+
'''
130+
Retrieve parameters from an SSRS Report
131+
'''
132+
133+
try:
134+
it = self.client.service.GetItemParameters(path, None, True, None, None)
135+
if isinstance(it, Text):
136+
return dict(it)
137+
138+
except BaseException as e:
139+
msg = "GetParameters() Could not retrieve the parameters: %s" % str(e)
140+
log.error(msg)
141+
142+
if self.verbose:
143+
print(msg)
144+
145+
return False
146+
147+
param_dict = {}
148+
for item in it.ItemParameter:
149+
param_dict[item['Name']] = {
150+
'ParameterTypeName' : item['ParameterTypeName'],
151+
'Nullable' : item['Nullable'],
152+
'AllowBlank' : item['AllowBlank'],
153+
'MultiValue' : item['MultiValue'],
154+
'QueryParameter' : item['QueryParameter'],
155+
'Prompt' : item['Prompt'],
156+
'PromptUser' : item['PromptUser'],
157+
'ValidValuesQueryBased' : item['ValidValuesQueryBased'],
158+
'DefaultValuesQueryBased' : item['DefaultValuesQueryBased'],
159+
}
160+
161+
return param_dict
162+
163+
164+
165+
166+

samples/FindItem.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import connection_data as d
5+
import context
6+
from SSRS import SSRS
7+
8+
RS = SSRS(d._host, d._user, d._psw)
9+
result = RS.Find(text='OP', objtype='Report')
10+
11+
if result:
12+
print(
13+
'''
14+
This method will search for any property value that matches with the parameter <text>
15+
It'll match if any property value of the object CONTAINS the <text> value
16+
17+
You can also specify the type of the object by using the <objtype> parameter as a string
18+
19+
Types accepted:
20+
-> Component
21+
-> DataSource
22+
-> Folder
23+
-> Model
24+
-> LinkedReport
25+
-> Report
26+
-> Resource
27+
-> DataSet
28+
-> Site
29+
-> Unknown
30+
31+
if you leave the <text> parameter blank it'll retrieve all objects (respecting the <objtype> parameter)
32+
'''
33+
)
34+
35+
for key, value in result.items() :
36+
print('ID:', key)
37+
38+
for key2, value2 in value.items():
39+
print(key2,':', value2)
40+
41+
print('\n')

samples/GetParameters.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import connection_data as d
5+
import context
6+
from SSRS import SSRS
7+
8+
RS = SSRS(d._host, d._user, d._psw)
9+
result = RS.GetParameters('/Qualidade/Indice de Conformidade')
10+
11+
print(
12+
'''
13+
Get Parameters linked to a specific report.
14+
15+
Available Parameters:
16+
ParameterTypeName
17+
Nullable
18+
AllowBlank
19+
MultiValue
20+
QueryParameter
21+
Prompt
22+
PromptUser
23+
ValidValuesQueryBased
24+
DefaultValuesQueryBased
25+
'''
26+
)
27+
28+
for key, value in result.items() :
29+
print('Name:', key)
30+
31+
for key2, value2 in value.items():
32+
print(key2,':', value2)
33+
34+
print('\n')

0 commit comments

Comments
 (0)