Esempio n. 1
0
def find_executable(executable):
    """Finds the specified executable in the PATH or known good locations."""

    # Figure out what we're looking for.
    if platform.system() == "Windows":
        executable = executable + ".exe"
        extra_dirs = []
    else:
        extra_dirs = ["/usr/local/bin"]

    # Figure out what paths to check.
    path_env = os.environ.get("PATH", None)
    if path_env is not None:
        paths_to_check = path_env.split(os.path.pathsep)
    else:
        paths_to_check = []

    # Add in the extra dirs
    paths_to_check.extend(extra_dirs)
    if len(paths_to_check) < 1:
        raise os.OSError(
            "executable was not specified, PATH has no "
            "contents, and there are no extra directories to search")

    result = _find_file_in_paths(paths_to_check, executable)

    if not result or len(result) < 1:
        raise os.OSError(
            "failed to find exe='{0!s}' in paths='{1!s}'".format(executable, paths_to_check))
    return result
Esempio n. 2
0
    def getImages(self):
        '''
        게시글 별 섬네일 이미지를 다운로드 하고, 저장된 파일 위치를 반환 합니다.

        이미지 저장 위치는 "images/ppomppu/" 폴더 아래에 현재
        "년-월-일_시간_분" 폴더를 만들고, 그 아래에 저장 됩니다.
        '''
        imgLinks = self.getImageLinks()

        # image/ppomppu 아래에 현재 시간("년-월-일_시간_분")으로 폴더 만들기
        now = datetime.now().isoformat()
        day_hour_minute = now[:10] + "_" + now[11:13] + "-" + now[14:16]
        path = "images/ppompu/" + day_hour_minute
        try:
            if not os.path.exists(path):
                os.makedirs(path)
        except:
            raise os.OSError("(%s) 디렉토리를 만들 수 없습니다!" % (path))

        images = []

        for src in imgLinks:
            img = getDownload(src)
            imgName = src.split("/")[-1].split("?")[0]

            fileName = path + "/" + imgName

            with open(fileName, "wb") as f:
                f.write(img.content)
                images.append(fileName)

        return images
Esempio n. 3
0
def copy_file(src, dst):
    # apfs clone?
    try:
        clonefile = ctypes.CDLL(None, use_errno=True).clonefile
        clonefile.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int]
    except Exception:
        raise
        shutil.copyfile(src, dst)
        return
    res = clonefile(bytes(src), bytes(dst), 0)
    if res == -1 and ctypes.get_errno() != 0:
        raise os.OSError(ctypes.get_errno())
Esempio n. 4
0
def _check_sdss_files(sdss,
                      run,
                      camcol,
                      field,
                      bandname,
                      filetypes,
                      retrieve=True,
                      tryopen=False):
    from astrometry.sdss import band_index

    bandnum = band_index(bandname)
    for filetype in filetypes:
        fn = sdss.getPath(filetype, run, camcol, field, bandname)
        print('Looking for file', fn)
        exists = os.path.exists(fn)
        retrieveKwargs = {}
        if exists and tryopen:
            import pyfits
            # This doesn't catch *all* types of errors you can imagine...
            try:
                T = pyfits.open(fn)
            except:
                print('Failed to open file', fn,
                      'as FITS file: maybe corrupt.')
                exists = False
                retrieveKwargs.update(skipExisting=False)

        if (not exists) and retrieve:
            print('Retrieving', fn)
            res = sdss.retrieve(filetype, run, camcol, field, bandnum,
                                **retrieveKwargs)
            if res is False:
                raise RuntimeError('No such file on SDSS DAS: %s, ' %
                                   filetype + 'rcfb %i/%i/%i/%s' %
                                   (run, camcol, field, bandname))
        elif not exists:
            raise os.OSError('no such file: "%s"' % fn)