Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.package
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Klaus Wölfel
slapos.package
Commits
f55f0ffe
Commit
f55f0ffe
authored
Jun 14, 2013
by
Jondy Zhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use TioXML format for netdrive usage report
parent
c62f29f3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
46 deletions
+64
-46
windows/netreport/setup.py
windows/netreport/setup.py
+14
-16
windows/netreport/src/netreport.py
windows/netreport/src/netreport.py
+50
-30
No files found.
windows/netreport/setup.py
View file @
f55f0ffe
...
...
@@ -3,10 +3,7 @@
import
sys
import
os
try
:
from
setuptools
import
setup
,
Extension
except
ImportError
:
from
distutils.core
import
setup
,
Extension
from
setuptools
import
setup
,
Extension
def
get_description
():
README
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'README'
))
...
...
@@ -16,7 +13,7 @@ def get_description():
finally
:
f
.
close
()
VERSION
=
"0.1.
1
"
VERSION
=
"0.1.
2
"
if
sys
.
platform
.
startswith
(
"cygwin"
):
...
...
@@ -41,30 +38,31 @@ else:
def
main
():
setup_args
=
dict
(
name
=
'netdrive
.report
'
,
name
=
'netdrive'
,
version
=
VERSION
,
download_url
=
'http://'
,
description
=
'A tool used to report the usage of net drive in the Windows'
,
long_description
=
get_description
(),
keywords
=
[
'netdrive'
,],
scripts
=
[
'src/netreport.py
'
],
py_modules
=
[
'src/netreport
'
],
author
=
'Nexedi'
,
author_email
=
'jondy.zhao@nexedi.com'
,
maintainer
=
'Jondy Zhao'
,
maintainer_email
=
'jondy.zhao@nexedi.com'
,
url
=
'http://'
,
license
=
'GPLv3'
,
zip_safe
=
False
,
install_requires
=
[
'lxml'
,
'slapos.core'
,
'slapos.core'
,
'setuptools'
,
'zc.buildout'
,
# plays with buildout
'zc.recipe.egg'
,
# for scripts generation
],
entry_points
=
{
'console_scripts'
:
[
'netdrive-reporter = netreport:main'
,
],
}
)
entry_points
=
{
'console_scripts'
:
[
'netdrive-reporter = netreport:main'
,
],
}
)
if
extensions
is
not
None
:
setup_args
[
"ext_modules"
]
=
extensions
setup
(
**
setup_args
)
...
...
windows/netreport/src/netreport.py
View file @
f55f0ffe
...
...
@@ -52,7 +52,10 @@ def parseArgumentTuple():
default
=
"/etc/slapos/ssl/computer.key"
)
parser
.
add_argument
(
"--report-interval"
,
help
=
"Interval in seconds to send report to master."
,
default
=
300
)
default
=
300.0
)
parser
.
add_argument
(
"--report-path"
,
help
=
"Where to save TioXML report."
,
default
=
300.0
)
parser
.
add_argument
(
"--data-file"
,
help
=
"File used to save report data."
,
default
=
"net_drive_usage_report.data"
)
...
...
@@ -80,6 +83,7 @@ class NetDriveUsageReporter(object):
self
.
_domain_account
=
None
self
.
_config_id
=
None
self
.
_report_date
=
None
self
.
report_interval
=
float
(
self
.
report_interval
)
self
.
initializeDatabase
(
self
.
data_file
)
def
initializeConnection
(
self
):
...
...
@@ -163,12 +167,16 @@ class NetDriveUsageReporter(object):
self
.
_db
.
execute
(
"UPDATE config SET report_date=? where _rowid_=?"
,
(
today
,
self
.
_config_id
))
def
_postData
(
self
,
xml_data
):
def
_postData
(
self
,
report
):
"""Send a marshalled dictionary of the net drive usage record
serialized via_getDict.
"""
if
xml_data
is
not
None
:
self
.
_slap_computer
.
reportNetDriveUsage
(
xml_data
)
if
report
is
not
None
:
name
=
"netdrive-report-%s.xml"
%
datetime
.
now
().
isoformat
()
etree
.
ElementTree
(
report
).
write
(
os
.
path
.
join
(
self
.
report_path
,
name
),
xml_declaration
=
True
)
def
initializeDatabase
(
self
,
db_path
):
self
.
_db
=
sqlite3
.
connect
(
db_path
,
isolation_level
=
None
)
...
...
@@ -198,32 +206,45 @@ class NetDriveUsageReporter(object):
def
generateDailyReport
(
self
,
config_id
,
computer_id
,
domain_account
,
report_date
,
remove
=
True
):
q
=
self
.
_db
.
execute
root
=
etree
.
Element
(
"report"
)
element
=
etree
.
Element
(
"computer"
)
element
.
text
=
computer_id
root
.
append
(
element
)
element
=
etree
.
Element
(
"account"
)
element
.
text
=
domain_account
root
.
append
(
element
)
element
=
etree
.
Element
(
"date"
)
element
.
text
=
report_date
root
.
append
(
element
)
element
=
etree
.
Element
(
"usage"
)
root
.
append
(
element
)
usage
=
element
element
=
etree
.
Element
(
"details"
)
root
.
append
(
element
)
total
=
0
for
r
in
q
(
"SELECT duration, usage_bytes FROM net_drive_usage "
report
=
etree
.
Element
(
"consumption"
)
for
r
in
q
(
"SELECT remote_folder, duration, usage_bytes FROM net_drive_usage "
"WHERE config_id=? AND strftime('%Y-%m-%d', start)=?"
,
(
config_id
,
report_date
)):
total
+=
r
[
0
]
*
r
[
1
]
usage
.
text
=
str
(
total
)
movement
=
etree
.
Element
(
'movement'
)
element
=
etree
.
Element
(
"resource"
)
element
.
text
=
r
[
0
]
movement
.
append
(
element
)
element
=
etree
.
Element
(
"title"
)
element
.
text
=
'NetDrive Usage %s'
%
report_date
movement
.
append
(
element
)
element
=
etree
.
Element
(
"reference"
)
element
.
text
=
domain_account
movement
.
append
(
element
)
element
=
etree
.
Element
(
"reference"
)
element
.
text
=
report_date
movement
.
append
(
element
)
element
=
etree
.
Element
(
"quantity"
)
element
.
text
=
str
(
r
[
1
]
*
r
[
2
])
movement
.
append
(
element
)
element
=
etree
.
Element
(
"price"
)
element
.
text
=
'0.0'
movement
.
append
(
element
)
element
=
etree
.
Element
(
"VAT"
)
movement
.
append
(
element
)
element
=
etree
.
Element
(
"category"
)
element
.
text
=
"NetDrive"
movement
.
append
(
element
)
report
.
append
(
movement
)
if
remove
:
q
(
"INSERT INTO net_drive_usage_history "
"SELECT * FROM net_drive_usage "
...
...
@@ -232,8 +253,7 @@ class NetDriveUsageReporter(object):
q
(
"DELETE FROM net_drive_usage "
"WHERE config_id=? AND strftime('%Y-%m-%d', start)=?"
,
(
config_id
,
report_date
))
if
total
:
return
etree
.
tostring
(
root
,
encoding
=
'utf-8'
,
xml_declaration
=
True
)
return
report
def
main
():
reporter
=
NetDriveUsageReporter
(
parseArgumentTuple
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment