[~] Refactor
This commit is contained in:
		
							parent
							
								
									58a1e5f1be
								
							
						
					
					
						commit
						48ce6c87a6
					
				
							
								
								
									
										1
									
								
								d1/f1.sh
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										1
									
								
								d1/f1.sh
									
									
									
									
									
								
							| @ -2,6 +2,7 @@ | ||||
| 
 | ||||
| mkdir -p ~/.local/bin | ||||
| cp dotfiles/.local/bin/commands ~/.local/bin/commands | ||||
| cp dotfiles/.local/bin/gnome-shortcuts-macbook-air ~/.local/bin/ | ||||
| mkdir -p ~/.sway | ||||
| cp dotfiles/.sway/config ~/.sway/config | ||||
| cp dotfiles/.zshenv ~/.zshenv | ||||
|  | ||||
| @ -21,16 +21,17 @@ import sys | ||||
| import tempfile | ||||
| import time | ||||
| import traceback | ||||
| from typing import (Literal, Optional,) | ||||
| 
 | ||||
| 
 | ||||
| logger = logging.getLogger(__name__) | ||||
| 
 | ||||
| 
 | ||||
| def custom_notify( | ||||
|     title=None, | ||||
|     msg=None, | ||||
|     timeout=None, | ||||
| ): | ||||
|     title: Optional[str]=None, | ||||
|     msg: Optional[str]=None, | ||||
|     timeout: Optional[int]=None, | ||||
| ) -> None: | ||||
|     if timeout is None: | ||||
|         timeout = 5 | ||||
| 
 | ||||
| @ -1683,7 +1684,7 @@ def pm_service(argv): | ||||
| 
 | ||||
|     print('') | ||||
| 
 | ||||
| def scrap_yt_music(argv): | ||||
| def scrap_yt_music(argv: Iterable[str]) -> None: | ||||
|     parser = optparse.OptionParser() | ||||
|     parser.add_option( | ||||
|         '--verbose', | ||||
| @ -1929,6 +1930,16 @@ def desktop_services(argv): | ||||
|         type=int, | ||||
|         help='0 - mac book air (no turbo boost, max pct 30, every 4 seconds', | ||||
|     ) | ||||
|     parser.add_option( | ||||
|         '--cpufreq-action', | ||||
|         dest='cpufreq_action', | ||||
|         default=None, | ||||
|         choices=[ | ||||
|             'performance', | ||||
|             'powersave', | ||||
|         ], | ||||
|         #type=str, | ||||
|     ) | ||||
|     parser.add_option( | ||||
|         '--battery', | ||||
|         dest='battery', | ||||
| @ -2360,6 +2371,39 @@ def desktop_services(argv): | ||||
| 
 | ||||
|             return state | ||||
| 
 | ||||
|     class Cpufreq: | ||||
|         @classmethod | ||||
|         @property | ||||
|         def profile(cls) -> Literal['applesmc.768']: | ||||
|             if os.path.exists('/sys/bus/platform/devices/applesmc.768'): | ||||
|                 return 'applesmc.768' | ||||
|             else: | ||||
|                 raise NotImplementedError | ||||
| 
 | ||||
|         @classmethod | ||||
|         def powersave(cls): | ||||
|             if cls.profile == 'applesmc.768': | ||||
|                 subprocess.check_call(r''' | ||||
| echo performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; | ||||
| echo powersave | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; | ||||
| echo 1 > /sys/bus/platform/devices/applesmc.768/fan1_manual; | ||||
| echo 2000 > /sys/bus/platform/devices/applesmc.768/fan1_output; | ||||
|                 ''', shell=True) | ||||
|             else: | ||||
|                 raise NotImplementedError | ||||
| 
 | ||||
|         @classmethod | ||||
|         def performance(cls): | ||||
|             if cls.profile == 'applesmc.768': | ||||
|                 subprocess.check_call(r''' | ||||
| echo powersave | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; | ||||
| echo performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; | ||||
| echo 1 > /sys/bus/platform/devices/applesmc.768/fan1_manual; | ||||
| echo 6500 > /sys/bus/platform/devices/applesmc.768/fan1_output; | ||||
|                 ''', shell=True) | ||||
|             else: | ||||
|                 raise NotImplementedError | ||||
| 
 | ||||
|     if options.backlight_increase or options.backlight_decrease: | ||||
|         if options.backlight_increase: | ||||
|             direction = Backlight.Direction.increase | ||||
| @ -2374,6 +2418,16 @@ def desktop_services(argv): | ||||
|         ) | ||||
| 
 | ||||
|         return | ||||
| 
 | ||||
|     elif not options.cpufreq_action is None: | ||||
|         if options.cpufreq_action == 'performance': | ||||
|             Cpufreq.performance() | ||||
|         elif options.cpufreq_action == 'powersave': | ||||
|             Cpufreq.powersave() | ||||
|         else: | ||||
|             raise NotImplementedError | ||||
| 
 | ||||
|         return | ||||
|     else: | ||||
|         pass | ||||
| 
 | ||||
