mirror of
https://github.com/c9moser/sgbackup.git
synced 2026-01-19 19:40:13 +00:00
2025.03.02 04:06:43 (desktop)
This commit is contained in:
parent
a9db15a3a5
commit
f9f0e07ee3
@ -16,8 +16,14 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
import os,sys
|
||||||
from sgbackup import __version__ as VERSION
|
from sgbackup import __version__ as VERSION
|
||||||
|
from ..settings import settings
|
||||||
from ..command import Command
|
from ..command import Command
|
||||||
|
from .. import commands
|
||||||
|
from gi.repository import GLib
|
||||||
|
from io import StringIO
|
||||||
|
from subprocess import run
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -57,7 +63,7 @@ class SynopsisCommand(Command):
|
|||||||
|
|
||||||
for i in argv:
|
for i in argv:
|
||||||
try:
|
try:
|
||||||
print(COMMANDS[i].get_synopsis())
|
print(commands.COMMANDS[i].get_synopsis())
|
||||||
except:
|
except:
|
||||||
self.logger.error("No such command {command}".foramt(command=i))
|
self.logger.error("No such command {command}".foramt(command=i))
|
||||||
error_code = 4
|
error_code = 4
|
||||||
@ -65,10 +71,47 @@ class SynopsisCommand(Command):
|
|||||||
return error_code
|
return error_code
|
||||||
|
|
||||||
|
|
||||||
__synopsis = SynopsisCommand()
|
class HelpCommand(Command):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__('help','Help', 'Show help for commands.')
|
||||||
|
|
||||||
|
def get_synopsis(self):
|
||||||
|
return "sgbackup help [COMMAND]"
|
||||||
|
|
||||||
|
def get_sgbackup_help(self):
|
||||||
|
return commands.COMMANDS['synopsis'].get_sgbackup_synopsis()
|
||||||
|
|
||||||
|
def get_help(self):
|
||||||
|
return self.get_synopsis()
|
||||||
|
|
||||||
|
def execute(self,argv):
|
||||||
|
if (len(argv) < 1):
|
||||||
|
message = self.get_sgbackup_help()
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
message = commands.COMMANDS[argv[0]].get_help()
|
||||||
|
except:
|
||||||
|
logger.error("No such command \"{}\"!".format(argv[0]))
|
||||||
|
return 2
|
||||||
|
|
||||||
|
if (sys.stdout.isatty() and settings.cli_pager is not None):
|
||||||
|
r,w = os.pipe()
|
||||||
|
with os.fdopen(w,'w',encoding="utf-8") as wr_stdin:
|
||||||
|
wr_stdin.write(message)
|
||||||
|
|
||||||
|
with os.fdopen(r,'r') as rd_stdin:
|
||||||
|
proc = run([settings.cli_pager],stdin=rd_stdin,shell=True,encoding="utf-8")
|
||||||
|
return proc.returncode
|
||||||
|
|
||||||
|
print(message)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
__synopsis = SynopsisCommand()
|
||||||
|
|
||||||
COMMANDS = {
|
COMMANDS = {
|
||||||
'version':VersionCommand(),
|
'version':VersionCommand(),
|
||||||
'synopsis': __synopsis,
|
'synopsis': __synopsis,
|
||||||
'usage': __synopsis
|
'usage': __synopsis,
|
||||||
|
'help': HelpCommand(),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -398,12 +398,10 @@ class GameView(Gtk.Box):
|
|||||||
for name,match,pos in result:
|
for name,match,pos in result:
|
||||||
self._liststore.get_item(pos).fuzzy_match = match
|
self._liststore.get_item(pos).fuzzy_match = match
|
||||||
|
|
||||||
print("-"*80)
|
|
||||||
self.__filter_model.set_filter(GameViewMatchFilter())
|
self.__filter_model.set_filter(GameViewMatchFilter())
|
||||||
self.__sort_model.set_sorter(GameViewMatchSorter())
|
self.__sort_model.set_sorter(GameViewMatchSorter())
|
||||||
|
|
||||||
def _on_search_entry_icon_release(self,entry,icon_pos):
|
def _on_search_entry_icon_release(self,entry,icon_pos):
|
||||||
#TODO###############################################
|
|
||||||
if icon_pos == Gtk.EntryIconPosition.PRIMARY:
|
if icon_pos == Gtk.EntryIconPosition.PRIMARY:
|
||||||
search_name=entry.get_text()
|
search_name=entry.get_text()
|
||||||
if len(search_name) == 0:
|
if len(search_name) == 0:
|
||||||
@ -417,7 +415,6 @@ class GameView(Gtk.Box):
|
|||||||
self.__sort_model.set_sorter(self.columnview.get_sorter())
|
self.__sort_model.set_sorter(self.columnview.get_sorter())
|
||||||
|
|
||||||
def _on_search_entry_changed(self,entry):
|
def _on_search_entry_changed(self,entry):
|
||||||
#TODO###############################################
|
|
||||||
search_name = entry.get_text()
|
search_name = entry.get_text()
|
||||||
if len(search_name) == 0:
|
if len(search_name) == 0:
|
||||||
self.__filter_model.set_filter(None)
|
self.__filter_model.set_filter(None)
|
||||||
|
|||||||
@ -267,6 +267,19 @@ class SettingsDialog(Gtk.Dialog):
|
|||||||
gui_frame.set_child(gui_grid)
|
gui_frame.set_child(gui_grid)
|
||||||
vbox.append(gui_frame)
|
vbox.append(gui_frame)
|
||||||
|
|
||||||
|
### CLI Settings
|
||||||
|
cli_frame = self.create_frame("Command Line Interface")
|
||||||
|
cli_grid = self.create_grid()
|
||||||
|
label = self.create_label("Pager:")
|
||||||
|
page.cli_pager_entry = Gtk.Entry()
|
||||||
|
page.cli_pager_entry.set_hexpand(True)
|
||||||
|
page.cli_pager_entry.set_text(settings.cli_pager if settings.cli_pager else "")
|
||||||
|
cli_grid.attach(label,0,0,1,1)
|
||||||
|
cli_grid.attach(page.cli_pager_entry,1,0,1,1)
|
||||||
|
|
||||||
|
cli_frame.set_child(cli_grid)
|
||||||
|
vbox.append(cli_frame)
|
||||||
|
|
||||||
page.set_child(vbox)
|
page.set_child(vbox)
|
||||||
self.add_page(page,"general","Generic settings")
|
self.add_page(page,"general","Generic settings")
|
||||||
return page
|
return page
|
||||||
|
|||||||
@ -26,6 +26,7 @@ from threading import RLock
|
|||||||
|
|
||||||
from .utility import sanitize_path
|
from .utility import sanitize_path
|
||||||
|
|
||||||
|
|
||||||
ZIPFILE_COMPRESSION_STR = {
|
ZIPFILE_COMPRESSION_STR = {
|
||||||
zipfile.ZIP_STORED: "stored",
|
zipfile.ZIP_STORED: "stored",
|
||||||
zipfile.ZIP_DEFLATED: "deflated",
|
zipfile.ZIP_DEFLATED: "deflated",
|
||||||
@ -416,6 +417,36 @@ class Settings(GObject.GObject):
|
|||||||
@steam_installpath.setter
|
@steam_installpath.setter
|
||||||
def steam_installpath(self,path:str):
|
def steam_installpath(self,path:str):
|
||||||
self.set_string('steam','installpath',path)
|
self.set_string('steam','installpath',path)
|
||||||
|
|
||||||
|
@GObject.Property
|
||||||
|
def cli_pager(self)->str:
|
||||||
|
pager = self.get_string('cli','pager',None)
|
||||||
|
if pager is None:
|
||||||
|
if PLATFORM_WINDOWS:
|
||||||
|
for prg in ['less.exe','more.com']:
|
||||||
|
pager = GLib.find_program_in_path(prg)
|
||||||
|
if pager is not None:
|
||||||
|
return pager
|
||||||
|
return ""
|
||||||
|
else:
|
||||||
|
for prg in ['less','more']:
|
||||||
|
pager = GLib.find_program_in_path(prg)
|
||||||
|
if pager is not None:
|
||||||
|
return pager
|
||||||
|
return None
|
||||||
|
return pager
|
||||||
|
|
||||||
|
@cli_pager.setter
|
||||||
|
def cli_pager(self,pager:str):
|
||||||
|
value = None
|
||||||
|
if not os.path.isabs(pager):
|
||||||
|
value = GLib.find_program_in_path(pager)
|
||||||
|
elif os.path.isfile(pager):
|
||||||
|
value = pager
|
||||||
|
if value is not None:
|
||||||
|
self.set_string('cli','pager',value)
|
||||||
|
else:
|
||||||
|
self.remove_key('cli','pager')
|
||||||
|
|
||||||
def add_variable(self,name:str,value:str):
|
def add_variable(self,name:str,value:str):
|
||||||
self.set_string('variables',name,value)
|
self.set_string('variables',name,value)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user