cross-platform Popen with hidden window
This commit is contained in:
parent
d76e5ca0e5
commit
0fa25af0ec
3 changed files with 21 additions and 7 deletions
|
@ -7,7 +7,6 @@ from wakatime.packages.requests.models import Response
|
|||
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import shutil
|
||||
import tempfile
|
||||
import time
|
||||
|
@ -219,9 +218,8 @@ class ProjectTestCase(TestCase):
|
|||
stderr = ''
|
||||
mock_popen.return_value = DynamicIterable((stdout, stderr), max_calls=1)
|
||||
|
||||
expected = None if platform.system() == 'Windows' else 'svn'
|
||||
self.shared(
|
||||
expected_project=expected,
|
||||
expected_project='svn',
|
||||
entity='projects/svn/afolder/emptyfile.txt',
|
||||
)
|
||||
|
||||
|
|
|
@ -11,11 +11,14 @@
|
|||
|
||||
|
||||
import codecs
|
||||
import platform
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
is_py2 = (sys.version_info[0] == 2)
|
||||
is_py3 = (sys.version_info[0] == 3)
|
||||
is_win = platform.system() == 'Windows'
|
||||
|
||||
|
||||
if is_py2: # pragma: nocover
|
||||
|
@ -98,3 +101,18 @@ try:
|
|||
from .packages import simplejson as json
|
||||
except (ImportError, SyntaxError): # pragma: nocover
|
||||
import json
|
||||
|
||||
|
||||
class Popen(subprocess.Popen):
|
||||
"""Patched Popen to prevent opening cmd window on Windows platform."""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
startupinfo = kwargs.get('startupinfo')
|
||||
if is_win or True:
|
||||
try:
|
||||
startupinfo = startupinfo or subprocess.STARTUPINFO()
|
||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||
except AttributeError:
|
||||
pass
|
||||
kwargs['startupinfo'] = startupinfo
|
||||
super(Popen, self).__init__(*args, **kwargs)
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
import logging
|
||||
import os
|
||||
import platform
|
||||
from subprocess import Popen, PIPE
|
||||
from subprocess import PIPE
|
||||
|
||||
from .base import BaseProject
|
||||
from ..compat import u, open
|
||||
from ..compat import u, open, Popen
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError: # pragma: nocover
|
||||
|
@ -86,8 +86,6 @@ class Subversion(BaseProject):
|
|||
return info
|
||||
|
||||
def _find_project_base(self, path, found=False):
|
||||
if platform.system() == 'Windows':
|
||||
return False # pragma: nocover
|
||||
path = os.path.realpath(path)
|
||||
if os.path.isfile(path):
|
||||
path = os.path.split(path)[0]
|
||||
|
|
Loading…
Reference in a new issue