Example #1
0
def load_pgnd_options():
    global PGND_OPTIONS
    PGND_OPTIONS = configparser.SafeConfigParser()
    try:
        PGND_OPTIONS.read(_PGND_CFG_FILE_PATH)
    except configparser.ParsingError as edata:
        return CmdResult.error(stderr=_("Error reading playground options: {0}\n").format(str(edata)))
    return CmdResult.ok()
Example #2
0
def load_global_options():
    global GLOBAL_OPTIONS
    GLOBAL_OPTIONS = configparser.SafeConfigParser()
    try:
        GLOBAL_OPTIONS.read(_GLOBAL_CFG_FILE_PATH)
    except configparser.ParsingError as edata:
        return CmdResult.error(stderr=_("Error reading global options: {0}\n").format(str(edata)))
    return CmdResult.ok()
Example #3
0
def os_create_dir(dir_path):
    _CONSOLE_LOG.start_cmd("mkdir -p " + dir_path)
    try:
        os.makedirs(dir_path)
        result = CmdResult.ok()
    except OSError as edata:
        result = CmdResult.error(str(edata))
    _CONSOLE_LOG.end_cmd(result)
    return result
Example #4
0
def check_for_overwrites(destn_file_paths):
    from aipoed import utils
    overwritten = [file_path for file_path in destn_file_paths if os.path.exists(file_path)]
    if overwritten:
        stderr = _("File(s):\n")
        for file_path in overwritten:
            stderr += "\t{0}\n".format(utils.quote_if_needed(file_path))
        return CmdResult.error(stderr=stderr + _("will be overwritten!\n")) | Suggestion.OVERWRITE_OR_RENAME
    return CmdResult.ok()
Example #5
0
 def _move_or_copy_fs_item(self, do_copy, fsi_path):
     get_target = lambda suggestion: self.ask_file_path(
         _("New Path"), suggestion=suggestion)
     target = get_target(fsi_path)
     if target:
         op = os_utils.os_copy_fs_item if do_copy else os_utils.os_move_fs_item
         do_op = lambda destn, overwrite=False, force=False: op(
             fsi_path, destn, overwrite=overwrite, force=force)
         return self.do_op_rename_overwrite_force_or_cancel(
             target, do_op, get_target)
     return CmdResult.ok()
Example #6
0
def launch_external_diff(file_a, file_b):
    extdiff = options.get("diff", "extdiff")
    if not extdiff:
        return CmdResult.warning(_("No external diff viewer is defined.\n"))
    try:
        runext.run_cmd_in_bgnd([extdiff, file_a, file_b])
    except OSError as edata:
        return CmdResult.error(
            stderr=_("Error launching external viewer \"{0}\": {1}\n").format(
                extdiff, edata.strerror))
    return CmdResult.ok()
Example #7
0
 def _move_or_copy_fs_items(self, do_copy, fsi_paths):
     if len(fsi_paths) == 1:
         return self._move_or_copy_fs_item(do_copy, fsi_paths[0])
     get_target = lambda suggestion=None: self.ask_dir_path(
         _("Target Directory Path"), suggestion=suggestion)
     target = get_target()
     if target:
         op = os_utils.os_copy_fs_items if do_copy else os_utils.os_move_fs_items
         do_op = lambda destn, overwrite=False, force=False: op(
             fsi_paths, destn, overwrite=overwrite, force=force)
         return self.do_op_rename_overwrite_force_or_cancel(
             target, do_op, get_target)
     return CmdResult.ok()
Example #8
0
def os_move_or_copy_fs_item(fsi_path, destn, opsym, overwrite=False, force=False, verbose=False):
    assert opsym in (Relation.MOVED_TO, Relation.COPIED_TO), _("Invalid operation requested")
    new_path = os.path.join(destn, os.path.basename(fsi_path)) if destn.endswith(os.sep) else destn
    omsg = "{0} {1} {2}.".format(fsi_path, opsym, new_path) if verbose else ""
    _CONSOLE_LOG.start_cmd("{0} {1} {2}\n".format(fsi_path, opsym, new_path))
    if os.path.exists(new_path):
        if not overwrite:
            emsg = _("{0} \"{1}\" already exists.").format(_("Directory") if os.path.isdir(new_path) else _("File"), new_path)
            result = CmdResult.error(omsg, emsg) | Suggestion.OVERWRITE_OR_RENAME
            _CONSOLE_LOG.end_cmd(result)
            return result
        try:
            if os.path.isdir(new_path) and not os.path.islink(new_path):
                if force:
                    shutil.rmtree(new_path)
                else:
                    os.removedirs(new_path)
            else:
                os.remove(new_path)
        except OSError as edata:
            errorcode = CmdResult.ERROR | Suggestion.FORCE if edata.errno == errno.ENOTEMPTY else CmdResult.ERROR
            errmsg = _("Error: {}: \"{}\" {} \"{}\"\n").format(edata.strerror, fsi_path, opsym, new_path)
            _CONSOLE_LOG.append_stderr(errmsg)
            return CmdResult(errorcode, "", errmsg)
        except shutil.Error as edata:
            serr = _("Error: \"{0}\" {1} \"{2}\" failed.\n").format(fsi_path, opsym, new_path)
            for src_path, dest_path, reason in edata.args:
                serr += _("Error: \"{0}\" {1} \"{2}\": {3}.\n").format(src_path, opsym, dest_path, reason)
            return CmdResult.error(omsg, serr)
    try:
        if opsym is Relation.MOVED_TO:
            os.rename(fsi_path, new_path)
        elif os.path.isdir(fsi_path):
            shutil.copytree(fsi_path, new_path)
        else:
            shutil.copy2(fsi_path, new_path)
        result = CmdResult.ok(omsg)
    except OSError as edata:
        result = CmdResult.error(omsg, _("Error: \"{0}\" {1} \"{2}\" failed. {3}.\n").format(fsi_path, opsym, new_path, edata.strerror))
    except shutil.Error as edata:
        serr = _("Error: \"{0}\" {1} \"{2}\" failed.\n").format(fsi_path, opsym, new_path)
        for src_path, dest_path, reason in edata.args:
            serr += _("Error: \"{0}\" {1} \"{2}\": {3}.\n").format(src_path, opsym, dest_path, reason)
        result = CmdResult.error(omsg, serr)
    _CONSOLE_LOG.end_cmd(result)
    enotify.notify_events(E_FILE_MOVED)
    return result
