added optional path in --update (#538)

* add --dir

* add to path option to --update

* optional add to path in --update

* update

* update README.md

* resolve bugs
This commit is contained in:
Devesh Sharma 2023-09-18 23:29:46 +05:30 committed by GitHub
parent 20a1a9d3a6
commit 7e02a0769d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 26 deletions

View File

@ -364,9 +364,11 @@ If the install has been performed as part of snap package, daemon status can be
### Update - auto-cpufreq update
Update functionality works by cloning auto-cpufreq repo to /home directory of currently logged in user, installing it using [auto-cpufreq-installer](#auto-cpufreq-installer) and performing [auto-cpufreq daemon install](#install---auto-cpufreq-daemon) with [latest version](https://github.com/AdnanHodzic/auto-cpufreq/releases) changes.
Update functionality works by cloning auto-cpufreq repo, installing it using [auto-cpufreq-installer](#auto-cpufreq-installer) and performing [auto-cpufreq daemon install](#install---auto-cpufreq-daemon) with [latest version](https://github.com/AdnanHodzic/auto-cpufreq/releases) changes.
Update the package by running: `sudo auto-cpufreq --update`
Update auto-cpufreq by running: `sudo auto-cpufreq --update`. Latest revision is cloned to default location `/opt/auto-cpufreq/source`, thus maintaining existing dir structure.
Update and clone to custom directory by running: `sudo auto-cpufreq --update=/path/to/directory`.
### Remove - auto-cpufreq daemon
@ -490,4 +492,4 @@ If auto-cpufreq helped you out and you find it useful, show your appreciation by
Other ways of supporting the project consists of making a code or documentation contribution. If you have an idea for a new features or want to implement some of the existing feature requests or fix some of the [bugs & issues](https://github.com/AdnanHodzic/auto-cpufreq/issues) please make your changes and submit a [pull request](https://github.com/AdnanHodzic/auto-cpufreq/pulls) which I'll be glad to review. If your changes are accepted you'll be credited as part of [releases page](https://github.com/AdnanHodzic/auto-cpufreq/releases).
**Please note: auto-cpufreq is looking for co-maintainers & open source developers to [help shape future of the project!](https://github.com/AdnanHodzic/auto-cpufreq/discussions/312)**
**Please note: auto-cpufreq is looking for co-maintainers & open source developers to [help shape future of the project!](https://github.com/AdnanHodzic/auto-cpufreq/discussions/312)**

View File

@ -20,9 +20,9 @@ fi
#separator
function separator {
local COLUMNS="`tput cols`"
local COLOUMNS="`tput cols`"
echo -e "\n"
printf "%0.s─" $(seq $COLUMNS)
printf "%0.s─" $(seq $COLOUMNS)
echo -e "\n"
}
@ -37,8 +37,8 @@ function root_check {
}
function header {
local COLUMNS="`tput cols`"
MID="$((COLUMNS / 2))"
local COLOUMNS="`tput cols`"
MID="$((COLOUMNS / 2))"
HEADER="$1"
printf "%0.s─" $(seq $((MID-(${#HEADER}/2)- 1)))
echo -n " $HEADER "

View File

@ -186,19 +186,14 @@ def verify_update():
print(f"Updates are available,\nCurrent version: {installed_version}\nLatest version: {latest_version}")
print("Note that your previous custom settings might be erased with the following update")
def new_update():
username = os.getlogin()
home_dir = "/home/" + username
os.chdir(home_dir)
current_working_directory = os.getcwd()
print("Cloning the latest release to the home directory: ")
print(os.getcwd())
def new_update(custom_dir):
os.chdir(custom_dir)
print(f"Cloning the latest release to {custom_dir}")
run(["git", "clone", "https://github.com/AdnanHodzic/auto-cpufreq.git"])
os.chdir("auto-cpufreq")
print("package cloned to directory ", current_working_directory)
print(f"package cloned to directory {custom_dir}")
run(['./auto-cpufreq-installer'], input='i\n', encoding='utf-8')
# return formatted version for a better readability
def get_formatted_version():
literal_version = pkg_resources.require("auto-cpufreq")[0].version

View File

@ -7,7 +7,7 @@
# core import
import sys
import time
import click
from click import UsageError
from subprocess import call, run
sys.path.append("../")
@ -18,8 +18,8 @@ from auto_cpufreq.power_helper import *
@click.command()
@click.option("--monitor", is_flag=True, help="Monitor and see suggestions for CPU optimizations")
@click.option("--live", is_flag=True, help="Monitor and make (temp.) suggested CPU optimizations")
@click.option("--update", is_flag=True, help="Update daemon and package for (permanent) automatic CPU optimizations")
@click.option("--install", is_flag=True, help="Install daemon for (permanent) automatic CPU optimizations")
@click.option("--update", is_flag=False, help="Update daemon and package for (permanent) automatic CPU optimizations", flag_value="--update")
@click.option("--remove", is_flag=True, help="Remove daemon for (permanent) automatic CPU optimizations")
@click.option("--stats", is_flag=True, help="View live stats of CPU optimizations made by daemon")
@ -89,7 +89,7 @@ def main(config, daemon, debug, update, install, remove, live, log, monitor, sta
else:
pass
#"daemon_not_found" is not defined
daemon_not_found()
#daemon_not_found()
elif monitor:
config_info_dialog()
root_check()
@ -226,9 +226,22 @@ def main(config, daemon, debug, update, install, remove, live, log, monitor, sta
remove_complete_msg()
elif update:
root_check()
custom_dir = "/opt/auto-cpufreq/source"
for arg in sys.argv:
if arg.startswith("--update="):
custom_dir = arg.split("=")[1]
sys.argv.remove(arg)
if "--update" in sys.argv:
update = True
sys.argv.remove("--update")
if len(sys.argv) == 2:
custom_dir = sys.argv[1]
if os.getenv("PKG_MARKER") == "SNAP":
print("Detected auto-cpufreq was installed using snap")
# refresh snap directly using this command
# path wont work in this case
print("Please update using snap package manager, i.e: `sudo snap refresh auto-cpufreq`.")
#check for AUR
@ -238,19 +251,21 @@ def main(config, daemon, debug, update, install, remove, live, log, monitor, sta
verify_update()
ans = input ("Do you want to update auto-cpufreq to the latest release? [y/n]: ")
valid_options = ['y', 'Y', 'yes', 'YES', 'Yes']
if not os.path.exists(custom_dir):
os.makedirs(custom_dir)
if os.path.exists(os.path.join(custom_dir, "auto-cpufreq")):
shutil.rmtree(os.path.join(custom_dir, "auto-cpufreq"))
if ans.lower() in valid_options:
remove_daemon()
remove_complete_msg()
new_update()
new_update(custom_dir)
print("enabling daemon")
run(["auto-cpufreq", "--install"])
print("auto-cpufreq is installed with the latest version")
run(["auto-cpufreq", "--version"])
else:
print("incorrect input\n")
print("Aborted")
print("enabling daemon")
run(["auto-cpufreq", "--install"])
print("auto-cpufreq is installed with the latest version")
app_version()
if __name__ == "__main__":
main()