Changeset 7989:a7708829e5bf in orange


Ignore:
Timestamp:
06/08/11 16:01:11 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
2518b65f27a844639637438d357e1520b3e80a2c
Message:

Ported orngEnviron to the new hierarchy.
Added .cfg file based configuration.
Added a default orangerc.cfg configuration file.

Location:
orange
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/__init__.py

    r7905 r7989  
    1313    try: 
    1414        __import__(name, globals(), locals(), [], -1) 
    15     except: 
     15    except Exception: 
    1616        warnings.warn("Could not import: " + name, UserWarning, 2) 
    1717 
     
    8282 
    8383_import("misc") 
     84_import("misc.environ") 
    8485_import("misc.counters") 
    8586_import("misc.addons") 
  • orange/orngEnviron.py

    r6984 r7989  
    1 # coding=utf-8 
    2 import os, sys 
    3 from zipfile import ZipFile 
    4 import urllib 
     1import Orange.misc.environ as environ 
    52 
    6 if os.name == "nt": 
    7     paths = os.environ["PATH"].split(";") 
    8     paths.sort(lambda x,y: -1 if "PyQt4" in x else (1 if "miktex" in y and os.path.exists(os.path.join(y, "QtCore4.dll")) else 0)) 
    9     os.environ["PATH"] = ";".join(paths) 
    10      
    11 if sys.platform == "darwin": 
    12     ## PyQt4 installed from fink is installed in %{FINK_ROOT}lib/qt4-mac/lib/python${PYVERSION}/site-packages" 
    13     posible_fink_pyqt4_path = os.path.join(sys.prefix, "lib/qt4-mac/lib/python" + sys.version[:3] + "/site-packages") 
    14     if os.path.exists(posible_fink_pyqt4_path): 
    15         sys.path.append(posible_fink_pyqt4_path)  
    16  
    17 def __getDirectoryNames(): 
    18     """Return a dictionary with Orange directories.""" 
    19     try: 
    20         orangeDir = os.path.split(os.path.abspath(__file__))[0] 
    21     except: 
    22         import orange 
    23         orangeDir = os.path.split(os.path.abspath(orange.__file__))[0] 
    24  
    25     orangeDocDir = os.path.join(orangeDir, "doc") 
    26     #TODO This might be redefined in orngConfiguration. 
    27  
    28     try: 
    29         orangeVer = orangeDir.split(os.path.sep)[-1] 
    30     except: 
    31         orangeVer = "orange" 
    32  
    33     canvasDir = os.path.join(orangeDir, "OrangeCanvas") 
    34     widgetDir = os.path.join(orangeDir, "OrangeWidgets") 
    35     picsDir = os.path.join(widgetDir, "icons") 
    36     addOnsDirSys = os.path.join(orangeDir, "add-ons") 
    37  
    38     if not os.path.isdir(widgetDir) or not os.path.isdir(widgetDir): 
    39         canvasDir = None 
    40         widgetDir = None 
    41     if not os.path.isdir(picsDir): 
    42         picsDir = "" 
    43  
    44     home = os.path.expanduser("~") 
    45      
    46     if home[-1] == ":": 
    47         home += "\\" 
    48     if os.name == "nt": 
    49         applicationDir = os.environ["APPDATA"] #os.path.join(home, "Application Data") 
    50         if not os.path.isdir(applicationDir): 
    51             try: os.makedirs(applicationDir) 
    52             except: pass 
    53         outputDir = os.path.join(applicationDir, orangeVer)                  # directory for saving settings and stuff 
    54         defaultReportsDir = os.path.join(home, "My Documents", "Orange Reports") 
    55     elif sys.platform == "darwin": 
    56         applicationDir = os.path.join(home, "Library", "Application Support") 
    57         if not os.path.isdir(applicationDir): 
    58             try: os.makedirs(applicationDir) 
    59             except: pass 
    60         outputDir = os.path.join(applicationDir, orangeVer) 
    61         defaultReportsDir = os.path.join(home, "Library/Application Support/orange/Reports") 
    62     else: 
    63         outputDir = os.path.join(home, "."+orangeVer)                  # directory for saving settings and stuff 
    64         defaultReportsDir = os.path.join(home, "orange-reports") 
    65  
    66     addOnsDirUser = os.path.join(outputDir, "add-ons") 
    67  
    68     orangeSettingsDir = outputDir 
    69     if sys.platform == "darwin": 
    70         bufferDir = os.path.join(home, "Library", "Caches", orangeVer) 
    71     else: 
    72         bufferDir = os.path.join(outputDir, "buffer") 
    73     canvasSettingsDir = os.path.join(outputDir, "OrangeCanvasQt4") if canvasDir <> None else None 
    74     widgetSettingsDir = os.path.join(outputDir, "widgetSettingsQt4") if widgetDir <> None else None 
    75  
    76     for dname in [orangeSettingsDir, bufferDir, widgetSettingsDir, canvasSettingsDir, defaultReportsDir]: 
    77         if dname <> None and not os.path.isdir(dname): 
    78             try: os.makedirs(dname)        # Vista has roaming profiles that will say that this folder does not exist and will then fail to create it, because it exists... 
    79             except: pass 
    80  
    81     return dict([(name, vars()[name]) for name in ["orangeDir", "orangeDocDir", "canvasDir", "widgetDir", "picsDir", "addOnsDirSys", "addOnsDirUser", "defaultReportsDir", "orangeSettingsDir", "widgetSettingsDir", "canvasSettingsDir", "bufferDir"]]) 
    82  
    83 def samepath(path1, path2): 
    84     return os.path.normcase(os.path.normpath(path1)) == os.path.normcase(os.path.normpath(path2)) 
    85  
    86 def addOrangeDirectoriesToPath(): 
    87     """Add orange directory paths to Python path.""" 
    88     pathsToAdd = [orangeDir] 
    89  
    90     if canvasDir <> None: 
    91         pathsToAdd.append(canvasDir) 
    92  
    93     if widgetDir <> None and os.path.isdir(widgetDir): 
    94         pathsToAdd.append(widgetDir) 
    95         defaultWidgetsDirs = [os.path.join(widgetDir, x) for x in os.listdir(widgetDir) if os.path.isdir(os.path.join(widgetDir, x))] 
    96         pathsToAdd.extend(defaultWidgetsDirs) 
    97  
    98     for path in pathsToAdd: 
    99         if os.path.isdir(path) and not any([samepath(path, x) for x in sys.path]): 
    100             sys.path.insert(0, path) 
    101  
    102 directoryNames = __getDirectoryNames() 
     3directoryNames = dict( 
     4    orangeDir = environ.install_dir, 
     5    orangeDocDir = environ.doc_install_dir, 
     6    orangeVer = environ.version, 
     7    canvasDir = environ.canvas_install_dir, 
     8    widgetDir = environ.widget_install_dir, 
     9    picsDir = environ.icons_install_dir, 
     10    addOnsDirSys = environ.add_ons_dir, 
     11    addOnsDirUser = environ.add_ons_dir_user, 
     12    applicationDir = environ.application_dir, 
     13    outputDir = environ.output_dir, 
     14    defaultReportsDir = environ.default_reports_dir, 
     15    orangeSettingsDir = environ.orange_settings_dir, 
     16    widgetSettingsDir = environ.widget_settings_dir, 
     17    canvasSettingsDir = environ.canvas_settings_dir, 
     18    bufferDir = environ.buffer_dir 
     19    ) 
    10320globals().update(directoryNames) 
    10421 
    105 addOrangeDirectoriesToPath() 
     22samepath = environ.samepath 
     23addOrangeDirectoriesToPath = environ.add_orange_directories_to_path 
  • orange/setup.py

    r7929 r7989  
    434434                      "OrangeWidgets.Unsupervised": ["icons/*.png"], 
    435435                      "OrangeWidgets.Visualize": ["icons/*.png"], 
    436                       "doc": ["datasets/*.tab", ] 
     436                      "doc": ["datasets/*.tab", ], 
     437                      ".": ["orangerc.cfg"]  
    437438                      }, 
    438439      ext_modules = [include_ext, orange_ext, orangeom_ext, orangene_ext, corn_ext, statc_ext], 
Note: See TracChangeset for help on using the changeset viewer.