Example #9
0
def os_create_file(file_path):
    """Attempt to create a file with the given file_path and report the outcome as
    a CmdResult tuple.
    1. If console is not None print report of successful creation on it.
    2. If a file with same file_path already exists fail and report a warning.
    3. If file creation fails for other reasons report an error.
    """
    _CONSOLE_LOG.start_cmd("create \"{0}\"".format(file_path))
    if not os.path.exists(file_path):
        try:
            open(file_path, 'w').close()
            enotify.notify_events(E_FILE_ADDED)
            result = CmdResult.ok()
        except (IOError, OSError) as msg:
            result = CmdResult.error(stderr="\"{0}\": {1}".format(file_path, msg))
    else:
        result = CmdResult.warning(stderr=_("\"{0}\": file already exists").format(file_path))
    _CONSOLE_LOG.end_cmd(result)
    return result
Example #10
0
def chdir(newdir):
    from aipoed import CmdResult
    events = 0
    try:
        os.chdir(newdir)
        retval = CmdResult.ok()
    except OSError as err:
        import errno
        ecode = errno.errorcode[err.errno]
        emsg = err.strerror
        retval = CmdResult.error(
            stderr="{0}: \"{1}\" : {2}".format(ecode, newdir, emsg))
        newdir = os.getcwd()
    # NB regardless of success of os.chdir() we need to check the interfaces
    from aipoed import enotify
    from aipoed import options
    from aipoed.gui.console import LOG
    from aipoed.scm.gui import ifce as scm_ifce
    scm_ifce.get_ifce()
    if scm_ifce.SCM.in_valid_pgnd:
        # move down to the root dir
        newdir = scm_ifce.SCM.get_playground_root()
        os.chdir(newdir)
        from aipoed.gui import recollect
        WorkspacePathView.append_saved_path(newdir)
        recollect.set("workspace", "last_used", newdir)
    from aipoed.pm.gui import ifce as pm_ifce
    pm_ifce.get_ifce()
    options.reload_pgnd_options()
    CURDIR = os.getcwd()
    LOG.start_cmd(_("New Working Directory: {0}\n").format(CURDIR))
    LOG.append_stdout(retval.stdout)
    LOG.append_stderr(retval.stderr)
    if scm_ifce.SCM.in_valid_pgnd:
        LOG.append_stdout('In valid repository\n')
    else:
        LOG.append_stderr('NOT in valid repository\n')
    LOG.end_cmd()
    enotify.notify_events(enotify.E_CHANGE_WD, new_wd=CURDIR)
    return retval
Example #11
0
def os_delete_fs_items(fsi_paths, events=E_FILE_DELETED, force=False):
    from aipoed import utils
    _CONSOLE_LOG.start_cmd(_('delete {0}').format(utils.quoted_join(fsi_paths)))
    serr = ""
    errorcode = CmdResult.ERROR
    for fsi_path in fsi_paths:
        try:
            if os.path.isdir(fsi_path) and not os.path.islink(fsi_path):
                if force:
                    shutil.rmtree(fsi_path)
                else:
                    os.removedirs(fsi_path)
            else:
                os.remove(fsi_path)
            _CONSOLE_LOG.append_stdout(_('Deleted: {0}\n').format(fsi_path))
        except OSError as edata:
            if edata.errno == errno.ENOTEMPTY:
                errorcode = CmdResult.ERROR | Suggestion.FORCE
            errmsg = _("Error: {}: \"{}\"\n").format(edata.strerror, fsi_path)
            serr += errmsg
            _CONSOLE_LOG.append_stderr(errmsg)
    _CONSOLE_LOG.end_cmd()
    enotify.notify_events(events)
    return CmdResult(errorcode, "", serr)  if serr else CmdResult.ok()
Example #12
0
 def _add_extra_patch_file_paths(cls, file_paths):
     patch_file_paths = cls.get_patch_files()
     ep_file_paths_set = {fp for fp in file_paths if fp not in patch_file_paths}
     if ep_file_paths_set:
         return cls.do_add_files(ep_file_paths_set)
     return CmdResult.ok()