pylint integration: gc.platform -> sys.platform

This commit is contained in:
The MMGen Project 2023-10-13 09:51:12 +00:00
commit 0a1e3c3c98
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
38 changed files with 108 additions and 127 deletions

View file

@ -55,16 +55,12 @@ class GlobalConstants(Lockable):
prog_name = os.path.basename(sys.argv[0])
is_txprog = prog_name == 'mmgen-regtest' or prog_name.startswith('mmgen-tx')
for k in ('linux','win','msys'):
if sys.platform.startswith(k):
platform = { 'linux':'linux', 'win':'win', 'msys':'win' }[k]
break
else:
if sys.platform not in ('linux','win32'):
die2(1,f'{sys.platform!r}: platform not supported by {proj_name}')
if os.getenv('HOME'): # Linux or MSYS2
home_dir = os.getenv('HOME')
elif platform == 'win': # Windows without MSYS2 - not supported
elif sys.platform == 'win32': # Windows without MSYS2 - not supported
die2(1,f'$HOME not set! {proj_name} for Windows must be run in MSYS2 environment')
else:
die2(2,'$HOME is not set! Unable to determine home directory')

View file

@ -47,8 +47,8 @@ def nocolor(s):
def set_vt100():
'hack to put term into VT100 mode under MSWin'
from .cfg import gc
if gc.platform == 'win':
import sys
if sys.platform == 'win32':
from subprocess import run
run([],shell=True)

View file

@ -20,7 +20,7 @@
daemon: Daemon control interface for the MMGen suite
"""
import os,time,importlib
import sys,os,time,importlib
from subprocess import run,PIPE,CompletedProcess
from collections import namedtuple
@ -54,8 +54,8 @@ class Daemon(Lockable):
def __init__(self,cfg,opts=None,flags=None):
self.cfg = cfg
self.platform = gc.platform
if self.platform == 'win':
self.platform = sys.platform
if self.platform == 'win32':
self.use_pidfile = False
self.use_threads = True
@ -65,11 +65,11 @@ class Daemon(Lockable):
def exec_cmd_thread(self,cmd):
import threading
tname = ('exec_cmd','exec_cmd_win_console')[self.platform == 'win' and self.new_console_mswin]
tname = ('exec_cmd','exec_cmd_win_console')[self.platform == 'win32' and self.new_console_mswin]
t = threading.Thread(target=getattr(self,tname),args=(cmd,))
t.daemon = True
t.start()
if self.platform == 'win':
if self.platform == 'win32':
Msg_r(' \b') # blocks w/o this...crazy
return True
@ -119,7 +119,7 @@ class Daemon(Lockable):
if self.use_pidfile:
with open(self.pidfile) as fp:
return fp.read().strip()
elif self.platform == 'win':
elif self.platform == 'win32':
# Assumes only one running instance of given daemon. If multiple daemons are running,
# the first PID in the list is returned and self.pids is set to the PID list.
ss = f'{self.exec_fn}.exe'
@ -155,7 +155,7 @@ class Daemon(Lockable):
@property
def stop_cmd(self):
return (
['kill','-Wf',self.pid] if self.platform == 'win' else
['kill','-Wf',self.pid] if self.platform == 'win32' else
['kill','-9',self.pid] if self.force_kill else
['kill',self.pid] )
@ -486,7 +486,7 @@ class CoinDaemon(Daemon):
assert self.test_suite, 'datadir removal restricted to test suite'
if self.state == 'stopped':
run([
('rm' if gc.platform == 'win' else '/bin/rm'),
('rm' if self.platform == 'win32' else '/bin/rm'),
'-rf',
self.datadir ])
set_vt100()

View file

@ -20,7 +20,7 @@
filename: File and MMGenFile classes and methods for the MMGen suite
"""
import os
import sys,os
from .util import die,get_extension
class File:
@ -43,8 +43,7 @@ class File:
import stat
if stat.S_ISBLK(st.st_mode):
mode = (os.O_RDONLY,os.O_RDWR)[bool(write)]
from .cfg import gc
if gc.platform == 'win':
if sys.platform == 'win32':
mode |= os.O_BINARY
try:
fd = os.open(fn, mode)

View file

