示例#1
0
    def workspace_dir(self):
        """
        Return the location on the filesystem for opening and closing files.

        The default is to use a directory in the users home folder, however
        in some network systems this in inaccessible. This allows a key in the
        settings file to be used to set a custom path.
        """
        sp = get_settings_path()
        workspace_dir = os.path.join(HOME_DIRECTORY, WORKSPACE_NAME)
        settings = {}
        try:
            with open(sp) as f:
                settings = json.load(f)
        except FileNotFoundError:
            logger.error('Settings file {} does not exist.'.format(sp))
        except ValueError:
            logger.error('Settings file {} could not be parsed.'.format(sp))
        else:
            if 'workspace' in settings:
                if os.path.isdir(settings['workspace']):
                    workspace_dir = settings['workspace']
                else:
                    logger.error(
                        'Workspace value in the settings file is not a valid'
                        'directory: {}'.format(settings['workspace']))
        return workspace_dir
示例#2
0
 def get_hex_path(self):
     """
     Returns the path to the hex runtime file - if this has been
     specified under element 'microbit_runtime_hex' in settings.json.
     This can be a fully-qualified file path, or just a file name
     in which case the file should be located in the workspace directory.
     Returns None if no path is specified or if the file is not present.
     """
     runtime_hex_path = None
     sp = get_settings_path()
     settings = {}
     try:
         with open(sp) as f:
             settings = json.load(f)
     except FileNotFoundError:
         logger.error('Settings file {} does not exist.'.format(sp))
     except ValueError:
         logger.error('Settings file {} could not be parsed.'.format(sp))
     else:
         if 'microbit_runtime_hex' in settings and \
                 settings['microbit_runtime_hex'] is not None:
             if os.path.exists(settings['microbit_runtime_hex']):
                 runtime_hex_path = settings['microbit_runtime_hex']
             else:
                 expected_path = settings['microbit_runtime_hex']
                 runtime_hex_path = os.path.join(self.workspace_dir(),
                                                 expected_path)
                 if not os.path.exists(runtime_hex_path):
                     runtime_hex_path = None
     return runtime_hex_path
示例#3
0
文件: base.py 项目: ZanderBrown/mu
def get_default_workspace():
    """
    Return the location on the filesystem for opening and closing files.

    The default is to use a directory in the users home folder, however
    in some network systems this in inaccessible. This allows a key in the
    settings file to be used to set a custom path.
    """
    sp = get_settings_path()
    workspace_dir = os.path.join(HOME_DIRECTORY, WORKSPACE_NAME)
    settings = {}
    try:
        with open(sp) as f:
            settings = json.load(f)
    except FileNotFoundError:
        logger.error('Settings file {} does not exist.'.format(sp))
    except ValueError:
        logger.error('Settings file {} could not be parsed.'.format(sp))
    else:
        if 'workspace' in settings:
            if os.path.isdir(settings['workspace']):
                workspace_dir = settings['workspace']
            else:
                logger.error(
                    'Workspace value in the settings file is not a valid'
                    'directory: {}'.format(settings['workspace']))
    return workspace_dir
示例#4
0
文件: microbit.py 项目: willingc/mu
 def get_hex_path(self):
     """
     Returns the path to the hex runtime file - if this has been
     specified under element 'microbit_runtime_hex' in settings.json.
     This can be a fully-qualified file path, or just a file name
     in which case the file should be located in the workspace directory.
     Returns None if no path is specified or if the file is not present.
     """
     runtime_hex_path = None
     sp = get_settings_path()
     settings = {}
     try:
         with open(sp) as f:
             settings = json.load(f)
     except FileNotFoundError:
         logger.error('Settings file {} does not exist.'.format(sp))
     except ValueError:
         logger.error('Settings file {} could not be parsed.'.format(sp))
     else:
         if 'microbit_runtime_hex' in settings and \
                 settings['microbit_runtime_hex'] is not None:
             if os.path.exists(settings['microbit_runtime_hex']):
                 runtime_hex_path = settings['microbit_runtime_hex']
             else:
                 expected_path = settings['microbit_runtime_hex']
                 runtime_hex_path = os.path.join(self.workspace_dir(),
                                                 expected_path)
                 if not os.path.exists(runtime_hex_path):
                     runtime_hex_path = None
     return runtime_hex_path
示例#5
0
文件: base.py 项目: skerr92/mu
def get_settings():
    """
    Return the JSON settings as a dictionary, which maybe empty if
    the `settings.json` file is not found or if it can not be parsed.
    """

    sp = get_settings_path()
    settings = {}
    try:
        with open(sp) as f:
            settings = json.load(f)
    except FileNotFoundError:
        logger.error("Settings file {} does not exist.".format(sp))
    except ValueError:
        logger.error("Settings file {} could not be parsed.".format(sp))

    return settings