def test_normcase(self):
        # Check that normcase() is idempotent
        p = "FoO/./BaR"
        p = posixpath.normcase(p)
        self.assertEqual(p, posixpath.normcase(p))

        self.assertRaises(TypeError, posixpath.normcase)
Exemplo n.º 2
0
    def test_normcase(self):
        # Check that normcase() is idempotent
        p = "FoO/./BaR"
        p = posixpath.normcase(p)
        self.assertEqual(p, posixpath.normcase(p))

        self.assertRaises(TypeError, posixpath.normcase)
Exemplo n.º 3
0
    def map2platform(self, path, target_platform=None):
        """Map paths of from the source i.e. current platform to the
        target platform. Supported plaforms are linux, win32 and darwin.

        The method does not perform any sanity checks wether the path exists
        on the current or target platform. It simply replaces the substrings of
        the current path, defined in mapping table.

        The new path is normalized using the xx.normcase method (x is replaced
        either by ntpath or posixpath).
        """

        if target_platform is None:
            target_platform = self.target_platform

        if target_platform not in ("linux", "linux2", "darwin", "win32"):
            raise RuntimeError("Target platform not supported!")

        platform = sys.platform
        if platform == target_platform:
            return path

        mapping = AppPreferences().mapping

        path_mapped = None


        for k, v in mapping[platform].iteritems():
            if platform == target_platform:
                path_mapped = path
                break

            elif path.find(k) == 0:
                path_mapped = path.replace(k, v[target_platform])
                break

        if path_mapped is None:
            pass
        elif target_platform.startswith("win"):
            path_mapped = ntpath.normcase(path_mapped)
        # OSX 10.X and linux
        else:
            path_mapped = posixpath.normcase(path_mapped)
            path_mapped = path_mapped.replace(ntpath.sep, posixpath.sep)
        return path_mapped
Exemplo n.º 4
0
    def map2platform(self, path, target_platform=None):
        """Map paths of from the source i.e. current platform to the
        target platform. Supported plaforms are linux, win32 and darwin.

        The method does not perform any sanity checks wether the path exists
        on the current or target platform. It simply replaces the substrings of
        the current path, defined in mapping table.

        The new path is normalized using the xx.normcase method (x is replaced
        either by ntpath or posixpath).
        """

        if target_platform is None:
            target_platform = self.target_platform

        if target_platform not in ("linux", "linux2", "darwin", "win32"):
            raise RuntimeError("Target platform not supported!")

        platform = sys.platform
        if platform == target_platform:
            return path

        mapping = AppPreferences().mapping

        path_mapped = None

        for k, v in mapping[platform].iteritems():
            if platform == target_platform:
                path_mapped = path
                break

            elif path.find(k) == 0:
                path_mapped = path.replace(k, v[target_platform])
                break

        if path_mapped is None:
            pass
        elif target_platform.startswith("win"):
            path_mapped = ntpath.normcase(path_mapped)
        # OSX 10.X and linux
        else:
            path_mapped = posixpath.normcase(path_mapped)
            path_mapped = path_mapped.replace(ntpath.sep, posixpath.sep)
        return path_mapped
Exemplo n.º 5
0
def _resolve(stdp: Path, path: Path) -> Optional[Path]:
    if path.is_absolute():
        if path.exists():
            return path
        else:
            u_p = Path(expanduser(path))
            if u_p != path and u_p.exists():
                return u_p
            else:
                v_p = Path(expandvars(path))
                if v_p != path and v_p.exists():
                    return v_p
                else:
                    return None
    else:
        if normcase(path).startswith("~"):
            return _resolve(stdp, path=Path(expanduser(path)))
        else:
            return _resolve(stdp, path=stdp / path)
Exemplo n.º 6
0
#to = "local"

#_from = "datastore"
#to = "ftp"

_from = "local"
to = "ftp"

if _from == "datastore":  #when at BIRA
    FROM_ROOT_DIRECTORY = os.path.normcase(
        r"W:\data\SATELLITE\TRACE-GAS-ORBITER\NOMAD\hdf5")
elif _from == "datastore_test":
    FROM_ROOT_DIRECTORY = os.path.normcase(
        r"W:\data\SATELLITE\TRACE-GAS-ORBITER\NOMAD\test\iant\hdf5")
elif _from == "hera":  #when at home
    FROM_ROOT_DIRECTORY = posixpath.normcase(
        r"/bira-iasb/data/SATELLITE/TRACE-GAS-ORBITER/NOMAD/hdf5")
elif _from == "hera_test":
    FROM_ROOT_DIRECTORY = posixpath.normcase(
        r"/bira-iasb/data/SATELLITE/TRACE-GAS-ORBITER/NOMAD/hdf5/test/ian")
elif _from == "local":
    FROM_ROOT_DIRECTORY = os.path.normcase(
        r"C:\Users\iant\Documents\DATA\hdf5_copy")

if to == "local":
    TO_ROOT_DIRECTORY = os.path.normcase(
        r"C:\Users\iant\Documents\DATA\hdf5_copy")
elif to == "ftp":
    TO_ROOT_DIRECTORY = posixpath.normcase(r"/Data")