@ -22,7 +22,6 @@ fileutil: Routines that read, write, execute or stat files
import sys,os
from .cfg import gc
from .color import set_vt100
from .util import (
msg,
@ -41,7 +40,7 @@ def check_or_create_dir(path):
if os.getenv('MMGEN_TEST_SUITE'):
from subprocess import run
run([
('rm' if gc.platform == 'win' else '/bin/rm'),
('rm' if sys.platform == 'win32' else '/bin/rm'),
'-rf',
path ])
set_vt100()
@ -206,9 +205,10 @@ def write_data_to_file(
else:
msg('Redirecting output to file')
if binary and gc.platform == 'win':
import msvcrt
msvcrt.setmode(sys.stdout.fileno(),os.O_BINARY)
if binary:
if sys.platform == 'win32': # condition on separate line for pylint
import msvcrt
msvcrt.setmode(sys.stdout.fileno(),os.O_BINARY)
# MSWin workaround. See msg_r()
try:

View file

@ -29,9 +29,8 @@ def launch(mod,package='mmgen'):
mod = 'addrgen'
import sys,os
from .cfg import gc
if gc.platform == 'linux' and sys.stdin.isatty():
if sys.platform == 'linux' and sys.stdin.isatty():
import termios,atexit
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)

View file

@ -21,6 +21,8 @@ mmgen-passgen: Generate a series or range of passwords from an MMGen
deterministic wallet
"""
import sys,time
from .cfg import gc,Config
from .addrlist import AddrIdxList
from .passwdlist import PasswordList
@ -181,7 +183,6 @@ if keypress_confirm( cfg, 'Encrypt password list?' ):
af.encrypt()
af.write(binary=True,desc='encrypted password list')
else:
if cfg.test_suite_popen_spawn and gc.platform == 'win':
import time
if cfg.test_suite_popen_spawn and sys.platform == 'win32':
time.sleep(0.1)
af.write(desc='password list')

View file

@ -268,7 +268,7 @@ def process_args(cmd,cmd_args,cls):
die(1,"'Binary input data must be supplied via STDIN")
if have_stdin_input and arg_type == 'str' and isinstance(arg,bytes):
NL = '\r\n' if gc.platform == 'win' else '\n'
NL = '\r\n' if sys.platform == 'win32' else '\n'
arg = arg.decode()
if arg[-len(NL):] == NL: # rstrip one newline
arg = arg[:-len(NL)]

View file

@ -29,7 +29,7 @@ class bitcoin_core_daemon(CoinDaemon):
nonstd_datadir = False
datadirs = {
'linux': [gc.home_dir,'.bitcoin'],
'win': [os.getenv('APPDATA'),'Bitcoin']
'win32': [os.getenv('APPDATA'),'Bitcoin']
}
def init_datadir(self):
@ -130,7 +130,7 @@ class bitcoin_cash_node_daemon(bitcoin_core_daemon):
nonstd_datadir = True
datadirs = {
'linux': [gc.home_dir,'.bitcoin-bchn'],
'win': [os.getenv('APPDATA'),'Bitcoin_ABC']
'win32': [os.getenv('APPDATA'),'Bitcoin_ABC']
}
def set_comment_args(self,rpc,coinaddr,lbl):
@ -159,5 +159,5 @@ class litecoin_core_daemon(bitcoin_core_daemon):
cfg_file_hdr = '# Litecoin Core config file\n'
datadirs = {
'linux': [gc.home_dir,'.litecoin'],
'win': [os.getenv('APPDATA'),'Litecoin']
'win32': [os.getenv('APPDATA'),'Litecoin']
}

View file

@ -63,7 +63,7 @@ class openethereum_daemon(ethereum_daemon):
cfg_file = 'parity.conf'
datadirs = {
'linux': [gc.home_dir,'.local','share','io.parity.ethereum'],
'win': [os.getenv('LOCALAPPDATA'),'Parity','Ethereum']
'win32': [os.getenv('LOCALAPPDATA'),'Parity','Ethereum']
}
def init_subclass(self):
@ -100,7 +100,7 @@ class geth_daemon(ethereum_daemon):
version_info_arg = 'version'
datadirs = {
'linux': [gc.home_dir,'.ethereum','geth'],
'win': [os.getenv('LOCALAPPDATA'),'Geth'] # FIXME
'win32': [os.getenv('LOCALAPPDATA'),'Geth'] # FIXME
}
def init_subclass(self):
@ -136,7 +136,7 @@ class erigon_daemon(geth_daemon):
version_info_arg = '--version'
datadirs = {
'linux': [gc.home_dir,'.local','share','erigon'],
'win': [os.getenv('LOCALAPPDATA'),'Erigon'] # FIXME
'win32': [os.getenv('LOCALAPPDATA'),'Erigon'] # FIXME
}
def init_subclass(self):

View file

@ -28,7 +28,7 @@ class monero_daemon(CoinDaemon):
cfg_file = 'bitmonero.conf'
datadirs = {
'linux': [gc.home_dir,'.bitmonero'],
'win': ['/','c','ProgramData','bitmonero']
'win32': ['/','c','ProgramData','bitmonero']
}
def init_datadir(self):
@ -65,13 +65,13 @@ class monero_daemon(CoinDaemon):
['--no-igd'],
[f'--data-dir={self.datadir}', self.non_dfl_datadir],
[f'--pidfile={self.pidfile}', self.platform == 'linux'],
['--detach', not (self.opt.no_daemonize or self.platform=='win')],
['--detach', not (self.opt.no_daemonize or self.platform=='win32')],
['--offline', not self.opt.online],
)
@property
def stop_cmd(self):
if self.platform == 'win':
if self.platform == 'win32':
return ['kill','-Wf',self.pid]
elif contains_any( self.start_cmd, ['--restricted-rpc','--public-node'] ):
return ['kill',self.pid]
@ -164,7 +164,7 @@ class MoneroWalletDaemon(RPCDaemon):
[f'--daemon-port={self.monerod_port}', not self.monerod_addr],
[f'--proxy={self.proxy}', self.proxy],
[f'--pidfile={self.pidfile}', self.platform == 'linux'],
['--detach', not (self.opt.no_daemonize or self.platform=='win')],
['--detach', not (self.opt.no_daemonize or self.platform=='win32')],
['--stagenet', self.network == 'testnet'],
['--allow-mismatched-daemon-version', test_suite],
)

View file

@ -20,11 +20,10 @@
rpc: Cryptocoin RPC library for the MMGen suite
"""
import re,base64,json,asyncio,importlib
import sys,re,base64,json,asyncio,importlib
from decimal import Decimal
from collections import namedtuple
from .cfg import gc
from .util import msg,die,fmt,fmt_list,pp_fmt,oneshot_warning
from .base_obj import AsyncInit
from .obj import NonNegativeInt
@ -264,7 +263,7 @@ class RPCClient(MMGenObject):
self.name = type(self).__name__
# aiohttp workaround, and may speed up RPC performance overall on some systems:
if gc.platform == 'win' and host == 'localhost':
if sys.platform == 'win32' and host == 'localhost':
host = '127.0.0.1'
global dmsg_rpc,dmsg_rpc_backend
@ -291,7 +290,7 @@ class RPCClient(MMGenObject):
def _get_backend(self,backend):
backend_id = backend or self.cfg.rpc_backend
if backend_id == 'auto':
return {'linux':RPCBackends.httplib,'win':RPCBackends.requests}[gc.platform](self)
return {'linux':RPCBackends.httplib,'win32':RPCBackends.requests}[sys.platform](self)
else:
return getattr(RPCBackends,backend_id)(self)

View file

@ -27,18 +27,18 @@ from collections import namedtuple
from .util import msg,msg_r,die
try:
if sys.platform == 'linux':
import tty,termios
from select import select
_platform = 'linux'
except ImportError:
elif sys.platform == 'win32':
try:
import msvcrt
_platform = 'mswin'
except:
die(2,'Unable to set terminal mode')
if not sys.stdin.isatty():
msvcrt.setmode(sys.stdin.fileno(),os.O_BINARY)
else:
die(2,f'{sys.platform!r}: unsupported platform')
_term_dimensions = namedtuple('terminal_dimensions',['width','height'])
@ -285,8 +285,8 @@ class MMGenTermMSWinStub(MMGenTermMSWin):
def get_term():
return {
'linux': (MMGenTermLinux if sys.stdin.isatty() else MMGenTermLinuxStub),
'mswin': (MMGenTermMSWin if sys.stdin.isatty() else MMGenTermMSWinStub),
}[_platform]
'win32': (MMGenTermMSWin if sys.stdin.isatty() else MMGenTermMSWinStub),
}[sys.platform]
def init_term(cfg,noecho=False):

