summaryrefslogtreecommitdiff
path: root/src/scripts/pyolian
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-11-26 11:56:41 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-11-26 12:40:32 -0300
commitbb3f741990dee47292c23936c05b80326ea49e45 (patch)
treea5406d7d49d9ceb5d997c9e061e58503b7359425 /src/scripts/pyolian
parentabaa90cfc20529f1507864e7b2d38ef69a16ded4 (diff)
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
Diffstat (limited to 'src/scripts/pyolian')
-rw-r--r--src/scripts/pyolian/eolian.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/scripts/pyolian/eolian.py b/src/scripts/pyolian/eolian.py
index eababfadba..e7681208c7 100644
--- a/src/scripts/pyolian/eolian.py
+++ b/src/scripts/pyolian/eolian.py
@@ -23,6 +23,7 @@ a way that this folder will be available on PYTHON_PATH, fe:
23 from pyolian.generator import Template 23 from pyolian.generator import Template
24 24
25""" 25"""
26import os
26from enum import IntEnum 27from enum import IntEnum
27import atexit 28import atexit
28from ctypes import cast, byref, c_char_p, c_void_p, c_int 29from ctypes import cast, byref, c_char_p, c_void_p, c_int
@@ -520,6 +521,44 @@ class Eolian_State(Eolian_Unit):
520 return bool(lib.eolian_state_check(self)) 521 return bool(lib.eolian_state_check(self))
521 522
522 523
524# Helper functions ###################################################
525
526def parse_folders(folders):
527 """Loads a new database scanning the given folders.
528
529 For example:
530
531 SCAN_FOLDER = os.path.join(eolian.in_tree_src_dir(), 'src', 'lib')
532 eolian_db = eolian.parse_folders(SCAN_FOLDER)
533 """
534
535 db = Eolian_State()
536 if not isinstance(db, Eolian_State):
537 raise (RuntimeError('Eolian, failed to create Eolian state'))
538
539 if isinstance(folders, str):
540 folders = [folders]
541
542 for folder in folders:
543 # eolian source tree scan
544 if not db.directory_add(folder):
545 raise (RuntimeError('Eolian, failed to scan source dirsectory'))
546
547 # Parse all known eo files
548 if not db.all_eot_files_parse():
549 raise (RuntimeError('Eolian, failed to parse all EOT files'))
550
551 if not db.all_eo_files_parse():
552 raise (RuntimeError('Eolian, failed to parse all EO files'))
553
554 return db
555
556def in_tree_src_dir():
557 """Returns the root folder of this script's source tree"""
558 script_path = os.path.dirname(os.path.realpath(__file__))
559 return os.path.abspath(os.path.join(script_path, '..', '..', '..'))
560
561
523# Namespace Utility Class ################################################### 562# Namespace Utility Class ###################################################
524 563
525class Namespace(object): 564class Namespace(object):