Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ogattaz committed Jan 14, 2018
2 parents 6bb8e40 + 74ff15b commit 7e5ac54
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 37 deletions.
19 changes: 10 additions & 9 deletions python/cohorte/forker/starters/cohorte_boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,31 @@


# Standard library
import cohorte
import cohorte.forker
import cohorte.monitor
import cohorte.utils
import logging
import os
from pelix.ipopo.decorators import ComponentFactory, Requires, Provides, \
Property, Instantiate
import subprocess
import sys

import cohorte
import cohorte.forker
import cohorte.forker.starters.common as common
import cohorte.monitor
import cohorte.utils
import cohorte.version
from herald import beans
import herald
from herald.exceptions import HeraldException
import pelix.http as http
from pelix.ipopo.decorators import ComponentFactory, Requires, Provides, \
Property, Instantiate


# Pelix framework
# COHORTE modules
# Herald
# ------------------------------------------------------------------------------

# Bundle version
import cohorte.version
__version__=cohorte.version.__version__
__version__ = cohorte.version.__version__

# ------------------------------------------------------------------------------

Expand Down Expand Up @@ -182,6 +181,8 @@ def start(self, configuration, state_updater_url):
if sys.platform == "darwin"\
and configuration['kind'] in ('java', 'osgi'):
looper = 'cocoa'
elif "looper" in configuration.keys() :
looper = configuration["looper"]
else:
looper = None

Expand Down
27 changes: 16 additions & 11 deletions python/cohorte/repositories/python/ipopo.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,19 @@
import logging
import threading

# Pelix
from pelix.utilities import is_string
import cohorte.repositories
from cohorte.repositories.beans import Factory
import cohorte.version
from pelix.ipopo.decorators import ComponentFactory, Provides, Invalidate, \
Property, Requires, Validate
from pelix.utilities import is_string

# Repository beans
import cohorte.repositories
from cohorte.repositories.beans import Factory

# Pelix
# Repository beans
# ------------------------------------------------------------------------------

# Bundle version
import cohorte.version
__version__=cohorte.version.__version__
__version__ = cohorte.version.__version__

# ------------------------------------------------------------------------------

Expand Down Expand Up @@ -151,10 +150,16 @@ def _extract_module_factories(filename):
"""
visitor = ComponentFactoryVisitor()
try:
with open(filename) as filep:
with open(filename,encoding="utf8") as filep:
source = filep.read()
except (OSError, IOError) as ex:
raise ValueError("Error reading {0}: {1}".format(filename, ex))
except (OSError, IOError,TypeError) as ex:
try:
import io
with io.open(filename,encoding="utf8") as filep:
source = filep.read()
except (OSError, IOError) as ex2:
_logger.exception(ex2)
raise ValueError("Error reading {0}: {1}".format(filename, ex2))

try:
module = ast.parse(source, filename, 'exec')
Expand Down
39 changes: 22 additions & 17 deletions python/cohorte/repositories/python/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,26 @@
# Standard library
import ast
import imp
import json
import logging
import os

# ######### added by: Bassem D.
import json
# #########

# Pelix
import cohorte
import cohorte.repositories
from cohorte.repositories.beans import Artifact, Version
import cohorte.version
from pelix.ipopo.decorators import ComponentFactory, Provides, Property, \
Invalidate, Validate
from pelix.utilities import is_string

# Repository beans
import cohorte
import cohorte.repositories
from cohorte.repositories.beans import Artifact, Version

# ######### added by: Bassem D.
# #########
# Pelix
# Repository beans
# ------------------------------------------------------------------------------

# Bundle version
import cohorte.version
__version__=cohorte.version.__version__
__version__ = cohorte.version.__version__

# ------------------------------------------------------------------------------

Expand Down Expand Up @@ -187,10 +185,17 @@ def _extract_module_info(filename, module_name, is_package):
:raise ValueError: Unreadable file
"""
try:
with open(filename) as filep:
with open(filename,encoding="utf8") as filep:
source = filep.read()
except (OSError, IOError) as ex:
raise ValueError("Error reading {0}: {1}".format(filename, ex))
except (OSError, IOError,TypeError) as ex:
try:
import io
with io.open(filename,encoding="utf8") as filep:
source = filep.read()
except (OSError, IOError) as ex2:
_logger.exception(ex2)
raise ValueError("Error reading {0}: {1}".format(filename, ex))


visitor = AstVisitor(module_name, is_package)
try:
Expand Down Expand Up @@ -295,7 +300,7 @@ def __compute_name(root, filename):
# Drop extension
filename = os.path.splitext(filename)[0]
name_parts = filename.split(os.path.sep)
is_package = name_parts[len(name_parts)-1] == "__init__"
is_package = name_parts[len(name_parts) - 1] == "__init__"
if is_package:
name_parts = name_parts[:-1]
return ".".join(name_parts), is_package
Expand Down Expand Up @@ -564,7 +569,7 @@ def load_cache(self):

for directory in cache["directories"]:
self._directory_package[directory["dir_name"]] \
= directory["pkg_name"]
= directory["pkg_name"]

return True
except (IOError, ValueError):
Expand Down

0 comments on commit 7e5ac54

Please sign in to comment.