Exemplo n.º 1
0
        def get_image_list():
            images_path = WindowsPath('./images/StarWars/cards')

            filenames = []
            for name in images_path.glob('*.png'):
                filenames.append(name)

            return filenames
Exemplo n.º 2
0
def resource_serving(file):
    
    target_path = Path(BASE_DIR.joinpath("styles"), file)

    if target_path.exists() and not target_path.is_dir():

        return send_file(target_path.open(mode="rb"), attachment_filename=target_path.name)

    abort(404)
Exemplo n.º 3
0
def get():
    path = os.path.sep.join((os.path.dirname(os.path.abspath(__file__)), 'mocked_grading.html'))
    if platform.system() == 'Windows':
        path = WindowsPath(path)
    else:
        path = PosixPath(path)
    url = path.as_uri()

    return session.get(url)
Exemplo n.º 4
0
    def get_subdirlist(cls, path: str):
        """
        Return list of subdirectories

        :param path: base pathname as r'string'
        :return: list of subdirectories
        """
        wpath = WindowsPath(path)
        return [f.name for f in wpath.iterdir() if f.is_dir()]
Exemplo n.º 5
0
    def get_subdirlist(cls, path: str):
        """
        Return list of subdirectories

        :param path: base pathname as r'string'
        :return: list of subdirectories
        """
        wpath = WindowsPath(path)
        return [f.name for f in wpath.iterdir() if f.is_dir()]
Exemplo n.º 6
0
    def process_binary(self, binary):
        if isinstance(binary, list):
            return
        print("Processing {}".format(binary))

        binary = Binary(binary)
        target_file = WindowsPath(
            self.target, f"unxutils-{binary.name_without_extension}.json")
        target_content = single_binary_content(self.source_json, binary)
        target_file.write_text(json.dumps(target_content, indent=2))
Exemplo n.º 7
0
def separate(source: WindowsPath = WindowsPath('unxutils.json'),
             target: WindowsPath = WindowsPath('bucket')):
    source = WindowsPath(source)
    source_data = source.read_text()
    source_json = json.loads(source_data)

    binary_writer = BinaryWriter(source_json, target)
    with ThreadPoolExecutor() as executor:
        futures = executor.map(binary_writer.process_binary,
                               source_json['bin'])
        for _ in futures:
            pass
Exemplo n.º 8
0
def path_settings(directory):
    dest = os.getcwd()

    if system() == 'Windows':
        appdata = WindowsPath(os.getenv('APPDATA'))
        dest = appdata.joinpath(directory)
    else:
        dest = PosixPath('/etc').joinpath(directory)

    dest.mkdir(parents = True, exist_ok = True)

    return dest
Exemplo n.º 9
0
def bu_uncatalogued_photos(tranche, source_dir_path: WindowsPath,
                           destination_dir: WindowsPath,
                           backup_options: BackupOptions):
    for t in tranche:
        src = WindowsPath(source_dir_path, t)
        options_list = ["-archW"
                        ] + backup_options_to_rsync_options(backup_options)
        home = WindowsPath.home()
        cmd_list = cygwin.rsync_cmd(options_list, home, src, destination_dir)
        # buph_logger.info("bu_catalogued_photos       %s" %(" ".join(cmd_list)))
        if try_popen(cmd_list, str(WindowsPath.home())) != 0:
            raise Exception("try_popen returns rc != 0")
Exemplo n.º 10
0
    def actually_send(s: socket.socket, file: pathlib.WindowsPath):
        size = file.stat().st_size
        progress = get_progress_bar(
            f'{Fore.GREEN}Sending {file.name}{Fore.RESET}', size)
        with open(str(file.absolute()), 'rb') as f:
            for _ in progress:
                bytes_read = f.read(BUFFER_SIZE)
                if not bytes_read:
                    break

                s.sendall(bytes_read)
                progress.update(len(bytes_read))
        s.close()