| @ -2852,7 +2906,7 @@ def suspend_timer(argv): | ||||
|     print("suspend computer at %s" % t1.isoformat()) | ||||
|     subprocess.check_call(["systemctl", "suspend"]); | ||||
| 
 | ||||
| def gnome_shortcuts(argv): | ||||
| def gnome_shortcuts(argv: list[str]) -> None: | ||||
|     parser = optparse.OptionParser() | ||||
|     parser.add_option( | ||||
|         '-a', '--add', | ||||
| @ -2868,10 +2922,14 @@ def gnome_shortcuts(argv): | ||||
|     options, args = parser.parse_args(argv) | ||||
| 
 | ||||
|     def commands_ids() -> list[str]: | ||||
|         t1 = json.loads(subprocess.check_output([ | ||||
|         bindings = subprocess.check_output([ | ||||
|             'gsettings', 'get', 'org.gnome.settings-daemon.plugins.media-keys', | ||||
|             'custom-keybindings', | ||||
|         ]).decode('utf-8').replace('\'', '"',)) | ||||
|         ]).decode('utf-8').strip().replace('\'', '"',) | ||||
|         if bindings == '@as []': | ||||
|             t1 = [] | ||||
|         else: | ||||
|             t1 = json.loads(bindings) | ||||
| 
 | ||||
|         return t1 | ||||
| 
 | ||||
| @ -3375,7 +3433,7 @@ def media_keys(argv): | ||||
|             'mocp', | ||||
|         ], stdout=subprocess.PIPE) == 0 | ||||
| 
 | ||||
|     def mocp_info(): | ||||
|     def mocp_info() -> str: | ||||
|         t1 = subprocess.check_output(['mocp', '-i']) | ||||
|         t3 = t1.decode('utf-8') | ||||
|         t2 = dict([ | ||||
| @ -3470,13 +3528,13 @@ def media_keys(argv): | ||||
|         msg=msg, | ||||
|     ) | ||||
| 
 | ||||
| def commands_cli(): | ||||
| def commands_cli() -> None: | ||||
|     logging.getLogger().setLevel(logging.INFO) | ||||
|     logger.setLevel(logging.INFO) | ||||
|     handler = logging.StreamHandler(sys.stderr) | ||||
|     logging.getLogger().addHandler(handler) | ||||
| 
 | ||||
|     msg = None | ||||
|     msg : Optional[str] = None | ||||
| 
 | ||||
|     try: | ||||
|         if sys.argv[1].startswith('media'): | ||||
|  | ||||
							
								
								
									
										13
									
								
								dotfiles/.local/bin/gnome-shortcuts-macbook-air
									
									
									
									
									
										Executable file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										13
									
								
								dotfiles/.local/bin/gnome-shortcuts-macbook-air
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,13 @@ | ||||
| #!/usr/bin/bash | ||||
| 
 | ||||
| commands gnome-shortcuts \ | ||||
| 	-a \ | ||||
| 	'powersave' \ | ||||
| 	'commands desktop-services --cpufreq-action powersave' \ | ||||
| 	'<Shift><Alt>1' | ||||
| 
 | ||||
| commands gnome-shortcuts \ | ||||
| 	-a \ | ||||
| 	'performance' \ | ||||
| 	'commands desktop-services --cpufreq-action performance' \ | ||||
| 	'<Shift><Alt>2' | ||||
| @ -1,3 +1,6 @@ | ||||
| ACTION=="add|change", SUBSYSTEM=="leds", DEVPATH=="/devices/pci0000:00/0000:00:1b.0/hdaudioC0D0/leds/hda::mute", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/brightness" | ||||
| ACTION=="add|change", SUBSYSTEM=="leds", DEVPATH=="/devices/platform/applesmc.768/leds/smc::kbd_backlight", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/brightness" | ||||
| ACTION=="add|change", DEVPATH=="/devices/platform/applesmc.768", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/fan1_manual /sys$devpath/fan1_output" | ||||
| ACTION=="add|change", DEVPATH=="/class/backlight/intel_backlight", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/brightness" | ||||
| ACTION=="add|change", DEVPATH=="/devices/system/cpu/", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/cpufreq/scaling_governor" | ||||
| ACTION=="add|change", KERNEL=="cpu[0-9]", SUBSYSTEM=="cpu", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/cpufreq/scaling_governor" | ||||
|  | ||||
							
								
								
									
										6
									
								
								m
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										6
									
								
								m
									
									
									
									
									
								
							| @ -27,5 +27,11 @@ def js(argv): | ||||
| 
 | ||||
| if len(sys.argv) > 1 and sys.argv[1] == 'js': | ||||
|     js(sys.argv[2:]) | ||||
| elif len(sys.argv) > 1 and sys.argv[1] == 'mypy': | ||||
|     subprocess.check_call([ | ||||
|         'mypy', | ||||
|         '--strict', | ||||
|         'dotfiles/.local/bin/commands', | ||||
|     ]) | ||||
| else: | ||||
|     raise NotImplementedError | ||||
|  | ||||
| @ -6,3 +6,4 @@ pyquery | ||||
| youtube-dl | ||||
| gdown | ||||
| aiohttp | ||||
| mypy | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user