Skip to content

Commit

Permalink
Merge pull request #59 from hjelev/dev
Browse files Browse the repository at this point in the history
still fixing update system
  • Loading branch information
hjelev authored Feb 1, 2024
2 parents 36cccac + 3240a19 commit 0d1da89
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
18 changes: 7 additions & 11 deletions src/rpi-cpu2mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def check_git_update(script_dir):
else:
git_update = {
"installed_ver": config.version,
"new_ver": check_git_version_remote(script_dir),
"new_ver": update.check_git_version_remote(script_dir),
}

return(json.dumps(git_update))
Expand All @@ -173,11 +173,7 @@ def check_git_version(script_dir):
return(git_version)


def check_git_version_remote(script_dir):
full_cmd = "git -C {} ls-remote --tags origin | awk -F'/' '{{print $3}}' | sort -V | tail -n 1".format(script_dir)
result = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].decode("utf-8")
latest_tag = result.strip()
return latest_tag if latest_tag else None


def get_network_ip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Expand Down Expand Up @@ -477,21 +473,21 @@ def parse_arguments():
args = parser.parse_args()

if args.update:
version = check_git_version_remote(script_dir).strip()
version = update.check_git_version_remote(script_dir).strip()
git_update = check_git_update(script_dir)

if git_update == 'on':
git_update = True
else:
git_update = False

update.do_update(version, git_update)
update.do_update(script_dir, version, git_update)

exit()

if args.version:
installed_version = check_git_version(script_dir).strip()
latest_versino = check_git_version_remote(script_dir).strip()
latest_versino = update.check_git_version_remote(script_dir).strip()
print("Installed version: " + installed_version)
print("Latest version: " + latest_versino)
if installed_version != latest_versino:
Expand Down Expand Up @@ -560,8 +556,8 @@ def on_message(client, userdata, msg):
global exit_flag
print("Received message: ", msg.payload.decode())
if msg.payload.decode() == "install":
version = check_git_version_remote(script_dir).strip()
update.do_update(version, git_update=True, config_update=True)
version = update.check_git_version_remote(script_dir).strip()
update.do_update(script_dir, version, git_update=True, config_update=True)
print("Update completed. Setting exit flag...")
exit_flag = True

Expand Down
18 changes: 12 additions & 6 deletions src/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import subprocess
import config


def get_assignments(filename):
with open(filename) as f:
tree = ast.parse(f.read(), filename)
Expand Down Expand Up @@ -39,6 +38,13 @@ def display_config_differences(current_config, example_config, display=True):
else:
return False

def check_git_version_remote(script_dir):
full_cmd = "git -C {} ls-remote --tags origin | awk -F'/' '{{print $3}}' | sort -V | tail -n 1".format(script_dir)
result = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].decode("utf-8")
latest_tag = result.strip()
return latest_tag if latest_tag else None


def update_config_version(version, script_dir):
with open(script_dir + '/config.py', 'r') as f:
lines = f.readlines()
Expand All @@ -52,11 +58,10 @@ def update_config_version(version, script_dir):
f.write(line)


def do_update(version=config.version, git_update=True, config_update=True):
script_dir = os.path.dirname(os.path.realpath(__file__))
def do_update(script_dir, version=config.version, git_update=True, config_update=True):
print("Current version: {}".format(config.version))
if git_update:
print(":: Updating git repository")
print(":: Updating git repository", script_dir)
result = subprocess.run(['git', '-C', script_dir, 'pull'], check=True, universal_newlines=True, stdout=subprocess.PIPE)
print(result.stdout)

Expand All @@ -68,5 +73,6 @@ def do_update(version=config.version, git_update=True, config_update=True):
update_config_version(version, script_dir)


if __name__ == '__main__':
do_update()
if __name__ == '__main__':
script_dir = os.path.dirname(os.path.realpath(__file__))
do_update(script_dir,check_git_version_remote(script_dir))

0 comments on commit 0d1da89

Please sign in to comment.