Exemplo n.º 11
0
 def tree_add(self, path_object: WindowsPath, parentDir, n=0):
     line = self.indentSpace * n
     fixedName = path_object.name.replace("_", " ")
     fixedName = re.sub(r'.md$', '', fixedName)
     fixedName = fixedName.title()
     pathName = re.sub(r'.md$', '', path_object.name)
     if path_object.is_file():
         fileContent = self.fileSign.replace("%s", fixedName) + '\n'
         fileContent = fileContent.replace('%path', parentDir + pathName)
         self.tree += line + fileContent + '\n'
         return False
     elif path_object.is_dir():
         self.tree += line + self.dirSign.replace("%s", fixedName) + '\n'
         return True
Exemplo n.º 12
0
def request_api(student_comments: pd.Series,
                endpoint: str,
                num_batches: int = 50,
                save: bool = True,
                folder: WindowsPath = None) -> pd.Series:
    """Sends student comments to the LUIS.ai API in batches and saves the 
    intemediate results into the OUTPUT folder
    
    Keyword arguments
    student_comments -- the pd.Series that contains the student comments in 
        natural language
    endpoint -- the luis endpoint
    num_batches -- the number of batches into which the comments would be 
        grouped and sent to the api
    save -- a boolean that saves the raw json response to local disk
    folder -- a location to which to save the response data, defaults to 
        /OUTPUT/LUIS/
    """
    if save and folder is None:
        folder = Path.cwd().joinpath('OUTPUT').joinpath('LUIS')

    for i, batch in enumerate(np.array_split(student_comments, num_batches)):
        print(f'Processing batch {i} of {num_batches}:')

        luis_result = batch.apply(lambda x: requests.get(f'{endpoint}{x}'))

        # Saving the results to pickle
        filename = f'luis_result_{str(i).zfill(4)}'
        luis_result.to_pickle(folder.joinpath(filename))

        print(f'Saved to {folder.joinpath(filename)}.')
Exemplo n.º 13
0
def make_correct_path(root_path, file_path):
    if platform.system() == 'Windows':
        path = WindowsPath(root_path).joinpath(file_path)
        return path
    else:
        path = PurePosixPath(root_path).joinpath(file_path)
        return path
Exemplo n.º 14
0
    def _find_path(given_path: str, system="posix"):
        """Turn given path into a proper path for given system.

        Parameters
        ----------
        given_path : str
            Path to be converted
        system : str, optional
            System type for getting the path, 'posix' or 'windows'

        Returns
        -------
        Path
            Generated path obj for locating certain directory

        Raises
        ------
        ValueError
            If system offered is not suppported
        """
        if system == "posix":
            given_path = PosixPath(given_path)
        elif system == "windows":
            given_path = WindowsPath(given_path)
        else:
            raise ValueError(f"system {system} is not supported")
        return given_path
Exemplo n.º 15
0
 def test_logfile_path_expanduser(self, mock_open, mock_stdout):
     with patch.dict(os.environ, {"USERPROFILE": "C:\\foo"}):
         self.subject(["streamlink", "--logfile", "~\\bar"])
     self.write_file_and_assert(mock_mkdir=WindowsPath("C:\\foo").mkdir,
                                mock_write=mock_open("C:\\foo\\bar",
                                                     "a").write,
                                mock_stdout=mock_stdout)
Exemplo n.º 16
0
 def test_logfile_path_absolute(self, mock_open, mock_stdout):
     self.subject(["streamlink", "--logfile", "C:\\foo\\bar"])
     self.write_file_and_assert(
         mock_mkdir=WindowsPath("C:\\foo").mkdir,
         mock_write=mock_open("C:\\foo\\bar", "a").write,
         mock_stdout=mock_stdout
     )
Exemplo n.º 17
0
    def normalize(path):
        if type(path) is PurePosixPath:
            normalized_path = PurePosixPath()
        elif type(path) is PureWindowsPath:
            normalized_path = PureWindowsPath()
        elif type(path) is PosixPath:
            normalized_path = PosixPath()
        elif type(path) is WindowsPath:
            normalized_path = WindowsPath()

        # remove anchor (necessary for Windows UNC paths) and convert to relative path
        if path.is_absolute():
            path = path.relative_to(path.anchor)

        for p in path.parts:
            if p == '.':
                continue

            if p == '..':
                normalized_path = normalized_path.parent
                continue

            normalized_path /= p

        return normalized_path
