1
0
Fork 0

Make setproctitle optional in Windows

This commit is contained in:
Amjith Ramanujam 2015-10-23 02:49:20 -07:00
parent d9c62b0925
commit cc7b9d2d56
3 changed files with 30 additions and 13 deletions

View File

@ -13,7 +13,10 @@ from time import time
from codecs import open
import click
import setproctitle
try:
import setproctitle
except ImportError:
setproctitle = None
import sqlparse
from prompt_toolkit import CommandLineInterface, Application, AbortAction
from prompt_toolkit.enums import DEFAULT_BUFFER
@ -526,7 +529,9 @@ def cli(database, user, host, port, prompt_passwd, never_prompt, dbname,
'\thost: %r'
'\tport: %r', database, user, host, port)
obfuscate_process_password()
if setproctitle:
obfuscate_process_password()
pgcli.run_cli()
def obfuscate_process_password():
@ -534,7 +539,7 @@ def obfuscate_process_password():
if '://' in process_title:
process_title = re.sub(r":(.*):(.*)@", r":\1:xxxx@", process_title)
elif "=" in process_title:
process_title = re.sub(r"password=(.+?)((\s[a-zA-Z]+=)|$)", r"password=xxxx\2", process_title)
process_title = re.sub(r"password=(.+?)((\s[a-zA-Z]+=)|$)", r"password=xxxx\2", process_title)
setproctitle.setproctitle(process_title)

View File

@ -1,5 +1,6 @@
import re
import ast
import platform
from setuptools import setup, find_packages
_version_re = re.compile(r'__version__\s+=\s+(.*)')
@ -10,6 +11,23 @@ with open('pgcli/__init__.py', 'rb') as f:
description = 'CLI for Postgres Database. With auto-completion and syntax highlighting.'
install_requirements = [
'pgspecial>=1.1.0',
'click >= 4.1',
'Pygments >= 2.0', # Pygments has to be Capitalcased. WTF?
'prompt_toolkit==0.46',
'psycopg2 >= 2.5.4',
'sqlparse == 0.1.16',
'configobj >= 5.0.6',
]
# setproctitle is used to mask the password when running `ps` in command line.
# But this is not necessary in Windows since the password is never shown in the
# task manager. Also setproctitle is a hard dependency to install in Windows,
# so we'll only install it if we're not in Windows.
if platform.system() != 'Windows':
install_requirements.append('setproctitle >= 1.1.9')
setup(
name='pgcli',
@ -23,16 +41,7 @@ setup(
'packages/pgliterals/pgliterals.json']},
description=description,
long_description=open('README.rst').read(),
install_requires=[
'pgspecial>=1.1.0',
'click >= 4.1',
'Pygments >= 2.0', # Pygments has to be Capitalcased. WTF?
'prompt_toolkit==0.46',
'psycopg2 >= 2.5.4',
'sqlparse == 0.1.16',
'configobj >= 5.0.6',
'setproctitle >= 1.1.9'
],
install_requires=install_requirements,
entry_points='''
[console_scripts]
pgcli=pgcli.main:cli

View File

@ -1,4 +1,5 @@
import pytest
import platform
from pgcli.main import need_completion_refresh, obfuscate_process_password
@ -9,6 +10,8 @@ from pgcli.main import need_completion_refresh, obfuscate_process_password
def test_need_completion_refresh(sql):
assert need_completion_refresh(sql)
@pytest.mark.skipif(platform.system() == 'Windows',
reason='Not applicable in windows')
def test_obfuscate_process_password():
import setproctitle
original_title = setproctitle.getproctitle()