From cabaf72a90ef80e6e509710c9147a2120b754e2a Mon Sep 17 00:00:00 2001 From: Savoy Date: Thu, 28 Oct 2021 22:01:21 -0500 Subject: [PATCH] Linter Fixes --- ipm.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ipm.py b/ipm.py index 877b30c..24080a0 100755 --- a/ipm.py +++ b/ipm.py @@ -26,7 +26,7 @@ import socket import time try: - import argcomplete + import argcomplete # type: ignore except ImportError: print( 'python3-argcomplete not found, proceeding without shell completion.\n' @@ -51,6 +51,7 @@ sqlite3.register_adapter(PosixPath, lambda a: a.as_posix()) sqlite3.register_converter("PATH", lambda c: Path(c.decode('utf-8')) if c else None) + class Sql: def __init__(self): '''Connects to the SQL database, creating the tables and schema if they @@ -75,7 +76,7 @@ class Sql: self.conn = sqlite3.connect( self.db, - detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES + detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES ) cur = self.conn.cursor() @@ -96,6 +97,7 @@ class Sql: def __exit__(self, type, value, traceback): self.conn.close() + def choices(): '''Returns the local names of the IPFS pins. @@ -107,6 +109,7 @@ def choices(): ''' return [x.name for x in list((_ipm_home / 'mounts').iterdir())] + def execute(cmd): '''Runs a given command while yielding all output as it runs. @@ -128,6 +131,7 @@ def execute(cmd): if return_code: raise sp.CalledProcessError(return_code, cmd) + def check_mounts(): '''Makes sure IPFS has mounted to its default location. @@ -137,14 +141,15 @@ def check_mounts(): If mount points have yet to be set up. ''' if not Path('/ipfs/').is_dir() and not Path('/ipns/').is_dir(): - raise FileNotfoundError( + raise FileNotFoundError( 'IPFS mount points do not yet exist. ' 'Please run `ipfs mount -h` for instructions in setting them up.' ) if not Path('/ipfs/').is_mount() and not Path('/ipns/').is_mount(): sp.run(['ipfs', 'mount']) -def add(path: str, desc: str=''): + +def add(path: str, desc: str = ''): '''Adds a file/dir or an existing IPFS hash to your pinned items. Will also symlink the mount point for the item to $IPM_HOME/mounts/ and @@ -241,6 +246,7 @@ def add(path: str, desc: str=''): sym = _ipm_home / f'mounts/{desc}' sym.symlink_to(og) + def ls(path: str, nnn: bool=False): '''Lists all IPFS pins through their mount locations for easy comprehension. @@ -259,6 +265,7 @@ def ls(path: str, nnn: bool=False): except FileNotFoundError: out = sp.run(['ls', '-lh', path.as_posix()]) + def rm(path: str): '''Removes an IPFS pin from your local repository. @@ -296,6 +303,7 @@ def rm(path: str): if line.startswith('added'): out.append(line) + if __name__ == '__main__': parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, -- 2.45.2