Exemplo n.º 18
0
def _get_rf_location(sub_path):
    rf = RfactorPlayer(only_version=True)
    rf_path = rf.location / sub_path
    if not rf_path.exists():
        logging.error('Could not locate rF2 Setups directory in %s',
                      rf_path.as_posix())
        return
    return str(WindowsPath(rf_path))
 def tree_add(self, path_object: WindowsPath, n=0, last=False):
     if n > 0:
         if last:
             self.tree += '│' + ('    │' * (n - 1)) + '    └────' + path_object.name
         else:
             self.tree += '│' + ('    │' * (n - 1)) + '    ├────' + path_object.name
     else:
         if last:
             self.tree += '└' + ('──' * 2) + path_object.name
         else:
             self.tree += '├' + ('──' * 2) + path_object.name
     if path_object.is_file():
         self.tree += '\n'
         return False
     elif path_object.is_dir():
         self.tree += '/\n'
         return True
Exemplo n.º 20
0
def main():
    parser = argparse.ArgumentParser(
        description=
        "Extract the pixel shader HLSL from a Yakuza .pso or .fxo file")
    parser.add_argument("yakuza_file",
                        help="The file to extract from.",
                        type=windows_path_arg)
    parser.add_argument(
        "-o",
        help="The file to output. Defaults to \"ORIGINAL_FILE.pxo.hlsl\"")
    parser.add_argument(
        "-i",
        help="Ignore compilation errors for disassembled shader",
        action="store_true",
        dest="ignore")

    args = parser.parse_args()

    if not args.o:
        args.o = args.yakuza_file.with_suffix(args.yakuza_file.suffix +
                                              ".hlsl")
    output_path = WindowsPath(args.o)

    yk_file = import_yakuza_shader_file(args.yakuza_file)

    shader_assembly = decompile_shader(yk_file.get_pixel_shader_data())
    print(shader_assembly)
    dp = DisassemblyParser(shader_assembly)
    pg = ProgramGenerator()
    program = pg.build_program(dp.declarations, dp.instructions,
                               dp.input_semantics, dp.output_semantics,
                               dp.global_flags)

    try:
        flags = (1 << 11) | (1 << 21) | (1 << 15)
        compile_shader(program.get_disassembled_shader(),
                       "DISASSEMBLED_SHADER", flags)
    except DXCallError as e:
        if not args.ignore:
            reraise(
                e,
                "Got error when compiling disassembled shader, use -i to ignore."
                + "\n{}")

    with output_path.open("w") as f:
        f.write(program.get_disassembled_shader())
Exemplo n.º 21
0
 def direction_ergodic(self, path_object: WindowsPath, parentDir, n=0):
     dir_file: list = list(path_object.iterdir())
     dir_file.sort(key=lambda x: x.name.lower())
     for item in dir_file:
         if self.ignore_judge(item.name):
             if self.tree_add(item, parentDir, n):
                 self.direction_ergodic(item, parentDir + item.name + "/",
                                        n + 1)
Exemplo n.º 22
0
def refold_dir(path: pathlib.WindowsPath, newer_path: pathlib.WindowsPath):
    for p in path.iterdir():
        if p.is_dir():
            refold_dir(p, newer_path)
        else:

            if not checkdir(p):  # 下层无目录,则为最底层目录,移动
                shutil.move(p, newer_path)
            return
def import_yakuza_shader_file(path: WindowsPath) -> 'YkShaderFile':
    byte_data = None
    with path.open("rb") as f:
        byte_data = bytearray(f.read())
    if not byte_data or len(byte_data) < 4:
        raise YkError(f"Couldn't open {path} and extract >4 bytes.")

    return FirstPossibleOf([YkPixelShaderFile, YkEffectShaderFile],
                           [YkError])(byte_data)
