misc: don't import memory in launch script:
launch script was importing a method from memory (fixLocalDir), but memory is importing twisted.internet.reactor which can result to a ReactorAlreadyInstalledError. This patch fixes it by moving fixLocalDir to tools/config. The launch script is now using /usr/bin/env.
This commit is contained in:
parent
6b4b0c26f9
commit
f7aad247c2
5 changed files with 51 additions and 47 deletions
6
bin/sat
6
bin/sat
|
|
@ -26,9 +26,9 @@ kill_process() {
|
|||
}
|
||||
|
||||
#We use python to parse config files
|
||||
eval `"$PYTHON" << PYTHONEND
|
||||
eval `/usr/bin/env "$PYTHON" << PYTHONEND
|
||||
from sat.core.constants import Const as C
|
||||
from sat.memory.memory import fixLocalDir
|
||||
from sat.tools.config import fixLocalDir
|
||||
from configparser import ConfigParser
|
||||
from os.path import expanduser, join
|
||||
import sys
|
||||
|
|
@ -100,4 +100,4 @@ if [ ! -d $log_dir ] ; then
|
|||
mkdir $log_dir
|
||||
fi
|
||||
|
||||
exec $PYTHON $TWISTD $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE
|
||||
exec /usr/bin/env $PYTHON $TWISTD $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ log = getLogger(__name__)
|
|||
import os.path
|
||||
import copy
|
||||
from collections import namedtuple
|
||||
from configparser import ConfigParser, NoOptionError, NoSectionError
|
||||
from uuid import uuid4
|
||||
from twisted.python import failure
|
||||
from twisted.internet import defer, reactor, error
|
||||
|
|
@ -221,36 +220,6 @@ class PasswordSessions(ProfileSessions):
|
|||
)
|
||||
|
||||
|
||||
# XXX: tmp update code, will be removed in the future
|
||||
# When you remove this, please add the default value for
|
||||
# 'local_dir' in sat.core.constants.Const.DEFAULT_CONFIG
|
||||
def fixLocalDir(silent=True):
|
||||
"""Retro-compatibility with the previous local_dir default value.
|
||||
|
||||
@param silent (boolean): toggle logging output (must be True when called from sat.sh)
|
||||
"""
|
||||
user_config = ConfigParser()
|
||||
try:
|
||||
user_config.read(C.CONFIG_FILES)
|
||||
except:
|
||||
pass # file is readable but its structure if wrong
|
||||
try:
|
||||
current_value = user_config.get("DEFAULT", "local_dir")
|
||||
except (NoOptionError, NoSectionError):
|
||||
current_value = ""
|
||||
if current_value:
|
||||
return # nothing to do
|
||||
old_default = "~/.sat"
|
||||
if os.path.isfile(os.path.expanduser(old_default) + "/" + C.SAVEFILE_DATABASE):
|
||||
if not silent:
|
||||
log.warning(
|
||||
_(
|
||||
"A database has been found in the default local_dir for previous versions (< 0.5)"
|
||||
)
|
||||
)
|
||||
tools_config.fixConfigOption("", "local_dir", old_default, silent)
|
||||
|
||||
|
||||
class Memory(object):
|
||||
"""This class manage all the persistent information"""
|
||||
|
||||
|
|
@ -266,7 +235,8 @@ class Memory(object):
|
|||
self.subscriptions = {}
|
||||
self.auth_sessions = PasswordSessions() # remember the authenticated profiles
|
||||
self.disco = Discovery(host)
|
||||
fixLocalDir(False) # XXX: tmp update code, will be removed in the future
|
||||
# XXX: tmp update code, will be removed in the future
|
||||
tools_config.fixLocalDir(False)
|
||||
self.config = tools_config.parseMainConf()
|
||||
database_file = os.path.expanduser(
|
||||
os.path.join(self.getConfig("", "local_dir"), C.SAVEFILE_DATABASE)
|
||||
|
|
|
|||
|
|
@ -70,6 +70,35 @@ def fixConfigOption(section, option, value, silent=True):
|
|||
config_file=target_file))
|
||||
|
||||
|
||||
# XXX: tmp update code, will be removed in the future
|
||||
# When you remove this, please add the default value for
|
||||
# 'local_dir' in sat.core.constants.Const.DEFAULT_CONFIG
|
||||
def fixLocalDir(silent=True):
|
||||
"""Retro-compatibility with the previous local_dir default value.
|
||||
|
||||
@param silent (boolean): toggle logging output (must be True when called from sat.sh)
|
||||
"""
|
||||
user_config = ConfigParser()
|
||||
try:
|
||||
user_config.read(C.CONFIG_FILES)
|
||||
except:
|
||||
pass # file is readable but its structure if wrong
|
||||
try:
|
||||
current_value = user_config.get("DEFAULT", "local_dir")
|
||||
except (NoOptionError, NoSectionError):
|
||||
current_value = ""
|
||||
if current_value:
|
||||
return # nothing to do
|
||||
old_default = "~/.sat"
|
||||
if os.path.isfile(os.path.expanduser(old_default) + "/" + C.SAVEFILE_DATABASE):
|
||||
if not silent:
|
||||
log.warning(_(
|
||||
"A database has been found in the default local_dir for previous "
|
||||
"versions (< 0.5)"
|
||||
))
|
||||
fixConfigOption("", "local_dir", old_default, silent)
|
||||
|
||||
|
||||
def parseMainConf():
|
||||
"""look for main .ini configuration file, and parse it"""
|
||||
config = ConfigParser(defaults=C.DEFAULT_CONFIG)
|
||||
|
|
|
|||
6
setup.py
6
setup.py
|
|
@ -70,8 +70,10 @@ def sat_dev_version():
|
|||
rev=version.node[1:],
|
||||
distance=version.distance)
|
||||
|
||||
return {'version_scheme': version_scheme,
|
||||
'local_scheme': local_scheme}
|
||||
return {
|
||||
'version_scheme': version_scheme,
|
||||
'local_scheme': local_scheme
|
||||
}
|
||||
|
||||
|
||||
setup(
|
||||
|
|
|
|||
|
|
@ -17,16 +17,6 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from twisted.internet import defer
|
||||
if defer.Deferred.debug:
|
||||
# if we are in debug mode, we want to use ipdb instead of pdb
|
||||
try:
|
||||
import ipdb
|
||||
import pdb
|
||||
pdb.set_trace = ipdb.set_trace
|
||||
pdb.post_mortem = ipdb.post_mortem
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from zope.interface import implementer
|
||||
from twisted.python import usage
|
||||
|
|
@ -56,9 +46,22 @@ class SatMaker:
|
|||
description = _("%s XMPP client backend") % C.APP_NAME_FULL
|
||||
options = Options
|
||||
|
||||
def setDebugger(self):
|
||||
from twisted.internet import defer
|
||||
if defer.Deferred.debug:
|
||||
# if we are in debug mode, we want to use ipdb instead of pdb
|
||||
try:
|
||||
import ipdb
|
||||
import pdb
|
||||
pdb.set_trace = ipdb.set_trace
|
||||
pdb.post_mortem = ipdb.post_mortem
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
def makeService(self, options):
|
||||
from twisted.internet import gireactor
|
||||
gireactor.install()
|
||||
self.setDebugger()
|
||||
# XXX: SAT must be imported after log configuration, because it write stuff to logs
|
||||
initialise(options.parent)
|
||||
from sat.core.sat_main import SAT
|
||||
|
|
|
|||
Loading…
Reference in a new issue