View file

@ -20,10 +20,9 @@
tool.fileutil: File routines for the 'mmgen-tool' utility
"""
import os
import sys,os
from .common import tool_cmd_base
from ..cfg import gc
from ..util import msg,msg_r,die,suf,make_full_path
from ..crypto import Crypto
@ -40,7 +39,7 @@ class tool_cmd(tool_cmd_base):
ivsize,bsize,mod = ( Crypto.aesctr_iv_len, 4096, 4096*8 )
n,carry = 0,b' '*ivsize
flgs = os.O_RDONLY|os.O_BINARY if gc.platform == 'win' else os.O_RDONLY
flgs = os.O_RDONLY|os.O_BINARY if sys.platform == 'win32' else os.O_RDONLY
f = os.open(filename,flgs)
for ch in incog_id:
if ch not in '0123456789ABCDEF':
@ -56,7 +55,6 @@ class tool_cmd(tool_cmd_base):
continue
msg(f'\rIncog data for ID {incog_id} found at offset {n+i-ivsize}')
if not keep_searching:
import sys
sys.exit(0)
carry = d[len(d)-ivsize:]
n += bsize

View file

@ -20,7 +20,8 @@
tool.util: Utility commands for the 'mmgen-tool' utility
"""
from ..cfg import gc
import sys,os
from .common import tool_cmd_base
class tool_cmd(tool_cmd_base):
@ -122,8 +123,8 @@ class tool_cmd(tool_cmd_base):
def unhexdump(self,infile:str):
"decode hexdump from file (use '-' for stdin) (warning: outputs binary data)"
if gc.platform == 'win':
import sys,os,msvcrt
if sys.platform == 'win32':
import msvcrt
msvcrt.setmode( sys.stdout.fileno(), os.O_BINARY )
from ..fileutil import get_data_from_file
from ..util2 import decode_pretty_hexdump

