Exemplo n.º 1
0
  def init_home_dir(cls, home_dir):
    """Initializes passed home directory if such wasn't already initialized.

    :returns: Path to home directory.
    """
    if not path_utils.exists(home_dir):
      raise IOError("'%s' doesn't exist" % home_dir)
    settings_dir = path_utils.join(home_dir, SETTINGS_DIR)
    path_utils.mkpath(settings_dir)
    return home_dir
Exemplo n.º 2
0
 def buildpath(self, path, recursive=True):
   """Path will be created if it doesn't exist."""
   if typecheck.is_list(path):
     path = path_utils.join(*path)
   elif not typecheck.is_string(path):
     raise TypeError("path can be only a string or list")
   path = path_utils.join(self.get_build_dir(), path)
   if path_utils.exists(path):
     return path
   return path_utils.touch(path, recursive=recursive)
Exemplo n.º 3
0
  def is_home_dir(cls, path):
    """Returns whether or not a given path is application home directory.

    :returns: `True` or `False`.
    :raises: :class:`TypeError`, :class:`IOError`
    """
    if not typecheck.is_string(path):
      raise TypeError("'path' has to be a string")
    elif not path_utils.exists(path):
      raise IOError("'%s' path doesn't exist" % path)
    return SETTINGS_DIR in os.listdir(path)
Exemplo n.º 4
0
  def set_build_dir(self, path, make=False):
    """Sets path to the build directory. The build directory will be used to
    store temporary/autogenerated and compiled build-files.

    :param path: Build-directory name.
    :param make: Whether or not the path needs to be created.
    """
    if not path_utils.exists(path):
      if not make:
        raise IOError("`%s' doesn't exist" % path)
      path_utils.mkpath(path)
    self._build_dir = path
Exemplo n.º 5
0
  def _set_home_dir(self, home_dir):
    """Set application home directory. There should be no other applications
    registered to this home directory.

    :param home_dir: A string that represents path to home directory. The path
       should exists.

    :raises: :class:`IOError`
    """
    if not path_utils.exists(home_dir):
      raise IOError("`%s' doesn't exist" % home_dir)
    self._home_dir = home_dir
Exemplo n.º 6
0
 def execute(self):
   print("Load propeller binary: %s" % self)
   self.resolve()
   if not self._binary or not path_utils.exists(self._binary):
     raise IOError()
   uploader = propler.SPIUploader(port=self.get_port(),
                                  baudrate=self._baudrate)
   if not uploader.connect():
     return
   uploader.upload_file(self._binary, eeprom=self._eeprom)
   if self._terminal_mode:
     propler.terminal_mode(port=self.get_port(), baudrate=self._baudrate)
   uploader.disconnect()
Exemplo n.º 7
0
  def add_file(self, path):
    """Adds file to the list of files. The path will be normalized by using
    :func:`os.path.abspath`.

    :param path: A string that represents file path.

    :returns: A normalized string path.

    :raises: TypeError
    """
    if typecheck.is_string(path):
      if not path_utils.exists(path):
        caller_frame = inspect.getouterframes(inspect.currentframe(), 2)
        filename = inspect.getsourcefile(caller_frame[2][0])
        possible_dir = path_utils.dirname(filename)
        alternative_path = path_utils.join(possible_dir, path)
        if path_utils.exists(alternative_path):
          return self.add_file(alternative_path)
      path = path_utils.abspath(path)
      if not path_utils.exists(path):
        raise Exception("Path doesn't exist: %s" % path)
      if not path in self._files:
        self._files.append(path)
      return path
    elif typecheck.is_callable(path):
      result = path()
      if not result:
        return
      elif typecheck.is_list(result):
        self.add_files(result)
      else:
        self.add_file(result)
    elif not path:
      return None
    else:
      raise TypeError("Unknown path type '%s' of '%s'" % (type(path), path))
Exemplo n.º 8
0
  def set_home_dir(self, home_dir):
    """Set application home directory. There should be no other applications
    registered to this home directory.

    :param home_dir: A string that represents path to home directory. The path
       should exists.

    :raises: :class:`IOError`
    """
    if not path_utils.exists(home_dir):
      raise IOError("`%s' doesn't exist" % home_dir)
    if self._home_dir:
      self._unregister_instance(self)
    if home_dir in self._register:
      raise IOError("%s is already using this home dir: %s" %
                      (self._register[home_dir], home_dir))
    self._home_dir = home_dir
    self._register_instance(self)
Exemplo n.º 9
0
 def __init__(self, name=None, home_dir=None, init_home_dir=False, settings_dir=None):
   Object.__init__(self)
   self._name = None
   self._network = Network()
   self._home_dir = None
   self._build_dir = None
   self._settings_dir = None
   if settings_dir:
     if not path_utils.exists(settings_dir):
       raise IOError()
     self._settings_dir = settings_dir
   if home_dir:
     if not self.is_home_dir(home_dir) and init_home_dir:
       self.init_home_dir(home_dir)
     self._set_home_dir(home_dir)
   if name:
     self.set_name(name)
   elif self.get_home_dir():
     self.set_name(path_utils.basename(self.get_home_dir()))
   else:
     raise NotImplementedError()