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
Rafael Monnerat
slapos.package
Commits
f1fe241b
Commit
f1fe241b
authored
Jun 26, 2015
by
Kristopher Ruzic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
just messing with the uploading...
not useable yet, but I need this online
parent
ae1b435d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
23 deletions
+27
-23
playbook/roles/test-suite/files/log-uploader
playbook/roles/test-suite/files/log-uploader
+27
-23
No files found.
playbook/roles/test-suite/files/log-uploader
View file @
f1fe241b
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
import
sys
import
sys
import
time
import
time
import
requests
from
watchdog.observers
import
Observer
from
watchdog.observers
import
Observer
from
watchdog.events
import
FileSystemEventHandler
from
watchdog.events
import
FileSystemEventHandler
...
@@ -15,38 +16,41 @@ class MyHandler(FileSystemEventHandler):
...
@@ -15,38 +16,41 @@ class MyHandler(FileSystemEventHandler):
f
=
open
(
"tmp/tmpupload"
,
'w'
)
f
=
open
(
"tmp/tmpupload"
,
'w'
)
f
.
write
(
fmt_date
()
+
": partition completed"
)
f
.
write
(
fmt_date
()
+
": partition completed"
)
f
.
close
()
f
.
close
()
upload_file
(
event
.
file
,
open
(
"tmp/tmpupload"
,
'rb'
)
upload_file
(
event
.
file
,
open
(
"tmp/tmpupload"
,
'rb'
))
else
:
return
def
fmt_date
():
def
fmt_date
():
return
time
.
strftime
(
"[ %Y%m%d %H:%M:%S ]"
)
return
time
.
strftime
(
"[ %Y%m%d %H:%M:%S ]"
)
def
dir_date
():
return
time
.
strftime
(
"%Y%m%d/"
)
class
uploader
():
class
uploader
():
system_name
=
"first-machine"
# possibly generate later?
url
=
'http://[2001:67c:1254:e:a9::bafb]:9000/post'
url
=
'https://[2001:67c:1254:e:a9::bafb]:???/post'
# takes a file handler and a name (where it should be saved on server)
# takes a file name and contents to append. Generates server file_path (where it should be saved on server)
def
upload_file
(
file_name
,
contents
):
def
upload_file
(
self
,
file_name
,
contents
):
files
=
{
'file'
:
f
}
values
=
{
'file_path'
:
dir_date
()
+
file_name
,
'contents'
:
contents
}
values
=
{
'file_path'
:
system_name
+
file_name
}
r
=
requests
.
post
(
self
.
url
,
data
=
values
)
r
=
requests
.
post
(
url
,
files
=
files
,
data
=
values
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
event_handler
=
MyHandler
()
c
=
uploader
()
observer
=
Observer
()
c
.
upload_file
(
"blah"
,
"new test content"
)
observer
.
schedule
(
event_handler
,
path
=
'/opt/slapos/log'
,
recursive
=
False
)
observer
.
start
()
# event_handler = MyHandler()
# observer = Observer()
# observer.schedule(event_handler, path='/opt/slapos/log', recursive=False)
# observer.start()
# check if .completed exists or not, and write it to the server log
# check if .completed exists or not, and write it to the server log
observer
.
schedule
(
event_handler
,
path
=
'/opt/slapgrid/'
,
recursive
=
True
,
patterns
=
".completed"
)
# """ observer.schedule(event_handler, path='/opt/slapgrid/', recursive=True)
observer
.
start
()
# observer.start()
try
:
# try:
while
True
:
# while True:
time
.
sleep
(
1
)
# time.sleep(1)
except
KeyboardInterrupt
:
# except KeyboardInterrupt:
observer
.
stop
()
# observer.stop()
observer
.
join
()
# observer.join()
#"""
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