server = ["hera.oma.be", "iant"]
password = ""
Exemplo n.º 7
0
async def envsubst() -> None:
    ascii = {*ascii_letters, *{"_", "-"}}
    j2 = build(_TEMPLATES)

    if git := which("git"):
        p1, p2, p3, p4 = await gather(
            call(
                git,
                "--exec-path",
                capture_stderr=False,
            ),
            call(
                git,
                "--info-path",
                capture_stderr=False,
            ),
            call(
                git,
                "--no-optional-locks",
                "rev-parse",
                "--show-toplevel",
                capture_stderr=False,
            ),
            call(
                git,
                "--no-optional-locks",
                "rev-parse",
                "--git-common-dir",
                capture_stderr=False,
            ),
        )

        gitweb_src = Path(p2.out.decode()).parent / "gitweb"
        top_level = Path(p3.out.decode().rstrip())
        title = "".join(char if char in ascii else "-" for char in top_level.name)

        git_dir = top_level / p4.out.decode().rstrip()
        gitweb_dst = git_dir / "gitweb"

        cwd = gitweb_dst / "python"
        cgi_bin = cwd / "cgi-bin"
        cgi_bin.mkdir(parents=True, exist_ok=True)

        with suppress(FileExistsError):
            (cgi_bin / "gitweb.cgi").symlink_to(gitweb_src / "gitweb.cgi")
        with suppress(FileExistsError):
            (cgi_bin / "static").symlink_to(gitweb_src / "static")

        script = gitweb_dst / "gitweb_config.perl"
        script_env = {
            "TOP_LEVEL": top_level,
            "TMP": gitweb_dst / "tmp",
            "TITLE": title,
        }
        perl = render(j2, PurePath(script.name), env=script_env)
        script.write_text(perl)

        env = {
            "GIT_EXEC_PATH": normcase(p1.out.decode()),
            "GITWEB_CONFIG": normcase(script),
            "GIT_DIR": normcase(git_dir),
        }
        environ.update(env)
        chdir(cwd)
Exemplo n.º 8
0
SEARCH IN ALL .PY FILES FOR A STRING
"""

import os
import glob
import posixpath

SEARCH_STRING = 'label="Pixel %i'

from tools.file.paths import paths

os.chdir(paths["BASE_DIRECTORY"])

#list all py files
file_list = glob.glob(posixpath.normcase(paths["BASE_DIRECTORY"]) + "/**/*.py",
                      recursive=True)

excluded_strings = ["search_py_v01.py", "django", "old_scripts"]

found = False

#load .py files one by one
for file in file_list:

    #check for excluded strings
    if not any([string in file for string in excluded_strings]):

        line_number = 0
        with open(file, "r", errors='ignore') as f:
            file_lines = f.readlines()
Exemplo n.º 9
0
def _variable_substitution(context: ParserCtx, *, var_name: str) -> Optional[str]:
    ctx = context.ctx
    row, _ = ctx.position
    c_lhs, c_rhs = context.info.comment_str
    path = PurePath(ctx.filename)

    if var_name == "TM_SELECTED_TEXT":
        return context.info.visual

    elif var_name == "TM_CURRENT_LINE":
        return ctx.line

    elif var_name == "TM_CURRENT_WORD":
        return ctx.words

    elif var_name == "TM_LINE_INDEX":
        return str(row)

    elif var_name == "TM_LINE_NUMBER":
        return str(row + 1)

    elif var_name == "TM_FILENAME":
        return path.name

    elif var_name == "TM_FILENAME_BASE":
        return path.stem

    elif var_name == "TM_DIRECTORY":
        return normcase(path.parent)

    elif var_name == "TM_FILEPATH":
        return normcase(path)

    elif var_name == "RELATIVE_FILEPATH":
        try:
            return normcase(path.relative_to(ctx.cwd))
        except ValueError:
            return None

    elif var_name == "CLIPBOARD":
        return context.info.clipboard

    elif var_name == "WORKSPACE_NAME":
        return ctx.cwd.name

    elif var_name == "WORKSPACE_FOLDER":
        return normcase(ctx.cwd)

    # Randomv value related
    elif var_name == "RANDOM":
        return "".join(choices(digits, k=6))

    elif var_name == "RANDOM_HEX":
        return "".join(choices(tuple({*hexdigits.upper()}), k=6))

    elif var_name == "UUID":
        return str(uuid4())

    # Date/time related
    elif var_name == "CURRENT_YEAR":
        return datetime.now().strftime("%Y")

    elif var_name == "CURRENT_YEAR_SHORT":
        return datetime.now().strftime("%y")

    elif var_name == "CURRENT_MONTH":
        return datetime.now().strftime("%m")

    elif var_name == "CURRENT_MONTH_NAME":
        return datetime.now().strftime("%B")

    elif var_name == "CURRENT_MONTH_NAME_SHORT":
        return datetime.now().strftime("%b")

    elif var_name == "CURRENT_DATE":
        return datetime.now().strftime("%d")

    elif var_name == "CURRENT_DAY_NAME":
        return datetime.now().strftime("%A")

    elif var_name == "CURRENT_DAY_NAME_SHORT":
        return datetime.now().strftime("%a")

    elif var_name == "CURRENT_HOUR":
        return datetime.now().strftime("%H")

    elif var_name == "CURRENT_MINUTE":
        return datetime.now().strftime("%M")

    elif var_name == "CURRENT_SECOND":
        return datetime.now().strftime("%S")

    elif var_name == "CURRENT_SECONDS_UNIX":
        return str(round(datetime.now().timestamp()))

    elif var_name == "BLOCK_COMMENT_START":
        return c_lhs if c_lhs and c_rhs else None

    elif var_name == "BLOCK_COMMENT_END":
        return c_rhs if c_lhs and c_rhs else None

    elif var_name == "LINE_COMMENT":
        return (c_lhs or None) if not c_rhs else None

    else:
        return None
Exemplo n.º 10
0
 def update_event(self, inp=-1):
     self.set_output_val(0, posixpath.normcase(self.input(0)))