Ejemplo n.º 1
0
def scan_workflows(debug_imports):
    workflows = []
    warnings.simplefilter("ignore")
    UnitRegistry.enabled = False
    root_dir = root.common.dirs.veles
    for path, _, files in os.walk(root_dir, followlinks=True):
        relpath = os.path.relpath(path, root_dir)
        skip = False
        for bdir in BLACKLISTED_DIRS:
            if relpath.startswith(bdir):
                skip = True
                break
        if skip:
            continue
        for f in set(files) - BLACKLISTED_FILES:
            f_path = os.path.join(path, f)
            modname, ext = os.path.splitext(f)
            if ext != '.py':
                continue
            if debug_imports:
                sys.stdout.write("[%s] importing %s... " % (relpath, modname))
            mod = try_to_import_file(f_path)
            if not is_module(mod):
                if debug_imports:
                    print("SKIP (import)")
                continue
            for func in dir(mod):
                if func == "run" and \
                        getargspec(mod.run).args == ["load", "main"]:
                    wf_path = os.path.relpath(f_path, root_dir)
                    workflows.append(os.path.abspath(wf_path))
                    if debug_imports:
                        print("OK")
                    break
            else:
                if debug_imports:
                    print("SKIP (run)")
    gc.collect()
    warnings.simplefilter("default")
    print("Found %d workflows:\n" % len(workflows), workflows)
    # Fix ResourceWarning on /dev/null
    from IPython.utils.io import devnull
    devnull.close()
    if len(threading.enumerate()) > 1:
        print("Warning: more than 1 thread is currently running, a join lock "
              "may happen.")
    return workflows
Ejemplo n.º 2
0
def scan_workflows(debug_imports):
    workflows = []
    warnings.simplefilter("ignore")
    UnitRegistry.enabled = False
    root_dir = root.common.dirs.veles
    for path, _, files in os.walk(root_dir, followlinks=True):
        relpath = os.path.relpath(path, root_dir)
        skip = False
        for bdir in BLACKLISTED_DIRS:
            if relpath.startswith(bdir):
                skip = True
                break
        if skip:
            continue
        for f in set(files) - BLACKLISTED_FILES:
            f_path = os.path.join(path, f)
            modname, ext = os.path.splitext(f)
            if ext != '.py':
                continue
            if debug_imports:
                sys.stdout.write("[%s] importing %s... " % (relpath, modname))
            mod = try_to_import_file(f_path)
            if not is_module(mod):
                if debug_imports:
                    print("SKIP (import)")
                continue
            for func in dir(mod):
                if func == "run" and \
                        getargspec(mod.run).args == ["load", "main"]:
                    workflows.append(f_path)
                    if debug_imports:
                        print("OK")
                    break
            else:
                if debug_imports:
                    print("SKIP (run)")
    gc.collect()
    warnings.simplefilter("default")
    print("Found %d workflows:\n" % len(workflows), workflows)
    # Fix ResourceWarning on /dev/null
    from IPython.utils.io import devnull
    devnull.close()
    if len(threading.enumerate()) > 1:
        print("Warning: more than 1 thread is currently running, a join lock "
              "may happen.")
    return workflows
Ejemplo n.º 3
0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

███████████████████████████████████████████████████████████████████████████████
"""


from IPython.config.loader import Config
from IPython.terminal.embed import InteractiveShellEmbed
from IPython.utils.io import devnull
devnull.close()
import select
import sys
from zope.interface import implementer

from veles.distributable import TriviallyDistributable
from veles.units import Unit, IUnit


@implementer(IUnit)
class Shell(Unit, TriviallyDistributable):
    """
    Runs embedded IPython
    """
    BANNER1 = "\nVELES interactive console"
    BANNER2 = "Type in 'workflow' or 'units' to start"