Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
agent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
7
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f4e07a75
authored
Nov 07, 2018
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix flake8 warnings
parent
16b8fc3a
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
36 additions
and
25 deletions
+36
-25
agent-winservice.py
+2
-1
agent.py
+12
-10
linux/_linuxcontext.py
+8
-5
linux/ssh.py
+3
-2
notify.py
+6
-3
watchdog-winservice.py
+2
-1
windows/_win32context.py
+1
-1
windows/network.py
+1
-1
windows/win32virtio.py
+1
-1
No files found.
agent-winservice.py
View file @
f4e07a75
...
@@ -61,10 +61,11 @@ def main():
...
@@ -61,10 +61,11 @@ def main():
else
:
else
:
win32serviceutil
.
HandleCommandLine
(
AppServerSvc
)
win32serviceutil
.
HandleCommandLine
(
AppServerSvc
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
try
:
try
:
main
()
main
()
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
raise
raise
except
:
except
Exception
:
logger
.
exception
(
"Exception:"
)
logger
.
exception
(
"Exception:"
)
agent.py
View file @
f4e07a75
...
@@ -6,14 +6,15 @@ import platform
...
@@ -6,14 +6,15 @@ import platform
import
subprocess
import
subprocess
import
sys
import
sys
system
=
platform
.
system
()
if
system
==
"Linux"
:
system
=
platform
.
system
()
# noqa
try
:
# noqa
chdir
(
sys
.
path
[
0
])
if
system
==
"Linux"
:
# noqa
subprocess
.
call
((
'pip'
,
'install'
,
'-r'
,
'requirements.txt'
))
try
:
# noqa
except
:
chdir
(
sys
.
path
[
0
])
# noqa
pass
# hope it works
subprocess
.
call
((
'pip'
,
'install'
,
'-r'
,
'requirements.txt'
))
# noqa
except
Exception
:
# noqa
pass
# hope it works # noqa
from
twisted.internet
import
reactor
,
defer
from
twisted.internet
import
reactor
,
defer
...
@@ -35,6 +36,7 @@ Context = get_context()
...
@@ -35,6 +36,7 @@ Context = get_context()
logging
.
basicConfig
()
logging
.
basicConfig
()
logger
=
logging
.
getLogger
()
logger
=
logging
.
getLogger
()
level
=
environ
.
get
(
'LOGLEVEL'
,
'INFO'
)
level
=
environ
.
get
(
'LOGLEVEL'
,
'INFO'
)
logger
.
setLevel
(
level
)
logger
.
setLevel
(
level
)
...
@@ -65,7 +67,7 @@ class SerialLineReceiver(SerialLineReceiverBase):
...
@@ -65,7 +67,7 @@ class SerialLineReceiver(SerialLineReceiverBase):
logger
.
debug
(
"Sending tick"
)
logger
.
debug
(
"Sending tick"
)
try
:
try
:
self
.
send_status
()
self
.
send_status
()
except
:
except
Exception
:
logger
.
exception
(
"Twisted hide exception"
)
logger
.
exception
(
"Twisted hide exception"
)
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -135,7 +137,7 @@ class SerialLineReceiver(SerialLineReceiverBase):
...
@@ -135,7 +137,7 @@ class SerialLineReceiver(SerialLineReceiverBase):
if
argspec
.
keywords
:
if
argspec
.
keywords
:
args
.
append
(
"**"
+
argspec
.
keywords
)
args
.
append
(
"**"
+
argspec
.
keywords
)
return
"
%
s(
%
s)"
%
(
fun
.
__name__
,
","
.
join
(
args
))
return
"
%
s(
%
s)"
%
(
fun
.
__name__
,
","
.
join
(
args
))
except
:
except
Exception
:
return
"<
%
s>"
%
type
(
fun
)
.
__name__
return
"<
%
s>"
%
type
(
fun
)
.
__name__
def
handle_command
(
self
,
command
,
args
):
def
handle_command
(
self
,
command
,
args
):
...
@@ -158,7 +160,7 @@ def main():
...
@@ -158,7 +160,7 @@ def main():
try
:
try
:
from
notify
import
register_publisher
from
notify
import
register_publisher
register_publisher
(
reactor
)
register_publisher
(
reactor
)
except
:
except
Exception
:
logger
.
exception
(
"Could not register notify publisher"
)
logger
.
exception
(
"Could not register notify publisher"
)
logger
.
debug
(
"Starting reactor."
)
logger
.
debug
(
"Starting reactor."
)
reactor
.
run
()
reactor
.
run
()
...
...
linux/_linuxcontext.py
View file @
f4e07a75
...
@@ -8,7 +8,9 @@ from shutil import rmtree, move
...
@@ -8,7 +8,9 @@ from shutil import rmtree, move
import
subprocess
import
subprocess
import
sys
import
sys
working_directory
=
sys
.
path
[
0
]
working_directory
=
sys
.
path
[
0
]
# noqa
import
logging
import
logging
import
fileinput
import
fileinput
...
@@ -26,6 +28,7 @@ from context import BaseContext
...
@@ -26,6 +28,7 @@ from context import BaseContext
from
twisted.internet
import
reactor
from
twisted.internet
import
reactor
logger
=
logging
.
getLogger
()
logger
=
logging
.
getLogger
()
SSH_DIR
=
expanduser
(
'~cloud/.ssh'
)
SSH_DIR
=
expanduser
(
'~cloud/.ssh'
)
...
@@ -96,7 +99,7 @@ class Context(BaseContext):
...
@@ -96,7 +99,7 @@ class Context(BaseContext):
Context
.
_linux_set_time
(
float
(
time
))
Context
.
_linux_set_time
(
float
(
time
))
try
:
try
:
subprocess
.
call
([
'/etc/init.d/ntp'
,
'restart'
])
subprocess
.
call
([
'/etc/init.d/ntp'
,
'restart'
])
except
:
except
Exception
:
pass
pass
@staticmethod
@staticmethod
...
@@ -142,7 +145,7 @@ class Context(BaseContext):
...
@@ -142,7 +145,7 @@ class Context(BaseContext):
for
line
in
f
.
readlines
():
for
line
in
f
.
readlines
():
try
:
try
:
retval
.
append
(
PubKey
.
from_str
(
line
))
retval
.
append
(
PubKey
.
from_str
(
line
))
except
:
except
Exception
:
logger
.
exception
(
u'Invalid ssh key: '
)
logger
.
exception
(
u'Invalid ssh key: '
)
except
IOError
:
except
IOError
:
pass
pass
...
@@ -170,7 +173,7 @@ class Context(BaseContext):
...
@@ -170,7 +173,7 @@ class Context(BaseContext):
p
=
PubKey
.
from_str
(
key
)
p
=
PubKey
.
from_str
(
key
)
if
p
not
in
new_keys
:
if
p
not
in
new_keys
:
new_keys
.
append
(
p
)
new_keys
.
append
(
p
)
except
:
except
Exception
:
logger
.
exception
(
u'Invalid ssh key: '
)
logger
.
exception
(
u'Invalid ssh key: '
)
Context
.
_save_keys
(
new_keys
)
Context
.
_save_keys
(
new_keys
)
...
@@ -184,7 +187,7 @@ class Context(BaseContext):
...
@@ -184,7 +187,7 @@ class Context(BaseContext):
new_keys
.
remove
(
p
)
new_keys
.
remove
(
p
)
except
ValueError
:
except
ValueError
:
pass
pass
except
:
except
Exception
:
logger
.
exception
(
u'Invalid ssh key: '
)
logger
.
exception
(
u'Invalid ssh key: '
)
Context
.
_save_keys
(
new_keys
)
Context
.
_save_keys
(
new_keys
)
...
...
linux/ssh.py
View file @
f4e07a75
from
base64
import
decodestring
from
base64
import
decodestring
from
struct
import
unpack
from
struct
import
unpack
import
binascii
import
binascii
import
unittest
class
InvalidKeyType
(
Exception
):
class
InvalidKeyType
(
Exception
):
...
@@ -56,8 +57,7 @@ class PubKey(object):
...
@@ -56,8 +57,7 @@ class PubKey(object):
return
u'<PubKey:
%
s>'
%
unicode
(
self
)
return
u'<PubKey:
%
s>'
%
unicode
(
self
)
import
unittest
# Unit tests
class
SshTestCase
(
unittest
.
TestCase
):
class
SshTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -102,5 +102,6 @@ class SshTestCase(unittest.TestCase):
...
@@ -102,5 +102,6 @@ class SshTestCase(unittest.TestCase):
s
.
add
(
self
.
p3
)
s
.
add
(
self
.
p3
)
self
.
assertEqual
(
len
(
s
),
2
)
self
.
assertEqual
(
len
(
s
),
2
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
notify.py
View file @
f4e07a75
...
@@ -120,7 +120,7 @@ def notify(url):
...
@@ -120,7 +120,7 @@ def notify(url):
logger
.
debug
(
"wall sent, trying to start browser"
)
logger
.
debug
(
"wall sent, trying to start browser"
)
p
=
multiprocessing
.
Process
(
target
=
open_in_browser
,
args
=
(
url
,
))
p
=
multiprocessing
.
Process
(
target
=
open_in_browser
,
args
=
(
url
,
))
p
.
start
()
p
.
start
()
except
:
except
Exception
:
logger
.
exception
(
"Couldn't notify about
%
s"
%
url
)
logger
.
exception
(
"Couldn't notify about
%
s"
%
url
)
...
@@ -152,7 +152,7 @@ def mount_smb(url):
...
@@ -152,7 +152,7 @@ def mount_smb(url):
stderr
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stdin
=
subprocess
.
PIPE
)
stdin
=
subprocess
.
PIPE
)
logger
.
info
(
'mount_smb():
%
s'
,
p
.
communicate
())
logger
.
info
(
'mount_smb():
%
s'
,
p
.
communicate
())
except
:
except
Exception
:
logger
.
exception
(
'Unhandled exception: '
)
logger
.
exception
(
'Unhandled exception: '
)
...
@@ -191,10 +191,11 @@ def search_display():
...
@@ -191,10 +191,11 @@ def search_display():
if
"DISPLAY"
in
envs
and
":"
in
envs
[
"DISPLAY"
]:
if
"DISPLAY"
in
envs
and
":"
in
envs
[
"DISPLAY"
]:
p
=
os
.
stat
(
os
.
path
.
join
(
"/proc"
,
pid
))
p
=
os
.
stat
(
os
.
path
.
join
(
"/proc"
,
pid
))
return
envs
[
"DISPLAY"
],
p
.
st_uid
,
p
.
st_gid
return
envs
[
"DISPLAY"
],
p
.
st_uid
,
p
.
st_gid
except
:
except
Exception
:
continue
continue
return
None
return
None
if
win
:
if
win
:
from
twisted.internet
import
protocol
from
twisted.internet
import
protocol
from
twisted.protocols
import
basic
from
twisted.protocols
import
basic
...
@@ -256,5 +257,7 @@ def main():
...
@@ -256,5 +257,7 @@ def main():
args
=
parse_arguments
()
args
=
parse_arguments
()
notify
(
args
.
url
)
notify
(
args
.
url
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
main
()
main
()
watchdog-winservice.py
View file @
f4e07a75
...
@@ -80,10 +80,11 @@ def main():
...
@@ -80,10 +80,11 @@ def main():
else
:
else
:
win32serviceutil
.
HandleCommandLine
(
AppServerSvc
)
win32serviceutil
.
HandleCommandLine
(
AppServerSvc
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
try
:
try
:
main
()
main
()
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
raise
raise
except
:
except
Exception
:
logger
.
exception
(
"Exception:"
)
logger
.
exception
(
"Exception:"
)
windows/_win32context.py
View file @
f4e07a75
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
working_directory
=
r"C:\circle"
working_directory
=
r"C:\circle"
# noqa
from
os.path
import
join
from
os.path
import
join
...
...
windows/network.py
View file @
f4e07a75
...
@@ -29,7 +29,7 @@ def check_output2(cmd, shell=False):
...
@@ -29,7 +29,7 @@ def check_output2(cmd, shell=False):
stdout
,
stderr
=
p
.
communicate
()
stdout
,
stderr
=
p
.
communicate
()
logger
.
info
(
'
%
s:
%
s,
%
s'
,
cmd
,
stdout
,
stderr
)
logger
.
info
(
'
%
s:
%
s,
%
s'
,
cmd
,
stdout
,
stderr
)
return
stdout
return
stdout
except
:
except
Exception
:
logger
.
exception
(
logger
.
exception
(
'Unhandled exception in
%
s: '
,
cmd
)
'Unhandled exception in
%
s: '
,
cmd
)
...
...
windows/win32virtio.py
View file @
f4e07a75
...
@@ -78,7 +78,7 @@ class SerialPort(abstract.FileDescriptor):
...
@@ -78,7 +78,7 @@ class SerialPort(abstract.FileDescriptor):
self
.
hComPort
,
self
.
hComPort
,
self
.
_overlappedRead
,
self
.
_overlappedRead
,
0
)
0
)
except
:
except
Exception
:
import
time
import
time
time
.
sleep
(
10
)
time
.
sleep
(
10
)
n
=
0
n
=
0
...
...
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