Ejemplo n.º 1
0
def launch_file_explorer(path, files):
    '''
	Given a absolute base path and names of its children (no path), open
	up one File Explorer window with all the child files selected
	
	Taken from http://mail.python.org/pipermail/python-win32/2012-September/012533.html
	'''
    files = [os.path.basename(f) for f in files]
    # folder_pidl = shell.SHILCreateFromPath(path,0)[0]
    folder_pidl = shell.SHGetDesktopFolder().ParseDisplayName(0, 0, path)
    # folder_pidl = shell.SHParseDisplayName(path,0)[0]

    desktop = shell.SHGetDesktopFolder()
    shell_folder = desktop.BindToObject(folder_pidl, None,
                                        shell.IID_IShellFolder)
    name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, 0), item)
                                 for item in shell_folder])
    to_show = []
    for file in files:
        if name_to_item_mapping.has_key(file):
            to_show.append(name_to_item_mapping[file])
        # else:
        # raise Exception('File: "%s" not found in "%s"' % (file, path))

    shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0)
Ejemplo n.º 2
0
def show_files_win32(path, files):
    """Takes a path to a directory and a list of filenames in that directory
    to display.

    Returns True on success.
    """

    assert os.name == "nt"

    import pywintypes
    from win32com.shell import shell

    assert is_fsnative(path)
    assert all(is_fsnative(f) for f in files)

    normalized_files = map(normalize_path, files)

    try:
        folder_pidl = shell.SHILCreateFromPath(path, 0)[0]
        desktop = shell.SHGetDesktopFolder()
        shell_folder = desktop.BindToObject(
            folder_pidl, None, shell.IID_IShellFolder)
        items = []
        for item in shell_folder:
            name = desktop.GetDisplayNameOf(item, 0)
            if normalize_path(name) in normalized_files:
                items.append(item)
        shell.SHOpenFolderAndSelectItems(folder_pidl, items, 0)
    except pywintypes.com_error:
        return False
    else:
        return True
Ejemplo n.º 3
0
def launch_file_explorer(path, files=None):
    '''
	Given a absolute base path and names of its children (no path), open
	up one File Explorer window with all the child files selected
	
	Taken from http://mail.python.org/pipermail/python-win32/2012-September/012533.html
	'''
    if not files:
        path, files = os.path.split(path)
        files = [files]
    else:
        files = [os.path.basename(f) for f in files]

    if sys.getwindowsversion().major == 5:  #if windows xp
        folder_pidl = shell.SHILCreateFromPath(path, 0)[0]
        desktop = shell.SHGetDesktopFolder()
        shell_folder = desktop.BindToObject(folder_pidl, None,
                                            shell.IID_IShellFolder)
        name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, 0), item)
                                     for item in shell_folder])
        to_show = []
        for f in files:
            if name_to_item_mapping.has_key(f):
                to_show.append(name_to_item_mapping[f])
            # else:
            # raise Exception('f: "%s" not found in "%s"' % (f, path))

        shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0)
    else:  # no SHILCreateFromPath in windows 7
        f = os.path.join(path, files[0])
        f_mbcs = f.encode('mbcs')
        if os.path.exists(f_mbcs):
            os.system(r'explorer /select,"%s"' % f_mbcs)
        else:
            os.startfile(path)
Ejemplo n.º 4
0
 def selectfiles(show):
     folders = defaultdict(list)
     for p in show:
         folders[os.path.dirname(p)].append(os.path.basename(p))
     for path, files in folders.iteritems():
         files = set(os.path.splitext(f)[0] for f in files) | set(files)
         folder = shell.SHILCreateFromPath(path, 0)[0]
         desktop = shell.SHGetDesktopFolder()
         shell_folder = desktop.BindToObject(folder, None, shell.IID_IShellFolder)
         shell.SHOpenFolderAndSelectItems(
             folder,
             [item for item in shell_folder if desktop.GetDisplayNameOf(item, 0) in files],
             0)
     return 0