Exemplo n.º 24
0
def listup_content_path() -> List[Path]:
    parent = WindowsPath('D:/aozorabunko/cards')
    files = list(parent.glob('**/*.html'))

    # 適当にピック
    RAND_MAX = 300
    DOUBLE_PICK_THR = 10
    count = 0
    until = randrange(1, RAND_MAX)
    pickup_files = []
    for file in files:
        if until == count:
            until = randrange(1, RAND_MAX)
            if until % DOUBLE_PICK_THR == 0:  # たまには2つ連続で取りたい
                until = 1
            pickup_files.append(file)
            count = 0
        count += 1
    return pickup_files
Exemplo n.º 25
0
def open_in_browser():
    maps_file_path = Path(str(path.cwd()) + '/places.html')
    if maps_file_path.exists():
        try:
            browser.open_new_tab(str(maps_file_path))
        #            print("Opening browser...")
        except browser.Error:
            print('Something went wrong...')
    else:
        print('File, places.html has not been created!')
Exemplo n.º 26
0
    def warehouse():
        if platform.system() == 'Windows':
            out_dir = Path(WindowsPath.home() / "Documents" / "Data")
            out_dir.mkdir(parents=True, exist_ok=True)
        else:
            # out_dir = Path(Path.home() / "Documents" / "Data")
            out_dir = Path("/mnt/c/Users/morris/Documents/Data")
            out_dir.mkdir(parents=True, exist_ok=True)

        return out_dir
Exemplo n.º 27
0
def checksubProcess():
    command = 'ls -ltr'
    # output = subprocess.check_output(['‪C:\\Program Files\\Git\\git-bash.exe','-c', command])
    cmd = "find . -maxdepth 1 -type f  -name '*Resume*' | awk '{print $0}'"
    dirForShell = WindowsPath(r'C:\Users\Ranjit\Downloads')
    output = subprocess.run(['C:\Program Files\Git\\bin\\bash.exe', '-c', cmd],
                            capture_output=True,
                            cwd=dirForShell)
    print(output.stdout.decode())
    print(os.listdir(dirForShell))
Exemplo n.º 28
0
def _libcmark():
    system = platform.system()

    if system == 'Darwin':
        return 'libcmark.dylib'

    if system == 'Windows':
        binary_dependencies = WindowsPath(__file__).parents[1] / 'binary_dependencies'
        return str(binary_dependencies / 'cmark.dll')

    return 'libcmark.so'
Exemplo n.º 29
0
def load_estimators(path: WindowsPath) -> List[Tuple]:
    """
    Returns a list of estimators for the VotingClassifier
    """
    estimator_list = []
    for suffix in ['*.joblib', '*.sav']:
        for filepath in path.glob(suffix):
            print(f'Loading {filepath.name}')
            estimator_list.append((filepath.stem, load(filepath)))

    return estimator_list
Exemplo n.º 30
0
    def save_artist_json(self):
        """
            Save artist json objects to file for logging/testing.
        """

        fixture_path = WindowsPath(base_dir / r'test/fixtures')
        with open(fixture_path / 'spotify_artists.json', 'w') as f:
            json.dump(self.artist_response, f)

        with open(fixture_path / 'spotify_track_ids.json', 'w') as f:
            json.dump(self.track_response, f)
Exemplo n.º 31
0
 def direction_ergodic(self, path_object: WindowsPath, n=0):
     dir_file: list = list(path_object.iterdir())
     dir_file.sort(key=lambda x: x.name.lower())
     dir_file = [f for f in filter(self.filter_file, dir_file)]
     for i, item in enumerate(dir_file):
         if i + 1 == len(dir_file):
             if self.tree_add(item, n, last=True):
                 self.direction_ergodic(item, n + 1)
         else:
             if self.tree_add(item, n, last=False):
                 self.direction_ergodic(item, n + 1)
Exemplo n.º 32
0
def run_exercice(num_ex: str):
    """This function runs exercice num_ex"""
    print("Running exercice n°", num_ex)
    ex_path = WindowsPath("./metarch/exercices/exercice1/" + num_ex + ".py")

    t = Path(".")
    all_python_files_in_subdirs = list(t.glob("**/*.py"))

    if ex_path in all_python_files_in_subdirs:
        print(os.system(str(ex_path)))

    pass