forked from enlightenment/efl
pyolian: Add helper functions for simple scripts
Summary: These two functions encapsulate some code that commonly is repeated through pyolian scripts. With these, a minimal example (provided `src/scripts/pyolian` is in the PYTHONPATH) could be done with: ``` import os from pyolian import eolian SCAN_FOLDER = os.path.join(eolian.in_tree_src_dir(), 'src', 'lib') eolian_db = eolian.parse_folders(SCAN_FOLDER) for cls in eolian_db.classes: print(cls) ``` Reviewers: segfaultxavi, DaveMDS, felipealmeida Reviewed By: felipealmeida Subscribers: cedric, #reviewers, #committers, felipealmeida, brunobelo Tags: #efl Differential Revision: https://phab.enlightenment.org/D10589
This commit is contained in:
parent
abaa90cfc2
commit
bb3f741990
|
@ -23,6 +23,7 @@ a way that this folder will be available on PYTHON_PATH, fe:
|
|||
from pyolian.generator import Template
|
||||
|
||||
"""
|
||||
import os
|
||||
from enum import IntEnum
|
||||
import atexit
|
||||
from ctypes import cast, byref, c_char_p, c_void_p, c_int
|
||||
|
@ -520,6 +521,44 @@ class Eolian_State(Eolian_Unit):
|
|||
return bool(lib.eolian_state_check(self))
|
||||
|
||||
|
||||
# Helper functions ###################################################
|
||||
|
||||
def parse_folders(folders):
|
||||
"""Loads a new database scanning the given folders.
|
||||
|
||||
For example:
|
||||
|
||||
SCAN_FOLDER = os.path.join(eolian.in_tree_src_dir(), 'src', 'lib')
|
||||
eolian_db = eolian.parse_folders(SCAN_FOLDER)
|
||||
"""
|
||||
|
||||
db = Eolian_State()
|
||||
if not isinstance(db, Eolian_State):
|
||||
raise (RuntimeError('Eolian, failed to create Eolian state'))
|
||||
|
||||
if isinstance(folders, str):
|
||||
folders = [folders]
|
||||
|
||||
for folder in folders:
|
||||
# eolian source tree scan
|
||||
if not db.directory_add(folder):
|
||||
raise (RuntimeError('Eolian, failed to scan source dirsectory'))
|
||||
|
||||
# Parse all known eo files
|
||||
if not db.all_eot_files_parse():
|
||||
raise (RuntimeError('Eolian, failed to parse all EOT files'))
|
||||
|
||||
if not db.all_eo_files_parse():
|
||||
raise (RuntimeError('Eolian, failed to parse all EO files'))
|
||||
|
||||
return db
|
||||
|
||||
def in_tree_src_dir():
|
||||
"""Returns the root folder of this script's source tree"""
|
||||
script_path = os.path.dirname(os.path.realpath(__file__))
|
||||
return os.path.abspath(os.path.join(script_path, '..', '..', '..'))
|
||||
|
||||
|
||||
# Namespace Utility Class ###################################################
|
||||
|
||||
class Namespace(object):
|
||||
|
|
Loading…
Reference in New Issue