2016-05-12 22:19:48 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2024-12-31 23:56:42 -06:00
|
|
|
# Copyright (C) 2013 - 2025, The pgAdmin Development Team
|
2016-05-12 22:19:48 -05:00
|
|
|
# This software is released under the PostgreSQL License
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
This python script is responsible for executing a process, and logs its output,
|
|
|
|
and error in the given output directory.
|
|
|
|
|
|
|
|
We will create a detached process, which executes this script.
|
|
|
|
|
|
|
|
This script will:
|
|
|
|
* Fetch the configuration from the given database.
|
|
|
|
* Run the given executable specified in the configuration with the arguments.
|
|
|
|
* Create log files for both stdout, and stdout.
|
|
|
|
* Update the start time, end time, exit code, etc in the configuration
|
|
|
|
database.
|
|
|
|
|
|
|
|
Args:
|
2017-02-04 08:26:57 -06:00
|
|
|
list of program and arguments passed to it.
|
|
|
|
|
|
|
|
It also depends on the following environment variable for proper execution.
|
|
|
|
PROCID - Process-id
|
|
|
|
OUTDIR - Output directory
|
2016-05-12 22:19:48 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
# To make print function compatible with python2 & python3
|
|
|
|
import sys
|
|
|
|
import os
|
2023-11-03 06:25:24 -05:00
|
|
|
from datetime import datetime, timedelta, tzinfo, timezone
|
2016-05-12 22:19:48 -05:00
|
|
|
from subprocess import Popen, PIPE
|
|
|
|
from threading import Thread
|
2017-02-04 08:26:57 -06:00
|
|
|
import signal
|
2016-05-12 22:19:48 -05:00
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_IS_WIN = (os.name == 'nt')
|
|
|
|
_ZERO = timedelta(0)
|
|
|
|
_sys_encoding = None
|
|
|
|
_fs_encoding = None
|
|
|
|
_out_dir = None
|
|
|
|
_log_file = None
|
|
|
|
|
2020-04-30 06:52:48 -05:00
|
|
|
|
|
|
|
def _log(msg):
|
|
|
|
with open(_log_file, 'a') as fp:
|
|
|
|
fp.write(
|
|
|
|
('INFO:: %s\n' % msg.encode('ascii', 'xmlcharrefreplace'))
|
|
|
|
)
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
|
|
|
|
|
2019-10-10 07:28:32 -05:00
|
|
|
def unescape_dquotes_process_arg(arg):
|
|
|
|
# Double quotes has special meaning for shell command line and they are
|
|
|
|
# run without the double quotes.
|
|
|
|
#
|
|
|
|
# Remove the saviour #DQ#
|
|
|
|
|
|
|
|
# This cannot be at common place as this file executes
|
|
|
|
# separately from pgadmin
|
|
|
|
dq_id = "#DQ#"
|
|
|
|
|
|
|
|
if arg.startswith(dq_id) and arg.endswith(dq_id):
|
|
|
|
return '{0}'.format(arg[len(dq_id):-len(dq_id)])
|
|
|
|
else:
|
|
|
|
return arg
|
|
|
|
|
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
def _log_exception():
|
2020-05-08 03:43:32 -05:00
|
|
|
type_, value_, traceback_ = sys.exc_info()
|
2016-06-21 08:21:06 -05:00
|
|
|
|
2018-10-11 07:13:08 -05:00
|
|
|
with open(_log_file, 'a') as fp:
|
2017-02-04 08:26:57 -06:00
|
|
|
from traceback import format_exception
|
|
|
|
res = ''.join(
|
|
|
|
format_exception(type_, value_, traceback_)
|
|
|
|
)
|
2016-05-12 22:19:48 -05:00
|
|
|
|
2017-02-04 08:26:57 -06:00
|
|
|
fp.write('EXCEPTION::\n{0}'.format(res))
|
|
|
|
return res
|
2016-05-12 22:19:48 -05:00
|
|
|
|
|
|
|
|
2017-02-04 08:26:57 -06:00
|
|
|
# Copied the 'UTC' class from the 'pytz' package to allow to run this script
|
|
|
|
# without any external dependent library, and can be used with any python
|
|
|
|
# version.
|
|
|
|
class UTC(tzinfo):
|
|
|
|
"""UTC
|
|
|
|
|
|
|
|
Optimized UTC implementation. It unpickles using the single module global
|
|
|
|
instance defined beneath this class declaration.
|
2016-05-12 22:19:48 -05:00
|
|
|
"""
|
2017-02-04 08:26:57 -06:00
|
|
|
zone = "UTC"
|
2016-05-12 22:19:48 -05:00
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_utcoffset = _ZERO
|
|
|
|
_dst = _ZERO
|
2017-02-04 08:26:57 -06:00
|
|
|
_tzname = zone
|
2016-05-12 22:19:48 -05:00
|
|
|
|
2017-02-04 08:26:57 -06:00
|
|
|
def fromutc(self, dt):
|
|
|
|
if dt.tzinfo is None:
|
|
|
|
return self.localize(dt)
|
|
|
|
return super(UTC.__class__, self).fromutc(dt)
|
|
|
|
|
|
|
|
def utcoffset(self, dt):
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
return _ZERO
|
2017-02-04 08:26:57 -06:00
|
|
|
|
|
|
|
def tzname(self, dt):
|
|
|
|
return "UTC"
|
|
|
|
|
|
|
|
def dst(self, dt):
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
return _ZERO
|
2017-02-04 08:26:57 -06:00
|
|
|
|
2022-09-09 08:06:51 -05:00
|
|
|
def localize(self, dt):
|
|
|
|
"""Convert naive time to local time"""
|
2017-02-04 08:26:57 -06:00
|
|
|
if dt.tzinfo is not None:
|
|
|
|
raise ValueError('Not naive datetime (tzinfo is already set)')
|
|
|
|
return dt.replace(tzinfo=self)
|
|
|
|
|
2022-09-09 08:06:51 -05:00
|
|
|
def normalize(self, dt):
|
|
|
|
"""Correct the timezone information on the given datetime"""
|
2017-02-04 08:26:57 -06:00
|
|
|
if dt.tzinfo is self:
|
|
|
|
return dt
|
|
|
|
if dt.tzinfo is None:
|
|
|
|
raise ValueError('Naive time - no tzinfo set')
|
|
|
|
return dt.astimezone(self)
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "<UTC>"
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "UTC"
|
2016-05-12 22:19:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
def get_current_time(format='%Y-%m-%d %H:%M:%S.%f %z'):
|
2023-11-03 06:25:24 -05:00
|
|
|
return datetime.now(timezone.utc).strftime(format)
|
2016-05-12 22:19:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
class ProcessLogger(Thread):
|
|
|
|
"""
|
|
|
|
This class definition is responsible for capturing & logging
|
|
|
|
stdout & stderr messages from subprocess
|
|
|
|
|
|
|
|
Methods:
|
|
|
|
--------
|
2017-02-04 08:26:57 -06:00
|
|
|
* __init__(stream_type)
|
2016-05-12 22:19:48 -05:00
|
|
|
- This method is use to initlize the ProcessLogger class object
|
|
|
|
|
2017-02-04 08:26:57 -06:00
|
|
|
* log(msg)
|
|
|
|
- Log message in the orderly manner.
|
2016-05-12 22:19:48 -05:00
|
|
|
|
|
|
|
* run()
|
|
|
|
- Reads the stdout/stderr for messages and sent them to logger
|
|
|
|
"""
|
|
|
|
|
2017-02-04 08:26:57 -06:00
|
|
|
def __init__(self, stream_type):
|
2016-05-12 22:19:48 -05:00
|
|
|
"""
|
|
|
|
This method is use to initialize the ProcessLogger class object
|
|
|
|
|
|
|
|
Args:
|
|
|
|
stream_type: Type of STD (std)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
None
|
|
|
|
"""
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
import codecs
|
|
|
|
|
2016-05-12 22:19:48 -05:00
|
|
|
Thread.__init__(self)
|
|
|
|
self.process = None
|
|
|
|
self.stream = None
|
2022-04-26 06:11:10 -05:00
|
|
|
self.logger = open(os.path.join(_out_dir, stream_type), 'wb',
|
|
|
|
buffering=0)
|
2016-05-12 22:19:48 -05:00
|
|
|
|
|
|
|
def attach_process_stream(self, process, stream):
|
|
|
|
"""
|
|
|
|
This function will attach a process and its stream with this thread.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
process: Process
|
|
|
|
stream: Stream attached with the process
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
None
|
|
|
|
"""
|
|
|
|
self.process = process
|
|
|
|
self.stream = stream
|
|
|
|
|
2020-04-30 06:52:48 -05:00
|
|
|
def log(self, msg):
|
|
|
|
"""
|
|
|
|
This function will update log file
|
|
|
|
|
|
|
|
Args:
|
|
|
|
msg: message
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
None
|
|
|
|
"""
|
|
|
|
# Write into log file
|
|
|
|
if self.logger:
|
|
|
|
if msg:
|
|
|
|
self.logger.write(
|
|
|
|
get_current_time(
|
|
|
|
format='%y%m%d%H%M%S%f'
|
|
|
|
).encode('utf-8')
|
|
|
|
)
|
|
|
|
self.logger.write(b',')
|
|
|
|
self.logger.write(
|
|
|
|
msg.lstrip(b'\r\n' if _IS_WIN else b'\n')
|
|
|
|
)
|
|
|
|
self.logger.write(os.linesep.encode('utf-8'))
|
|
|
|
|
|
|
|
return True
|
|
|
|
return False
|
2016-05-12 22:19:48 -05:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
if self.process and self.stream:
|
|
|
|
while True:
|
|
|
|
nextline = self.stream.readline()
|
|
|
|
|
|
|
|
if nextline:
|
|
|
|
self.log(nextline)
|
|
|
|
else:
|
|
|
|
if self.process.poll() is not None:
|
|
|
|
break
|
|
|
|
|
|
|
|
def release(self):
|
|
|
|
if self.logger:
|
|
|
|
self.logger.close()
|
|
|
|
self.logger = None
|
|
|
|
|
|
|
|
|
2017-02-04 08:26:57 -06:00
|
|
|
def update_status(**kw):
|
2016-05-12 22:19:48 -05:00
|
|
|
"""
|
|
|
|
This function will updates process stats
|
|
|
|
|
|
|
|
Args:
|
|
|
|
kwargs - Process configuration details
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
None
|
|
|
|
"""
|
2017-02-04 08:26:57 -06:00
|
|
|
import json
|
2016-05-12 22:19:48 -05:00
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
if _out_dir:
|
2017-02-08 10:28:04 -06:00
|
|
|
status = dict(
|
2018-02-09 06:57:37 -06:00
|
|
|
(k, v) for k, v in kw.items()
|
|
|
|
if k in ('start_time', 'end_time', 'exit_code', 'pid')
|
2017-02-08 10:28:04 -06:00
|
|
|
)
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('Updating the status:\n{0}'.format(json.dumps(status)))
|
|
|
|
with open(os.path.join(_out_dir, 'status'), 'w') as fp:
|
2017-02-04 08:26:57 -06:00
|
|
|
json.dump(status, fp)
|
2016-05-12 22:19:48 -05:00
|
|
|
else:
|
2016-06-17 08:21:14 -05:00
|
|
|
raise ValueError("Please verify pid and db_file arguments.")
|
2016-05-12 22:19:48 -05:00
|
|
|
|
|
|
|
|
2020-08-25 02:09:14 -05:00
|
|
|
def _handle_execute_exception(ex, args, _stderr, exit_code=None):
|
|
|
|
"""
|
|
|
|
Used internally by execute to handle exception
|
|
|
|
:param ex: exception object
|
|
|
|
:param args: execute args dict
|
|
|
|
:param _stderr: stderr
|
|
|
|
:param exit_code: exit code override
|
|
|
|
"""
|
|
|
|
info = _log_exception()
|
|
|
|
if _stderr:
|
|
|
|
_stderr.log(info)
|
|
|
|
else:
|
2021-01-13 04:33:28 -06:00
|
|
|
print('WARNING: {0}'.format(str(ex)))
|
2020-08-25 02:09:14 -05:00
|
|
|
args.update({'end_time': get_current_time()})
|
|
|
|
args.update({
|
|
|
|
'exit_code': ex.errno if exit_code is None else exit_code})
|
|
|
|
|
|
|
|
|
|
|
|
def _fetch_execute_output(process, _stdout, _stderr):
|
|
|
|
"""
|
|
|
|
Used internally by execute to fetch execute output and log it.
|
|
|
|
:param process: process obj
|
|
|
|
:param _stdout: stdout
|
|
|
|
:param _stderr: stderr
|
|
|
|
"""
|
|
|
|
data = process.communicate()
|
|
|
|
if data:
|
|
|
|
if data[0]:
|
|
|
|
_stdout.log(data[0])
|
|
|
|
if data[1]:
|
|
|
|
_stderr.log(data[1])
|
|
|
|
|
|
|
|
|
2019-10-10 07:28:32 -05:00
|
|
|
def execute(argv):
|
2016-05-12 22:19:48 -05:00
|
|
|
"""
|
|
|
|
This function will execute the background process
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
None
|
|
|
|
"""
|
2019-10-10 07:28:32 -05:00
|
|
|
command = argv[1:]
|
2017-02-04 08:26:57 -06:00
|
|
|
args = dict()
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('Initialize the process execution: {0}'.format(command))
|
2017-02-04 08:26:57 -06:00
|
|
|
|
|
|
|
# Create seprate thread for stdout and stderr
|
|
|
|
process_stdout = ProcessLogger('out')
|
|
|
|
process_stderr = ProcessLogger('err')
|
|
|
|
|
|
|
|
try:
|
|
|
|
# update start_time
|
|
|
|
args.update({
|
|
|
|
'start_time': get_current_time(),
|
|
|
|
'stdout': process_stdout.log,
|
|
|
|
'stderr': process_stderr.log,
|
|
|
|
'pid': os.getpid()
|
|
|
|
})
|
|
|
|
|
|
|
|
# Update start time
|
|
|
|
update_status(**args)
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('Status updated...')
|
2017-02-04 08:26:57 -06:00
|
|
|
|
2020-08-25 02:09:14 -05:00
|
|
|
if os.environ.get(os.environ.get('PROCID', None), None):
|
2017-02-04 08:26:57 -06:00
|
|
|
os.environ['PGPASSWORD'] = os.environ[os.environ['PROCID']]
|
|
|
|
|
|
|
|
kwargs = dict()
|
|
|
|
kwargs['close_fds'] = False
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
kwargs['shell'] = True if _IS_WIN else False
|
2017-02-04 08:26:57 -06:00
|
|
|
|
|
|
|
# We need environment variables & values in string
|
2020-04-30 06:52:48 -05:00
|
|
|
kwargs['env'] = os.environ.copy()
|
2017-02-04 08:26:57 -06:00
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('Starting the command execution...')
|
2017-02-04 08:26:57 -06:00
|
|
|
process = Popen(
|
|
|
|
command, stdout=PIPE, stderr=PIPE, stdin=None, **kwargs
|
|
|
|
)
|
2018-10-22 02:05:21 -05:00
|
|
|
args.update({
|
|
|
|
'start_time': get_current_time(),
|
|
|
|
'stdout': process_stdout.log,
|
|
|
|
'stderr': process_stderr.log,
|
|
|
|
'pid': process.pid
|
|
|
|
})
|
|
|
|
update_status(**args)
|
|
|
|
_log('Status updated after starting child process...')
|
2016-05-12 22:19:48 -05:00
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('Attaching the loggers to stdout, and stderr...')
|
2017-02-04 08:26:57 -06:00
|
|
|
# Attach the stream to the process logger, and start logging.
|
|
|
|
process_stdout.attach_process_stream(process, process.stdout)
|
|
|
|
process_stdout.start()
|
|
|
|
process_stderr.attach_process_stream(process, process.stderr)
|
|
|
|
process_stderr.start()
|
|
|
|
|
|
|
|
# Join both threads together
|
|
|
|
process_stdout.join()
|
|
|
|
process_stderr.join()
|
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('Waiting for the process to finish...')
|
2017-02-04 08:26:57 -06:00
|
|
|
# Child process return code
|
2020-07-06 01:18:23 -05:00
|
|
|
exit_code = process.wait()
|
2017-02-04 08:26:57 -06:00
|
|
|
|
2020-07-06 01:18:23 -05:00
|
|
|
if exit_code is None:
|
|
|
|
exit_code = process.poll()
|
2017-02-04 08:26:57 -06:00
|
|
|
|
2020-07-06 01:18:23 -05:00
|
|
|
_log('Process exited with code: {0}'.format(exit_code))
|
|
|
|
args.update({'exit_code': exit_code})
|
2017-02-04 08:26:57 -06:00
|
|
|
|
|
|
|
# Add end_time
|
|
|
|
args.update({'end_time': get_current_time()})
|
|
|
|
|
|
|
|
# Fetch last output, and error from process if it has missed.
|
2020-08-25 02:09:14 -05:00
|
|
|
_fetch_execute_output(process, process_stdout, process_stderr)
|
2017-02-04 08:26:57 -06:00
|
|
|
|
|
|
|
# If executable not found or invalid arguments passed
|
2019-10-10 07:28:32 -05:00
|
|
|
except OSError as e:
|
2020-08-25 02:09:14 -05:00
|
|
|
_handle_execute_exception(e, args, process_stderr, exit_code=None)
|
2017-02-04 08:26:57 -06:00
|
|
|
# Unknown errors
|
2020-05-08 03:43:32 -05:00
|
|
|
except Exception as e:
|
2020-08-25 02:09:14 -05:00
|
|
|
_handle_execute_exception(e, args, process_stderr, exit_code=-1)
|
2017-02-04 08:26:57 -06:00
|
|
|
finally:
|
|
|
|
# Update the execution end_time, and exit-code.
|
|
|
|
update_status(**args)
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('Exiting the process executor...')
|
2017-02-04 08:26:57 -06:00
|
|
|
if process_stderr:
|
|
|
|
process_stderr.release()
|
|
|
|
if process_stdout:
|
|
|
|
process_stdout.release()
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('Bye!')
|
2017-02-04 08:26:57 -06:00
|
|
|
|
|
|
|
|
|
|
|
def signal_handler(signal, msg):
|
2020-07-24 01:16:30 -05:00
|
|
|
# Let's ignore all the signal comming to us.
|
2017-02-04 08:26:57 -06:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def convert_environment_variables(env):
|
|
|
|
"""
|
|
|
|
This function is use to convert environment variable to string
|
|
|
|
because environment variable must be string in popen
|
|
|
|
:param env: Dict of environment variable
|
|
|
|
:return: Encoded environment variable as string
|
|
|
|
"""
|
|
|
|
temp_env = dict()
|
|
|
|
for key, value in env.items():
|
2016-05-14 13:33:21 -05:00
|
|
|
try:
|
2017-02-04 08:26:57 -06:00
|
|
|
if not isinstance(key, str):
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
key = key.encode(_sys_encoding)
|
|
|
|
if not isinstance(value, str):
|
|
|
|
value = value.encode(_sys_encoding)
|
2017-02-04 08:26:57 -06:00
|
|
|
temp_env[key] = value
|
2018-02-09 06:57:37 -06:00
|
|
|
except Exception:
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log_exception()
|
2017-02-04 08:26:57 -06:00
|
|
|
return temp_env
|
2016-05-12 22:19:48 -05:00
|
|
|
|
|
|
|
|
2017-02-04 08:26:57 -06:00
|
|
|
if __name__ == '__main__':
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
|
2019-10-10 07:28:32 -05:00
|
|
|
argv = [
|
|
|
|
unescape_dquotes_process_arg(arg) for arg in sys.argv
|
|
|
|
]
|
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_sys_encoding = sys.getdefaultencoding()
|
|
|
|
if not _sys_encoding or _sys_encoding == 'ascii':
|
|
|
|
# Fall back to 'utf-8', if we couldn't determine the default encoding,
|
|
|
|
# or 'ascii'.
|
|
|
|
_sys_encoding = 'utf-8'
|
|
|
|
|
|
|
|
_fs_encoding = sys.getfilesystemencoding()
|
|
|
|
if not _fs_encoding or _fs_encoding == 'ascii':
|
2018-02-09 06:57:37 -06:00
|
|
|
# Fall back to 'utf-8', if we couldn't determine the file-system
|
|
|
|
# encoding or 'ascii'.
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_fs_encoding = 'utf-8'
|
|
|
|
|
2020-07-06 01:18:23 -05:00
|
|
|
_out_dir = os.environ['OUTDIR']
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log_file = os.path.join(_out_dir, ('log_%s' % os.getpid()))
|
|
|
|
|
|
|
|
_log('Starting the process executor...')
|
2017-02-04 08:26:57 -06:00
|
|
|
|
|
|
|
# Ignore any signals
|
|
|
|
signal.signal(signal.SIGINT, signal_handler)
|
|
|
|
signal.signal(signal.SIGTERM, signal_handler)
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('Disabled the SIGINT, SIGTERM signals...')
|
2017-02-04 08:26:57 -06:00
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
if _IS_WIN:
|
|
|
|
_log('Disable the SIGBREAKM signal (windows)...')
|
2017-02-04 08:26:57 -06:00
|
|
|
signal.signal(signal.SIGBREAK, signal_handler)
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('Disabled the SIGBREAKM signal (windows)...')
|
2017-02-04 08:26:57 -06:00
|
|
|
|
|
|
|
# For windows:
|
|
|
|
# We would run the process_executor in the detached mode again to make
|
|
|
|
# the child process to run as a daemon. And, it would run without
|
|
|
|
# depending on the status of the web-server.
|
|
|
|
if 'PGA_BGP_FOREGROUND' in os.environ and \
|
2018-02-09 06:57:37 -06:00
|
|
|
os.environ['PGA_BGP_FOREGROUND'] == "1":
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('[CHILD] Start process execution...')
|
2017-02-04 08:26:57 -06:00
|
|
|
# This is a child process running as the daemon process.
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
# Let's do the job assigning to it.
|
|
|
|
try:
|
|
|
|
_log('Executing the command now from the detached child...')
|
2019-10-10 07:28:32 -05:00
|
|
|
execute(argv)
|
2018-02-09 06:57:37 -06:00
|
|
|
except Exception:
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log_exception()
|
2017-02-04 08:26:57 -06:00
|
|
|
else:
|
|
|
|
from subprocess import CREATE_NEW_PROCESS_GROUP
|
|
|
|
DETACHED_PROCESS = 0x00000008
|
|
|
|
|
|
|
|
# Forward the standard input, output, and error stream to the
|
|
|
|
# 'devnull'.
|
|
|
|
stdin = open(os.devnull, "r")
|
|
|
|
stdout = open(os.devnull, "a")
|
|
|
|
stderr = open(os.devnull, "a")
|
|
|
|
env = os.environ.copy()
|
|
|
|
env['PGA_BGP_FOREGROUND'] = "1"
|
|
|
|
|
|
|
|
# We need environment variables & values in string
|
2018-02-09 06:57:37 -06:00
|
|
|
_log('[PARENT] Converting the environment variable in the '
|
|
|
|
'bytes format...')
|
2016-05-15 11:59:14 -05:00
|
|
|
try:
|
2017-02-04 08:26:57 -06:00
|
|
|
env = convert_environment_variables(env)
|
2018-02-09 06:57:37 -06:00
|
|
|
except Exception:
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log_exception()
|
2017-02-04 08:26:57 -06:00
|
|
|
|
|
|
|
kwargs = {
|
|
|
|
'stdin': stdin.fileno(),
|
|
|
|
'stdout': stdout.fileno(),
|
|
|
|
'stderr': stderr.fileno(),
|
|
|
|
'creationflags': CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS,
|
|
|
|
'close_fds': False,
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
'cwd': _out_dir,
|
2018-02-09 06:57:37 -06:00
|
|
|
'env': env
|
2017-02-04 08:26:57 -06:00
|
|
|
}
|
2016-05-12 22:19:48 -05:00
|
|
|
|
2017-02-04 08:26:57 -06:00
|
|
|
cmd = [sys.executable]
|
2019-10-10 07:28:32 -05:00
|
|
|
cmd.extend(argv)
|
2016-05-12 22:19:48 -05:00
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('[PARENT] Command executings: {0}'.format(cmd))
|
2016-05-12 22:19:48 -05:00
|
|
|
|
2017-02-04 08:26:57 -06:00
|
|
|
p = Popen(cmd, **kwargs)
|
2016-05-12 22:19:48 -05:00
|
|
|
|
2017-02-04 08:26:57 -06:00
|
|
|
exitCode = p.poll()
|
|
|
|
|
|
|
|
if exitCode is not None:
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log(
|
2017-02-04 08:26:57 -06:00
|
|
|
'[PARENT] Child exited with exit-code#{0}...'.format(
|
|
|
|
exitCode
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('[PARENT] Started the child with PID#{0}'.format(p.pid))
|
2017-02-04 08:26:57 -06:00
|
|
|
|
|
|
|
# Question: Should we wait for sometime?
|
|
|
|
# Answer: Looks the case...
|
|
|
|
from time import sleep
|
|
|
|
sleep(2)
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('[PARENT] Exiting...')
|
2017-02-04 08:26:57 -06:00
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
r, w = os.pipe()
|
|
|
|
|
|
|
|
# For POSIX:
|
|
|
|
# We will fork the process, and run the child process as daemon, and
|
|
|
|
# let it do the job.
|
|
|
|
if os.fork() == 0:
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('[CHILD] Forked the child process...')
|
2017-02-04 08:26:57 -06:00
|
|
|
# Hmm... So - I need to do the job now...
|
|
|
|
try:
|
|
|
|
os.close(r)
|
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('[CHILD] Make the child process leader...')
|
2017-02-04 08:26:57 -06:00
|
|
|
# Let me be the process leader first.
|
|
|
|
os.setsid()
|
|
|
|
os.umask(0)
|
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('[CHILD] Make the child process leader...')
|
2017-02-04 08:26:57 -06:00
|
|
|
w = os.fdopen(w, 'w')
|
|
|
|
# Let me inform my parent - I will do the job, do not worry
|
|
|
|
# now, and die peacefully.
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('[CHILD] Inform parent about successful child forking...')
|
2017-02-04 08:26:57 -06:00
|
|
|
w.write('1')
|
|
|
|
w.close()
|
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('[CHILD] Start executing the background process...')
|
2019-10-10 07:28:32 -05:00
|
|
|
execute(argv)
|
2017-02-04 08:26:57 -06:00
|
|
|
except Exception:
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log_exception()
|
2017-02-04 08:26:57 -06:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
os.close(w)
|
|
|
|
r = os.fdopen(r)
|
|
|
|
# I do not care, what the child send.
|
|
|
|
r.read()
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('[PARENT] Got message from the child...')
|
2017-02-04 08:26:57 -06:00
|
|
|
r.close()
|
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_log('[PARENT] Exiting...')
|
2017-02-04 08:26:57 -06:00
|
|
|
sys.exit(0)
|