Example #1
0
def populateProgramList():
    shortcuts = {}
    programpaths = {}

    user_programs = winshell.programs()
    for dirpath, dirnames, filenames in os.walk(user_programs):
        relpath = dirpath[1 + len(user_programs):]
        shortcuts.setdefault(relpath, []).extend(
            [winshell.shortcut(os.path.join(dirpath, f)) for f in filenames])

    all_programs = winshell.programs(common=1)
    for dirpath, dirnames, filenames in os.walk(all_programs):
        relpath = dirpath[1 + len(all_programs):]
        shortcuts.setdefault(relpath, []).extend(
            [winshell.shortcut(os.path.join(dirpath, f)) for f in filenames])

    for relpath, lnks in sorted(shortcuts.items()):
        level = relpath.count("\\")
        if level == 0:
            print("")
        #print("%s+ %s" % ("    " * level, relpath))

        for lnk in lnks:
            name, _ = os.path.splitext(os.path.basename(lnk.lnk_filepath))
            #print("%s* %s -> %s" % ("    " * (level + 1), name, lnk.path))
            programpaths[name] = lnk.lnk_filepath

    programpaths = sorted(programpaths.items())
    '''
    for program, path in programpaths:
        if '.exe' in path:
            print(program)
            print(path)
    '''
    return programpaths
def getAllApplicationsRPi():
    system_progs = traverseSubdirectories(
        r'C:\ProgramData\Microsoft\Windows\Start Menu\Programs')
    user_progs = traverseSubdirectories(winshell.programs())
    all_programs = system_progs + user_progs

    # flatten 2D array to 1D array
    from functools import reduce
    all_programs_list = reduce(lambda x, y: x + y, all_programs)

    all_programs_list_rpi = []

    for prog in all_programs_list:
        try:
            if prog['icon_path'] is not None:
                string = ImageWriter.iconTo64String(prog['icon_path'])
                jason = {
                    "name": prog['name'],
                    "exe_path": prog['exe_path'],
                    "icon_path": string
                }

                all_programs_list_rpi.append(jason)
        except:
            pass
    return json.dumps(all_programs_list_rpi, separators=(',', ':'))
Example #3
0
 def on_modified(self, event):
   for filename in os.listdir(folder_to_track):
     if filename == 'Games':
       continue
     if filename == 'desktop.ini':
       continue
     if filename.startswith('~'):
       continue
     if filename.startswith('.'):
       continue
     if not filename.endswith('.lnk'):
       # create_shortcut()
       program_files = winshell.programs()
       target = f'{folder_to_track}{filename}'
       winshell.CreateShortcut(
         Path = os.path.join(folder_to_track, f'{filename}.lnk'),
         Target = f'{folder_to_track}/{filename}')
       
       # move_file()
       file_exists = os.path.isfile(f'{folder_destination}/{filename}')
       if file_exists:
         while file_exists:
           new_filename = f'({self.i}) - {filename}'
           self.i += 1
           file_exists = os.path.isfile(f'{folder_destination}/{new_filename}')
         os.rename(f'{folder_to_track}/{filename}', f'{folder_destination}/{new_filename}')
       else:
         os.rename(f'{folder_to_track}/{filename}', f'{folder_destination}/{filename}')
Example #4
0
def post_install():
    if sys.platform == 'win32':
        new_cadnano_binary_fps = [pjoin( script_path, fn)
                                         for fn in cadnano_binaries]
        # print("Copying from ... :", cadnano_binary_fps)
        # print("... to:", new_cadnano_binary_fps)
        # [shutil.copy2(o, d) for o, d in zip(cadnano_binary_fps,
        #                                        new_cadnano_binary_fps)]
        # list(map(makeExecutable, new_cadnano_binary_fps))
        print("Installing Start menu shortcut...")
        import winshell
        link_filepath = os.path.join(winshell.programs(), "cadnano.lnk")
        import cadnano
        CN_PATH = os.path.dirname(os.path.abspath(cadnano.__file__))
        ICON_PATH = pjoin(CN_PATH, 'gui', 'ui',
                    'mainwindow', 'images', 'radnano-app-icon.ico')
        with winshell.shortcut(link_filepath) as link:
          link.path = new_cadnano_binary_fps[0]
          link.description = "Shortcut to cadnano"
          link.icon_location = (ICON_PATH, 0)
          # link.arguments = ""
        print("...Installation Complete")
    elif sys.platform == 'darwin':
        import cadnano.bin.appify as appify
        CN_BIN_PATH = os.path.dirname(os.path.abspath(appify.__file__))
        CN_PATH = os.path.dirname(CN_BIN_PATH)
        # rename script to fix Mac About menu text
        entry_path = pjoin(CN_BIN_PATH, 'radnano')
        shutil.copy2(pjoin(CN_BIN_PATH, 'main.py'), entry_path)
        ICON_PATH = pjoin(CN_PATH, 'gui', 'ui',
                            'mainwindow', 'images', 'radnano-app-icon.icns')
        appify.doAppify(entry_path, 'cadnano',
                            app_icon_path=ICON_PATH)
        print("...Installation Complete")
