Skip to content

Commit

Permalink
iSpindel null and venv perms fix (#186)
Browse files Browse the repository at this point in the history
- d8a41b6 Add .local to exclusions
- 168cfa6 Add toolPath to config
- 7bb0589 Whitespace cleanup
- 3dd2d27 Remove trailing comma after null (#174)
- 03ca630 Add gitInfo.py for future use
- 4c93d3e Skip perms on venv (#185)
  • Loading branch information
lbussy committed Apr 24, 2021
1 parent 22906ca commit fe28738
Show file tree
Hide file tree
Showing 16 changed files with 198 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Home dir files
.local
.bash_logout
.bash_aliases
.bashrc
Expand Down
7 changes: 5 additions & 2 deletions BrewPiUtil.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python3

# Copyright (C) 2018, 2019 Lee C. Bussy (@LBussy)
# Copyright (C) 2018-2021 Lee C. Bussy (@LBussy)

# This file is part of LBussy's BrewPi Script Remix (BrewPi-Script-RMX).
#
Expand Down Expand Up @@ -96,6 +96,7 @@ def readCfgWithDefaults(configFile = None):
if error:
defCfg = ConfigObj()
defCfg.filename = defaultFile
defCfg['toolPath'] = '/home/pi/brewpi-tools-rmx/'
defCfg['scriptPath'] = '/home/brewpi/'
defCfg['wwwPath'] = '/var/www/html/'
defCfg['port'] = 'auto'
Expand Down Expand Up @@ -126,8 +127,10 @@ def readCfgWithDefaults(configFile = None):
logMessage("Using default configuration.")

# Fix pathnames
defCfg['toolPath'] = addSlash(defCfg['toolPath'])
defCfg['scriptPath'] = addSlash(defCfg['scriptPath'])
defCfg['wwwPath'] = addSlash(defCfg['wwwPath'])

return defCfg


Expand Down Expand Up @@ -270,7 +273,7 @@ def logMessage(*objs):
def logWarn(*objs):
"""
Prints a timestamped warning message to stdout
"""
"""
if 'USE_TIMESTAMP_LOG' in os.environ:
printStdOut(strftime("%Y-%m-%d %H:%M:%S [W]"), *objs)
else:
Expand Down
2 changes: 1 addition & 1 deletion Tilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def blecallback(self, data):
if self.opts.json and self.debug: # Print Debug
display_raw = False
print("Tilt JSON: {}".format(tiltJson))

else: # Not a Tilt
return

Expand Down
2 changes: 1 addition & 1 deletion brewpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ def initTilt(): # Set up Tilt
config['tiltColor'] + 'Batt': 0
})


def initISpindel(): # Initialize iSpindel
global ispindel
global config
Expand Down
2 changes: 1 addition & 1 deletion brewpiJson.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def addRow(jsonFileName, row, tiltColor = None, iSpindel = None):
# Write iSpindel values
elif iSpindel:
if row['spinSG'] is None:
jsonFile.write(",null,")
jsonFile.write(",null")
else:
jsonFile.write(",{\"v\":" + str(row['spinSG']) + "}")

Expand Down
132 changes: 132 additions & 0 deletions gitInfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/usr/bin/python3

# Copyright (C) 2021 Lee C. Bussy (@LBussy)

# This file is part of LBussy's BrewPi Script Remix (BrewPi-Script-RMX).
#
# BrewPi Script RMX is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# BrewPi Script RMX is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BrewPi Script RMX. If not, see <https://www.gnu.org/licenses/>.

import git
import os
import json
from pprint import pprint as pp

import BrewPiUtil as util


class GitInfo:
path = None
repo = None

def __init__(self, arg):
self.path = arg
self.repo = git.Repo(self.path, search_parent_directories=True)

def get_git_root(self) -> str:
try:
root = self.repo.git.rev_parse("--show-toplevel")
except:
root = None
return root

def get_git_tag(self) -> str:
try:
tags = sorted(self.repo.tags, key=lambda t: t.commit.committed_datetime)
tagref = str(tags[-1])
except:
tagref = None
return tagref

def get_git_branch(self) -> str:
try:
branch = str(self.repo.active_branch)
except:
branch = None
return branch

def get_commit_author(self) -> str:
try:
name = self.repo.head.commit.author.name
except:
name = None
return name

def get_commit_author_email(self) -> str:
try:
email = self.repo.head.commit.author.email
except:
email = None
return email

def get_commit_hash(self, length = None) -> str:
try:
if length == None:
commithash = self.repo.head.commit.hexsha
else:
commithash = self.repo.head.commit.hexsha[:length]
except:
hash = None
return commithash

def get_commit_message(self) -> str:
try:
message = self.repo.head.commit.message
message = message.split('\n', 1)[0]
message = message[ 0 : 50 ].strip()
except:
message = None
return message

def get_git_dict(self) -> dict:
git_dict = {}
git_dict['git_root'] = self.get_git_root()
git_dict['git_tag'] = self.get_git_tag()
git_dict['git_branch'] = self.get_git_branch()
git_dict['commit_author'] = self.get_commit_author()
git_dict['commit_author_email'] = self.get_commit_author_email()
git_dict['commit_hash'] = self.get_commit_hash()
git_dict['commit_hash_short'] = self.get_commit_hash(7)
git_dict['commit_message'] = self.get_commit_message()
return git_dict

def get_git_json(self, ind = None) -> str:
if ind == None:
json_str = json.dumps(self.get_git_dict())
else:
json_str = json.dumps(self.get_git_dict(), indent = ind)
return json_str


if __name__ == "__main__":
config = util.readCfgWithDefaults()
path_list = [config['toolPath'], config['scriptPath'], config['wwwPath']]
for path in path_list:
# need path
gi = GitInfo(path)
print("Testing git information for {}".format(path))
print("Repo = {}".format(gi.get_git_root()))
print("Tag = {}".format(gi.get_git_tag()))
print("Branch = {}".format(gi.get_git_branch()))
print("Commit Hash = {}".format(gi.get_commit_hash()))
print("Short Commit Hash = {}".format(gi.get_commit_hash(7)))
print("Commit Author = {}".format(gi.get_commit_author()))
print("Commit Author Email = {}".format(gi.get_commit_author_email()))
print("Commit Message = {}".format(gi.get_commit_message()))
print("Dict object:")
pp(gi.get_git_dict())
print("JSON Beacon:")
print(gi.get_git_json())
print("JSON Beacon Pretty:")
print(gi.get_git_json(4))
print()
2 changes: 1 addition & 1 deletion programController.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def flash_file(self, hexFile):
bootLoaderPort = util.findSerialPort(bootLoader=True, my_port=config['port'])
# bootLoaderPort = util.findSerialPort(bootLoader=True)
if not bootLoaderPort:
printStdErr("\nERROR: Could not find port in bootloader.")
printStdErr("\nERROR: Could not find port in bootloader.")
return False

programCommand = (avrdudehome + 'avrdude' +
Expand Down
1 change: 1 addition & 0 deletions settings/defaults.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# the settings in config.cfg. That file will overrule the defaults
# set here.

toolPath = /home/pi/brewpi-tools-rmx/
scriptPath = /home/brewpi/
wwwPath = /var/www/html/
port = auto
Expand Down
8 changes: 4 additions & 4 deletions utils/doCleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ init() {
popd &> /dev/null || exit 1
exit 1
fi

# Get project constants
# shellcheck source=/dev/null
. "$GITROOT/inc/const.inc" "$@"

# Get error handling functionality
# shellcheck source=/dev/null
. "$GITROOT/inc/error.inc" "$@"

# Get help and version functionality
# shellcheck source=/dev/null
. "$GITROOT/inc/asroot.inc" "$@"

# Get help and version functionality
# shellcheck source=/dev/null
. "$GITROOT/inc/help.inc" "$@"
Expand Down
8 changes: 4 additions & 4 deletions utils/doDaemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ init() {
popd &> /dev/null || exit 1
exit 1
fi

# Get project constants
# shellcheck source=/dev/null
. "$GITROOT/inc/const.inc" "$@"
Expand All @@ -55,11 +55,11 @@ init() {
# Get error handling functionality
# shellcheck source=/dev/null
. "$GITROOT/inc/error.inc" "$@"

# Get help and version functionality
# shellcheck source=/dev/null
. "$GITROOT/inc/asroot.inc" "$@"

# Get help and version functionality
# shellcheck source=/dev/null
. "$GITROOT/inc/help.inc" "$@"
Expand Down Expand Up @@ -194,7 +194,7 @@ ExecStart=/bin/bash $scriptName
SyslogIdentifier=$daemonName
[Install]
WantedBy=multi-user.target"
WantedBy=multi-user.target"
} > "$unitFile"
chown root:root "$unitFile"
chmod 0644 "$unitFile"
Expand Down
12 changes: 6 additions & 6 deletions utils/doDepends.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ declare SCRIPTPATH GITROOT APTPACKAGES PIP3PACKAGES REINSTALL GOODPORT GOODPORTS
# Declare /inc/const.inc file constants
declare THISSCRIPT GITROOT USERROOT REALUSER
# Declare /inc/asroot.inc file constants
declare HOMEPATH
declare HOMEPATH
# Declare placeholders for nginx work
declare DANGER_AHEAD RECONFIG_APACHE
# Declare alternative ports
Expand All @@ -45,7 +45,7 @@ init() {
popd &> /dev/null || exit 1
exit 1
fi

# Get project constants
# shellcheck source=/dev/null
. "$GITROOT/inc/const.inc" "$@"
Expand Down Expand Up @@ -268,7 +268,7 @@ do_packages() {
fi
for pkg in ${APTPACKAGES,,}; do
if [ -n "$REINSTALL" ]; then

apt-get --reinstall install "${pkg,,}" -y -q=2||die
echo
else
Expand All @@ -294,12 +294,12 @@ do_packages() {
else
echo -e "\nNo apt packages were missing."
fi

# Get list of installed packages with upgrade available
upgradesAvail=$(dpkg --get-selections | xargs apt-cache policy {} | \
grep -1 Installed | sed -r 's/(:|Installed: |Candidate: )//' | \
uniq -u | tac | sed '/--/I,+1 d' | tac | sed '$d' | sed -n 1~2p)

# Loop through only the required packages and see if they need an upgrade
for pkg in ${APTPACKAGES,,}; do
if [[ ${upgradesAvail,,} == *"$pkg"* ]]; then
Expand All @@ -308,7 +308,7 @@ do_packages() {
doCleanup=1
fi
done

# Cleanup if we updated packages
if [ -n "$doCleanup" ]; then
echo -e "Cleaning up local repositories."
Expand Down
10 changes: 5 additions & 5 deletions utils/doIndex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ init() {
popd &> /dev/null || exit 1
exit 1
fi

# Get project constants
# shellcheck source=/dev/null
. "$GITROOT/inc/const.inc" "$@"

# Get error handling functionality
# shellcheck source=/dev/null
. "$GITROOT/inc/error.inc" "$@"

# Get help and version functionality
# shellcheck source=/dev/null
. "$GITROOT/inc/asroot.inc" "$@"

# Get help and version functionality
# shellcheck source=/dev/null
. "$GITROOT/inc/help.inc" "$@"

# Get config file read functionality
# shellcheck source=/dev/null
. "$GITROOT/inc/config.inc" "$@"
Expand Down
6 changes: 3 additions & 3 deletions utils/doMenu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ init() {
# Get project constants
# shellcheck source=/dev/null
. "$GITROOT/inc/const.inc" "$@"

# Get error handling functionality
# shellcheck source=/dev/null
. "$GITROOT/inc/error.inc" "$@"

# Get help and version functionality
# shellcheck source=/dev/null
. "$GITROOT/inc/asroot.inc" "$@"

# Get help and version functionality
# shellcheck source=/dev/null
. "$GITROOT/inc/help.inc" "$@"
Expand Down
16 changes: 13 additions & 3 deletions utils/doPerms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,21 @@ perms() {
if [ -e "$GITROOT/BEERSOCKET" ]; then
chown -R brewpi:www-data "$GITROOT/BEERSOCKET" || warn
fi
find "$GITROOT" -type d -exec chmod 775 {} \; || warn
find "$GITROOT" -type f -exec chmod 660 {} \; || warn
find "$GITROOT" -type f -regex ".*\.\(py\|sh\)" -exec chmod 770 {} \; || warn

# Set the directories excluding venv
chmod 660 "$GITROOT"/*.* || warn
chmod +x "$GITROOT"/*.sh >/dev/null 2>&1 # Probably no shell scripts here
chmod +x "$GITROOT"/*.py || warn
for dirname in "$GITROOT"/*/; do
if [ "${dirname%%}" != "$GITROOT/venv/" ]; then
find "${dirname%%}" -type d -exec chmod 775 {} \; || warn
find "${dirname%%}" -type f -exec chmod 660 {} \; || warn
find "${dirname%%}" -type f -regex ".*\.\(py\|sh\)" -exec chmod 770 {} \; || warn
fi
done
find "$GITROOT/logs" -type f -iname "*.txt" -exec chmod 777 {} \; || warn
find "$GITROOT/settings" -type f -exec chmod 664 {} \; || warn

echo -e "\nAllowing BrewPi python access to Bluetooth interfaces."
setcap cap_net_raw+eip $(eval readlink -f `which python3`)
}
Expand Down
Loading

0 comments on commit fe28738

Please sign in to comment.