View file

@ -12,7 +12,7 @@
tw.json: export and import tracking wallet to JSON format
"""
import os,json
import sys,os,json
from collections import namedtuple
from ..util import msg,ymsg,fmt,suf,die,make_timestamp,make_chksum_8
@ -54,8 +54,7 @@ class TwJSON:
from ..addrlist import AddrIdxList
prune_id = AddrIdxList(idx_list=self.pruned).id_str
fn = get_fn(prune_id)
from ..cfg import gc
mf = 255 if gc.platform == 'win' else os.statvfs(self.cfg.outdir or os.curdir).f_namemax
mf = 255 if sys.platform == 'win32' else os.statvfs(self.cfg.outdir or os.curdir).f_namemax
if len(fn) > mf:
fn = get_fn(f'idhash={make_chksum_8(prune_id.encode()).lower()}')
else:

View file

@ -171,7 +171,7 @@ class TwView(MMGenObject,metaclass=AsyncInit):
'\x1b[7~': 'm_top',
'\x1b[8~': 'm_bot',
},
'win': {
'win32': {
'\xe0H': 'm_cursor_up',
'\xe0P': 'm_cursor_down',
'\xe0I': 'm_pg_up',
@ -526,7 +526,7 @@ class TwView(MMGenObject,metaclass=AsyncInit):
for k in self.scroll_keys['vi']:
assert k not in self.key_mappings, f'{k!r} is in key_mappings'
self.key_mappings.update(self.scroll_keys['vi'])
self.key_mappings.update(self.scroll_keys[gc.platform])
self.key_mappings.update(self.scroll_keys[sys.platform])
return self.key_mappings
scroll = self.scroll = self.cfg.scroll

View file

@ -94,7 +94,7 @@ class Util:
msg(f'{capfirst(desc2)} OK ({val2})')
return True
if gc.platform == 'win':
if sys.platform == 'win32':
def msg_r(s):
try:
gv.stderr.write(s)
@ -457,5 +457,5 @@ def wrap_ripemd160(called=[]):
called.append(True)
def exit_if_mswin(feature):
if gc.platform == 'win':
if sys.platform == 'win32':
die(2, capfirst(feature) + ' not supported on the MSWin / MSYS2 platform' )

View file

@ -12,9 +12,8 @@
wallet.incog_hidden: hidden incognito wallet class
"""
import os
import sys,os
from ..cfg import gc
from ..seed import Seed
from ..util import msg,die,capfirst
from ..util2 import parse_bytespec
@ -73,7 +72,7 @@ class wallet(wallet):
d.target_data_len = self._get_incog_data_len(self.cfg.seed_len or Seed.dfl_len)
self._check_valid_offset(self.infile,'read')
flgs = os.O_RDONLY|os.O_BINARY if gc.platform == 'win' else os.O_RDONLY
flgs = os.O_RDONLY|os.O_BINARY if sys.platform == 'win32' else os.O_RDONLY
fh = os.open(self.infile.name,flgs)
os.lseek(fh,int(d.hincog_offset),os.SEEK_SET)
self.fmt_data = os.read(fh,d.target_data_len)
@ -136,7 +135,7 @@ class wallet(wallet):
message = '',
action = f'alter file {f.name!r}' )
flgs = os.O_RDWR|os.O_BINARY if gc.platform == 'win' else os.O_RDWR
flgs = os.O_RDWR|os.O_BINARY if sys.platform == 'win32' else os.O_RDWR
fh = os.open(f.name,flgs)
os.lseek(fh, int(d.hincog_offset), os.SEEK_SET)
os.write(fh, self.fmt_data)

View file

@ -112,7 +112,7 @@ class TestKeccak(TestHashFunc):
from mmgen.contrib.keccak import keccak_256
self.t_cls = keccak_256
from mmgen.pyversion import python_version
if python_version >= '3.11' or gc.platform == 'win':
if python_version >= '3.11' or sys.platform == 'win32':
class hashlib:
@staticmethod
def keccak_256(data):
@ -175,7 +175,7 @@ class TestSha512(TestSha2):
0x431d67c49c100d4c, 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 )
from test.include.common import getrand,set_globals
from mmgen.cfg import Config,gc
from mmgen.cfg import Config
set_globals(Config())

Some files were not shown because too many files have changed in this diff Show more