Example #5
0
 def getAllAppInfo(self, package):
     """
     It will find and put all the info of installed apps to two list: appname and path
     :param filters: self.appName, self.appPath
     :return: self.appName, self.appPath
     """
     shortcuts = {}
     appName = []
     appPth = []
     # get list of all programmes installed in local pc
     all_programs = winshell.programs(common=1)
     # loop to store info to shortcut, path, filename.
     for dirpath, dirnames, filenames in os.walk(all_programs):
         relpath = dirpath[1+ len(all_programs):]
         shortcuts.setdefault(relpath, []).extend([winshell.shortcut(os.path.join(dirpath, f)) for f in filenames])
     # loop to store all the app names, paths to a dictionary
     for relpath, lnks in sorted(shortcuts.items()):
         for lnk in lnks:
             name, _ = os.path.splitext(os.path.basename(lnk.lnk_filepath))
             appName.append(name)
             appPth.append(lnk.path)
             #self.createLog('Found %s: %s' % (name, lnk.path))
     appInfo = {}
     # fix the encoding convention
     for name in appName:
         pth = appPth[appName.index(name)]
         pth = func.encode(pth, 'utf8')
         name = func.encode(name, 'utf8')
         appInfo[name] = pth
     # return data
     return appInfo
Example #6
0
    def get_app_installed(self, fileName='appInfo.cfg', **appInfo):
        shortcuts = {}
        appName = []
        appPth = []

        all_programs = winshell.programs(common=1)

        for dirpath, dirnames, filenames in os.walk(all_programs):
            relpath = dirpath[1 + len(all_programs):]
            shortcuts.setdefault(relpath, []).extend([
                winshell.shortcut(os.path.join(dirpath, f)) for f in filenames
            ])
        for relpath, lnks in sorted(shortcuts.items()):
            for lnk in lnks:
                name, _ = os.path.splitext(os.path.basename(lnk.lnk_filepath))
                appName.append(name)
                appPth.append(lnk.path)

        for name in appName:
            appInfo[str(name)] = str(appPth[appName.index(name)])

        self.appInfo = appInfo
        self._appInfo = True

        pth = os.path.join(self.pthInfo['config'], fileName)
        self.compare_data(pth, self.appInfo)
        return True
Example #7
0
def generate_shortcut(name, path=None):
    if path is None:
        path = '{0}.bat'.format(name)
    winshell.CreateShortcut(Path=os.path.join(os.path.abspath(os.curdir), '{0}.lnk'.format(name)),
                            Target=path,
                            Icon=(os.path.join(os.path.abspath(os.curdir), '{0}.ico'.format(name)), 0))
    winshell.move_file(source_path='{0}.lnk'.format(name),
                       target_path=os.path.join(winshell.programs(), '{0}.lnk'.format(name)))
Example #8
0
        def GetSysStartupMenuPath():
            """MUST_SUCCESS_METHOD"""
            import winshell
            from os.path import normpath

            result = None
            
            try:
                result = normpath(winshell.programs())
            except Exception as e:
                Process.handle_exception(e, False)
                sys.exit(-42)

            return result
Example #9
0
def post_install():
    if platform.system() == 'Windows':
        print("Creating start menu shortcut...")
        import winshell
        icon_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'images', 'favicon.ico')
        flika_exe = os.path.join(sys.exec_prefix, 'Scripts', 'flika.exe')
        link_path = os.path.join(winshell.programs(), "flika.lnk")
        with winshell.shortcut(link_path) as link:
            link.path = flika_exe
            link.description = "flika"
            link.icon_location = (icon_path, 0)
        link_path = os.path.join(winshell.desktop(), "flika.lnk")
        with winshell.shortcut(link_path) as link:
            link.path = flika_exe
            link.description = "flika"
            link.icon_location = (icon_path, 0)
def getAllApplicationsEmulation():
    system_progs = traverseSubdirectories(
        r'C:\ProgramData\Microsoft\Windows\Start Menu\Programs')
    user_progs = traverseSubdirectories(winshell.programs())
    all_programs = system_progs + user_progs

    # flatten 2D array to 1D array
    from functools import reduce
    all_programs_list = reduce(lambda x, y: x + y, all_programs)

    # do a check here for icons since some of them dont show up as ico files
    # instead replacing them bitmaps that dont have transparent background
    for prog in all_programs_list:
        prog['icon_path'] = verifyExeIcons(prog['icon_path'])

    # print(json.dumps(all_programs_list, separators=(',', ':'), indent = 1))
    return json.dumps(all_programs_list, separators=(',', ':'))
Example #11
0
import os, sys
import glob
import winshell

for lnk in glob.glob(os.path.join(winshell.programs(), "*.lnk")):
    shortcut = winshell.shortcut(lnk)
    shortcut.dump()
    break
else:
    print("None found")
Example #12
0
import os, sys
import winshell

shortcuts = {}

user_programs = winshell.programs()
for dirpath, dirnames, filenames in os.walk(user_programs):
    relpath = dirpath[1 + len(user_programs) :]
    shortcuts.setdefault(relpath, []).extend([winshell.shortcut(os.path.join(dirpath, f)) for f in filenames])

