Skip to content

Commit

Permalink
added optional path in --update (#538)
Browse files Browse the repository at this point in the history
* add --dir

* add to path option to --update

* optional add to path in --update

* update

* update README.md

* resolve bugs
  • Loading branch information
cosmos1721 committed Sep 18, 2023
1 parent 20a1a9d commit 7e02a07
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 26 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)**
8 changes: 4 additions & 4 deletions auto-cpufreq-installer
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -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 "
Expand Down
13 changes: 4 additions & 9 deletions auto_cpufreq/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 25 additions & 10 deletions bin/auto-cpufreq
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# core import
import sys
import time
import click
from click import UsageError
from subprocess import call, run

sys.path.append("../")
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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()

0 comments on commit 7e02a07

Please sign in to comment.