Ejemplo n.º 5
0
 def open(self):
     i = len(self.__fl) - 1
     r = ""
     while i >= 0:
         fn = self.__fl[i]
         if exists(fn) and isfile(fn):
             r = fn
             break
         i = i - 1
     if r != "":
         if system() == "Windows":
             if self.__logg is not None:
                 self.__logg.write(f"Try open '{r}'.", currentframe(),
                                   "Auto Open File List Open")
             d = shell.SHParseDisplayName(r, 0)
             shell.SHOpenFolderAndSelectItems(d[0], [], 0)
Ejemplo n.º 6
0
def launch_file_explorer(pathes):
    '''Given a list of Path up one File Explorer window
       per folder with all the child files selected'''

    folders = defaultdict(list)
    for p in pathes:
        folders[str(p.parent)].append(p.name)

    for path, files in folders.items():
        folder_pidl = shell.SHILCreateFromPath(path, 0)[0]
        desktop = shell.SHGetDesktopFolder()
        shell_folder = desktop.BindToObject(folder_pidl, None,
                                            shell.IID_IShellFolder)
        name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, 0), item)
                                     for item in shell_folder])
        to_show = []
        for file in files:
            if not file in name_to_item_mapping:
                wx.LogMessage('File: "%s" not found in "%s"' % (file, path))
                continue
            to_show.append(name_to_item_mapping[file])
        shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0)
Ejemplo n.º 7
0
def loginwithqrcode(r: requests.Session, logg=None):
    print(lan['WARN1'])
    prepareSession(r)
    year = 365 * 24 * 3600
    while True:
        url = "https://passport.bilibili.com/qrcode/getLoginUrl"
        if logg:
            logg.write(f"GET {url}", currentframe(), "getloginurl")
        re = r.get(url)
        re = re.json()
        if re['code'] != 0:
            print(f"{re['code']}")
            if logg:
                logg.write(f"content: {re}", currentframe(), "unknownerror")
            return -1
        ts = re['ts']
        oauthKey = re['data']['oauthKey']
        oauthUrl = re['data']['url']
        if not exists('Temp/'):
            mkdir('Temp/')
        qr = QRCode(version=1,
                    error_correction=qrconst.ERROR_CORRECT_H,
                    box_size=10)
        qr.add_data(oauthUrl)
        pn = f'Temp/{ts}.svg'
        qr.make_image(SvgImage).save(pn)
        print(lan['OUTPUT3'].replace("<path>", pn))  # 二维码已保存至
        if system() == "Windows":
            from win32com.shell import shell  # pylint: disable=import-error no-name-in-module
            d = shell.SHParseDisplayName(abspath(pn), 0)
            shell.SHOpenFolderAndSelectItems(d[0], [], 0)
        suc = False
        while not suc:
            re = r.post("https://passport.bilibili.com/qrcode/getLoginInfo",
                        data={
                            "oauthKey": oauthKey,
                            "gourl": ""
                        })
            re = re.json()
            if re['status']:
                url = re['data']['url']
                for (key, value) in parse_qsl(urlsplit(url).query):
                    if key != "gourl" and key != "Expires":
                        r.cookies.set(key,
                                      value,
                                      path="/",
                                      domain=".bilibili.com",
                                      expires=round(time.time() + year),
                                      discard=False)
                suc = True
                if exists(pn):
                    try:
                        remove(pn)
                    except:
                        pass
                break
            else:
                if re['data'] == -4:
                    time.sleep(3)
                    if time.time() > ts + 300:
                        if exists(pn):
                            try:
                                remove(pn)
                            except:
                                pass
                        input(lan['OUTPUT4'])
                        break
                elif re['data'] == -2:
                    if exists(pn):
                        try:
                            remove(pn)
                        except:
                            pass
                    input(lan['OUTPUT4'])
                    break
                else:
                    if exists(pn):
                        try:
                            remove(pn)
                        except:
                            pass
                    print(f"{re['data']} {re['message']}")
                    return -1
        if suc:
            sa = []
            for domain in r.cookies._cookies.keys():
                for path in r.cookies._cookies[domain].keys():
                    for cookiename in r.cookies._cookies[domain][path]:
                        cookie = r.cookies._cookies[domain][path][cookiename]
                        if not cookie.discard:
                            sa.append({
                                "name": cookie.name,
                                "value": cookie.value,
                                'domain': cookie.domain,
                                'path': cookie.path
                            })
            return sa