all_programs = winshell.programs(common=1)
for dirpath, dirnames, filenames in os.walk(all_programs):
    relpath = dirpath[1 + len(all_programs) :]
    shortcuts.setdefault(relpath, []).extend([winshell.shortcut(os.path.join(dirpath, f)) for f in filenames])

for relpath, lnks in sorted(shortcuts.items()):
    level = relpath.count("\\")
    if level == 0:
        print("")
    print("%s+ %s" % ("    " * level, relpath))
    for lnk in lnks:
        name, _ = os.path.splitext(os.path.basename(lnk.lnk_filepath))
        print("%s* %s -> %s" % ("    " * (level + 1), name, lnk.path))
Example #13
0
import os, winshell
from win32com.client import Dispatch

desktop = winshell.programs()
path = os.path.join(desktop, "startup/LolNormalStats.lnk")
target = os.getcwd()+"/dist/main.exe"
wDir = r"D:\Users\Myself\My Music"
icon = r"D:\Users\Myself\My Music\some_file.mp3"

shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.WorkingDirectory = wDir
shortcut.IconLocation = icon
shortcut.save()
Example #14
0
 def test_programs(self):
     self.assert_folder_exists("programs personal", winshell.programs(0))
     self.assert_folder_exists("programs common", winshell.programs(1))
        def ShortcutRules(Action, FileName, Args):
            import winshell
            import os

            # These codes used python sequential execution characteristics.

            # Def a switch for base library, affect create shortcut or not
            # after fill information.
            # Close it if create shortcut manually.
            createSwitch = True

            # Def env(desktop, startmenu, etc) and lnk name.
            environmentPath = None
            lnkName = None

            # Get user settings.
            manageDesktop = wizardCfg.Methods.Unattended.ManageDesktopShortcut(
            )
            manageStartMenu = wizardCfg.Methods.Unattended.ManageStartMenuShortcut(
            )

            # Def shortcut information
            lnkFileLocation = None
            targetFullPath = None
            targetWorkingDir = None

            if Action == 'TskMainLnk':
                lnkName = wizardCfg.Methods.Basic.MainShortcut()
                targetFullPath = wizardCfg.Methods.Optional.Structure.Program.Tsk.Bin.TskMainExe(
                )
                targetWorkingDir = wizardCfg.Methods.Basic.InstallPath()

                if manageDesktop:
                    environmentPath = winshell.desktop()

                    lnkFileLocation = Env.Path.Complement.merge_system(
                        environmentPath, lnkName)

                    createSwitch = False
                    Shortcut.CreateShortcut(lnkFileLocation, targetFullPath,
                                            targetWorkingDir)
                if manageStartMenu:
                    environmentPath = winshell.programs()

                    tskSmGroupName = wizardCfg.Methods.Basic.StartMenuGroup()
                    tskSmGroupPath = Env.Path.Complement.merge_system(
                        environmentPath, tskSmGroupName)

                    lnkFileLocation = Env.Path.Complement.merge_system(
                        tskSmGroupPath, lnkName)

                    # Create shortcut menu for base library.
                    if not os.path.exists(tskSmGroupPath):
                        os.makedirs(tskSmGroupPath)

                    createSwitch = False
                    Shortcut.CreateShortcut(lnkFileLocation, targetFullPath,
                                            targetWorkingDir)

            if Action == 'UploadNow':

                createSwitch = False
                doNothing = None  #TODO

            if Action == 'DoNothing':

                createSwitch = False

            if createSwitch:
                Shortcut.CreateShortcut(lnkFileLocation, targetFullPath,
                                        targetWorkingDir)
            return
import os, sys
import winshell

shortcut = winshell.shortcut(sys.executable)
shortcut.write(os.path.join(winshell.desktop(), "python.lnk"))
shortcut.write(os.path.join(winshell.programs(), "python.lnk"))
import os, sys
import winshell

shortcuts = {}
dir_list=[]
dir_list2=[]
user_programs = winshell.programs()
for dirpath, dirnames, filenames in os.walk(user_programs):
    relpath = dirpath[1 + len(user_programs):]
    shortcuts.setdefault(
        relpath, []
    ).extend(
        [winshell.shortcut(os.path.join(dirpath, f)) for f in filenames]
    )

all_programs = winshell.programs(common=1)
for dirpath, dirnames, filenames in os.walk(all_programs):
    relpath = dirpath[1 + len(all_programs):]
    shortcuts.setdefault(
        relpath, []
    ).extend(
        [winshell.shortcut(os.path.join(dirpath, f)) for f in filenames]
    )

for relpath, lnks in sorted(shortcuts.items()):
    level = relpath.count("\\")
    for lnk in lnks:
        name, _ = os.path.splitext(os.path.basename(lnk.lnk_filepath))
        dir_list2.append("%s" % (lnk.path))

for items in dir_list2:
def create_shortcut(filename, dest):
    program_files = winshell.programs()
    target = f'{dest}{filename}'
    winshell.CreateShortcut(Path=os.path.join(dest, f'{filename}.lnk'),
                            Target=f'{dest}{filename}')