Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed 3 issues (Sourcery refactored) #39

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions gnu-linux/install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh -e
#!/bin/sh
#
# Installation script for Pombo.
#
Expand All @@ -11,15 +11,19 @@ fi
inst_dir=/usr/local/bin
[ -d ${inst_dir} ] || inst_dir=/usr/local/sbin

src_dir=""
[ -f pombo.py ] || src_dir="../"
script=$(readlink -f "$0")
# Absolute path install.sh script is in
src_dir=$(dirname "$script")
# Absolute path of Pombo main dir (without trailing /)
src_dir=$(dirname "$src_dir")


echo "\nInstalling (verbose) ..."
[ -f /etc/pombo.conf ] && mv -fv /etc/pombo.conf /etc/pombo.conf.$(date '+%s')
install -v ${src_dir}pombo.conf /etc
install -v ${src_dir}/pombo.conf /etc
echo "« chmod 600 /etc/pombo.conf »"
chmod 600 /etc/pombo.conf
install -v ${src_dir}pombo.py ${inst_dir}/pombo
install -v ${src_dir}/pombo.py ${inst_dir}/pombo
echo "« chmod +x ${inst_dir}/pombo »"
chmod +x ${inst_dir}/pombo

Expand All @@ -43,12 +47,13 @@ echo "Done."

echo "\nChecking dependancies ..."
ok=1
for package in python gpg ifconfig iwlist traceroute streamer; do

for package in python gpg ifconfig iwlist traceroute streamer; do
test=$(which ${package})
[ $? != 0 ] && echo " ! ${package} needed but not installed." && ok=0
[ $? != 0 ] && echo " ! ${test}.... ${package} needed but not installed." && ok=0
done
python check-imports.py
[ $? != 0 ] && ok=0
echo "Shell script uses Python $(python --version)"
python ${src_dir}/tools/check-imports.py
case ${ok} in
1) echo "Done." ;;
*) echo "Please install necessary tools before continuing." ;;
Expand Down
2 changes: 1 addition & 1 deletion gnu-linux/uninstall.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh -e
#!/bin/sh
#
# Uninstallation script for Pombo.
#
Expand Down
2 changes: 2 additions & 0 deletions pombo.conf
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ screenshot=yes
; Take webcam shot?
; <filepath> will be replaced by a filename, do not customize (required).
; [W] yes or no
; [L] /usr/bin/streamer -q -t 1 -r 2 -o <filepath>
; [L] /usr/bin/streamer -q -t 1 -r 2 -j 100 -s 640x480 -o <filepath>
; [L] /usr/bin/streamer -q -w 3 -o <filepath>
; [L] /usr/bin/streamer -q -j 100 -w 3 -s 640x480 -o <filepath>
; [L] /usr/bin/gst-launch -q v4l2src num_buffers=1 decimate=70 ! pngenc ! filesink location=<filepath>
Expand Down
22 changes: 12 additions & 10 deletions pombo.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ def snapshot_sendto_server(self, filename, data):

# Send to the webserver (HTTP POST).
parameters = {"filename": filename, "filedata": filedata, "token": authtoken}
txt = "Sending file (%s) to %s"
for distant in self.configuration["server_url"].split("|"):
txt = "Sending file (%s) to %s"
Comment on lines +632 to -633
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Pombo.snapshot_sendto_server refactored with the following changes:

  • Hoist statements out of for/while loops

self.log.info(txt, sizeof_fmt(len(filedata)), urlsplit(distant).netloc)
self.request_url(distant, "post", parameters)

Expand Down Expand Up @@ -699,9 +699,9 @@ def snapshot(self, current_ip):
"-r",
self.configuration["gpgkeyid"],
"-o",
output,
"-e",
output + ".gpg",
"-e",
output,
]
)

Expand Down Expand Up @@ -842,13 +842,15 @@ def webcamshot(self, filename):
)
cmd = self.configuration["camshot"].replace("<filepath>", filepath)
self.runprocess(cmd, useshell=True)
if os.path.isfile(filepath):
if self.configuration["camshot_filetype"] == "ppm":
full_path_ = os.path.join(temp, filename)
new_path_ = "{}_webcam.jpg".format(full_path_)
self.runprocess(["/usr/bin/convert", filepath, new_path_])
os.unlink(filepath)
filepath = new_path_
if (
os.path.isfile(filepath)
and self.configuration["camshot_filetype"] == "ppm"
):
full_path_ = os.path.join(temp, filename)
new_path_ = "{}_webcam.jpg".format(full_path_)
self.runprocess(["/usr/bin/convert", filepath, new_path_])
os.unlink(filepath)
filepath = new_path_
Comment on lines -845 to +853
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Pombo.webcamshot refactored with the following changes:

  • Merge nested if conditions


if not os.path.isfile(filepath):
return None
Expand Down