Exemplo n.º 1
0
def GetAhkExe():
    """try to get executable of autohotkey.exe, if not there, empty string is put in ahkexe
    
    now also use status, if set in configfunctions (in future config gui)
    
    """
    global ahkexe
    exedir = status.getAhkExeDir()
    if exedir and os.path.isdir(exedir):
        ahk = os.path.join(exedir, "autohotkey.exe")
        if os.path.isfile(ahk):
            ahkexe = ahk
            return
        else:
            print 'warning, AhkExeDir in natlinkstatus.ini does not contain "autohotkey.exe": %s' % exedir
            print 'try default setting in PROGRAMFILES'
            #print 'AutoHotkey found, %s'% ahkexe

    # no succes, go on with program files:
    pf = natlinkcorefunctions.getExtendedEnv("PROGRAMFILES")
    if pf.find('(x86)') > 0:
        # 64 bit:
        pf = natlinkcorefunctions.getExtendedEnv(
            "PROGRAMW6432")  # the old pf directory
    if not os.path.isdir(pf):
        raise IOError("cannot find (old style) program files directory: %s" %
                      pf)

    ahk = os.path.join(pf, "autohotkey", "autohotkey.exe")
    if os.path.isfile(ahk):
        ahkexe = ahk
        #print 'AutoHotkey found, %s'% ahkexe
    else:
        ahkexe = ""
Exemplo n.º 2
0
def GetAhkExe():
    """try to get executable of autohotkey.exe, if not there, empty string is put in ahkexe
    
    now also use status, if set in configfunctions (in future config gui)
    
    """
    global ahkexe
    exedir = status.getAhkExeDir()
    if exedir and os.path.isdir(exedir):
        ahk = os.path.join(exedir, "autohotkey.exe")
        if os.path.isfile(ahk):
            ahkexe = ahk
            return
        else:
            print 'warning, AhkExeDir in natlinkstatus.ini does not contain "autohotkey.exe": %s'% exedir
            print 'try default setting in PROGRAMFILES'
            #print 'AutoHotkey found, %s'% ahkexe

    # no succes, go on with program files:
    pf = natlinkcorefunctions.getExtendedEnv("PROGRAMFILES")
    if pf.find('(x86)')>0:
        # 64 bit:
        pf = natlinkcorefunctions.getExtendedEnv("PROGRAMW6432")  # the old pf directory
    if not os.path.isdir(pf):
        raise IOError("cannot find (old style) program files directory: %s"% pf)
    
    
    ahk = os.path.join(pf, "autohotkey", "autohotkey.exe")
    if os.path.isfile(ahk):
        ahkexe = ahk
        #print 'AutoHotkey found, %s'% ahkexe
    else:
        ahkexe = ""
Exemplo n.º 3
0
    def test_setClearUnimacroIniFilesEditor(self):
        """This option should set or clear the unimacro INI files editor
        """
        testName = 'test_setClearUnimacroIniFilesEditor'
        key = "UnimacroIniFilesEditor"
        cli = natlinkconfigfunctions.CLI()
        old = self.Userregnl.get(key, None)

        
        # not a valid folder:
        cli.do_p("not a valid file")
        self.checkUserregnl(key, old, "%s, nothing should be changed yet"% testName)

        # change to notepad:
        wordpad = os.path.join(natlinkcorefunctions.getExtendedEnv("PROGRAMFILES"), 'Windows NT',
                            Accessories, "wordpad.exe")
        if not os.path.isfile(wordpad):
            raise IOError("Test error, cannot find wordpad on: %s"% wordpad)
        
        cli.do_p(wordpad)
        self.checkUserregnl(key, wordpad, "%s, UnimacroIniFilesEditor should be changed now"% testName)

        # now clear:
        cli.do_P("dummy")
        self.checkUserregnl(key, None, "%s UnimacroIniFilesEditor should be cleared now"% testName)
Exemplo n.º 4
0
def GetAhkScriptFolder():
    """try to get AutoHotkey folder as subdirectory of PERSONAL
    
    create if non-existent.
    
    """
    global ahkscriptfolder

    scriptfolder = status.getAhkUserDir()
    if scriptfolder:
        if os.path.isdir(scriptfolder):
            ahkscriptfolder = scriptfolder
            copySampleAhkScripts(sampleAhkDirectory, ahkscriptfolder)
            return
        else:
            print 'warning: AhkUserDir set in natlinkstatus.ini, but no valid directory: %s'% scriptfolder
            print 'take default in subfolder AutoHotkey from your PERSONAL directory'
    # not proceed with PERSONAL:

    personal = natlinkcorefunctions.getExtendedEnv("PERSONAL")
    if not os.path.isdir(personal):
        raise IOError('cannot find PERSONAL (documents) directory: %s\nPlease check environment variable "PERSONAL", this one should be the same as "~" or "HOME"'% personal)
    
    ahkscriptfolder = os.path.join(personal, "AutoHotkey")
    if os.path.isdir(ahkscriptfolder):
        copySampleAhkScripts(sampleAhkDirectory, ahkscriptfolder)
        return
    print 'try to create the folder %s'% ahkscriptfolder
    os.mkdir(ahkscriptfolder)
    if os.path.isdir(ahkscriptfolder):
        copySampleAhkScripts(sampleAhkDirectory, ahkscriptfolder)
        return
    raise IOError("GetAhkScriptFolder, cannot create AutoHotkey scripts folder: %s\nPlease try to do so yourself."% ahkscriptfolder)
Exemplo n.º 5
0
    def tttest_setClearVocolaCommandFilesEditor(self):
        """This option should set or clear the vocola command files editor
        """
        testName = 'test_setClearVocolaCommandFilesEditor'
        key = "VocolaCommandFilesEditor"
        cli = natlinkconfigfunctions.CLI()
        old = self.testinisection.get(key, None)

        # not a valid folder:
        cli.do_w("not a valid file")
        self.checkusertestinifile(
            key, old, "%s, nothing should be changed yet" % testName)

        # change to notepad:
        wordpad = os.path.join(
            natlinkcorefunctions.getExtendedEnv("PROGRAMFILES"), 'Windows NT',
            Accessories, "wordpad.exe")
        if not os.path.isfile(wordpad):
            raise IOError("Test error, cannot find wordpad on: %s" % wordpad)

        cli.do_w(wordpad)
        self.checkusertestinifile(
            key, wordpad,
            "%s, VocolaCommandFilesEditor should be changed now" % testName)

        # now clear:
        cli.do_W("dummy")
        self.checkusertestinifile(
            key, None,
            "%s VocolaUserDirectory should be cleared now" % testName)
Exemplo n.º 6
0
    def tttest_getExtendedEnv(self):
        """Test the different functions in natlinkcorefunctions that do environment variables

        Assume if HOME is set in os.environ (system environment variables), it is identical to PERSONAL.

        This is quite complicated        

        """
        # get HOME from os.environ, or CSLID: PERSONAL, ~ taken as HOME...
        home = natlinkcorefunctions.getExtendedEnv("HOME")
        self.assertTrue(os.path.isdir(home), "home should be a folder, not: |%s|"% home)
        home2 = natlinkcorefunctions.getExtendedEnv("~")
        self.assertTrue(home == home2, "home2 (~) should be same as HOME (%s), not: |%s|"%
                     (home,home2))

        # check spaces and erroneous spaces around such a variable:        
        personal = natlinkcorefunctions.getExtendedEnv("PERSONAL")
        personal2 = natlinkcorefunctions.getExtendedEnv("%PERSONAL%")  # erroneous call, but allowed
        personal3 = natlinkcorefunctions.getExtendedEnv("  PERSONAL     ")  # erroneous call, but allowed
        personal4 = natlinkcorefunctions.getExtendedEnv(" % PERSONAL %    ")  # erroneous call, but allowed
        self.assertTrue(personal == home, "PERSONAL should be same as HOME (%s), not: |%s|"%
                     (home,personal))
        self.assertTrue(personal2 == personal, "PERSONAL should allow %% signs in it")
        self.assertTrue(personal3 == personal, "PERSONAL should allow spaces signs around it")
        self.assertTrue(personal4 == personal, "PERSONAL should allow spaces and %% signs around it")

        # unknown CSIDL_ variable should give ValueError:
        self.assertRaises(ValueError, natlinkcorefunctions.getExtendedEnv, 'ABACADABRA')
Exemplo n.º 7
0
    def test_getExtendedEnv(self):
        """Test the different functions in natlinkcorefunctions that do environment variables

        Assume if HOME is set in os.environ (system environment variables), it is identical to PERSONAL.

        This is quite complicated        

        """
        # get HOME from os.environ, or CSLID: PERSONAL, ~ taken as HOME...
        home = natlinkcorefunctions.getExtendedEnv("HOME")
        self.assert_(os.path.isdir(home), "home should be a folder, not: |%s|"% home)
        home2 = natlinkcorefunctions.getExtendedEnv("~")
        self.assert_(home == home2, "home2 (~) should be same as HOME (%s), not: |%s|"%
                     (home,home2))

        # check spaces and erroneous spaces around such a variable:        
        personal = natlinkcorefunctions.getExtendedEnv("PERSONAL")
        personal2 = natlinkcorefunctions.getExtendedEnv("%PERSONAL%")  # erroneous call, but allowed
        personal3 = natlinkcorefunctions.getExtendedEnv("  PERSONAL     ")  # erroneous call, but allowed
        personal4 = natlinkcorefunctions.getExtendedEnv(" % PERSONAL %    ")  # erroneous call, but allowed
        self.assert_(personal == home, "PERSONAL should be same as HOME (%s), not: |%s|"%
                     (home,personal))
        self.assert_(personal2 == personal, "PERSONAL should allow %% signs in it")
        self.assert_(personal3 == personal, "PERSONAL should allow spaces signs around it")
        self.assert_(personal4 == personal, "PERSONAL should allow spaces and %% signs around it")

        # unknown CSIDL_ variable should give ValueError:
        self.assertRaises(ValueError, natlinkcorefunctions.getExtendedEnv, 'ABACADABRA')
Exemplo n.º 8
0
    def setUp(self):
        # for setting getting values test:
        f1 = open(testinifile1, 'w')
        f1.close()
        self.usergroup = "SOFTWARE\Natlink"
##    lmgroup = "SOFTWARE\Natlink"
        self.Userregnl = RegistryDict.RegistryDict(win32con.HKEY_CURRENT_USER, self.usergroup)
        self.backupUserregnl = dict(self.Userregnl)

        ## testfolder:
        tmp = natlinkcorefunctions.getExtendedEnv("TMP")
        tmpTest = os.path.join(tmp, 'testconfig')
        if not os.path.isdir(tmp):
            raise TestError('test error, not a valid tmp folderpath: %s'% tmp)
        if os.path.exists(tmpTest):
            shutil.rmtree(tmpTest)
        if os.path.exists(tmpTest):
            raise TestError('test error, test path should not be there: %s'% tmpTest)
        os.mkdir(tmpTest)
        self.assert_(os.path.isdir(tmpTest), "Could not make test folder: %s"% tmpTest)
        self.tmpTest = tmpTest
Exemplo n.º 9
0
 def setUp(self):
     """define self.tmpTest (in TMP)
         and vocolausertest and unimacrousertest in HOME directory
         raise TestError if HOME is not existent, or one of these directories already exist
     """
     ## testfolder:
     tmp = natlinkcorefunctions.getExtendedEnv("TMP")
     tmpTest = os.path.join(tmp, 'testconfig')
     if not os.path.isdir(tmp):
         raise TestError('test error, not a valid tmp folderpath: %s'% tmp)
     if os.path.exists(tmpTest):
         shutil.rmtree(tmpTest)
     if os.path.exists(tmpTest):
         raise TestError('test error, test path should not be there: %s'% tmpTest)
     
     
     os.mkdir(tmpTest)
     homeDir = isValidPath("~")
     if homeDir:
         vocolausertest = os.path.join(homeDir, "vocolausertest")
         if not isValidPath(vocolausertest):
             os.mkdir(vocolausertest)
         self.vocolausertest = vocolausertest
         unimacrousertest = os.path.join(homeDir, "unimacrousertest")
         if not isValidPath(unimacrousertest):
             os.mkdir(unimacrousertest)
         self.unimacrousertest = unimacrousertest
     else:
         raise TestError("home directory not defined: %s")
             
         
     self.assertTrue(os.path.isdir(tmpTest), "Could not make test folder: %s"% tmpTest)
     # self.tmpTest to test directory things safely:
     self.tmpTest = tmpTest
     self.cli = natlinkconfigfunctions.CLI()
     config = self.cli.config
     config.userregnl = NatlinkstatusTestInifileSection()
     config.userregnl.clear()
     self.testinisection = config.userregnl
Exemplo n.º 10
0
def GetAhkScriptFolder():
    """try to get AutoHotkey folder as subdirectory of PERSONAL
    
    create if non-existent.
    
    """
    global ahkscriptfolder

    scriptfolder = status.getAhkUserDir()
    if scriptfolder:
        if os.path.isdir(scriptfolder):
            ahkscriptfolder = scriptfolder
            copySampleAhkScripts(sampleAhkDirectory, ahkscriptfolder)
            return
        else:
            print 'warning: AhkUserDir set in natlinkstatus.ini, but no valid directory: %s' % scriptfolder
            print 'take default in subfolder AutoHotkey from your PERSONAL directory'
    # not proceed with PERSONAL:

    personal = natlinkcorefunctions.getExtendedEnv("PERSONAL")
    if not os.path.isdir(personal):
        raise IOError(
            'cannot find PERSONAL (documents) directory: %s\nPlease check environment variable "PERSONAL", this one should be the same as "~" or "HOME"'
            % personal)

    ahkscriptfolder = os.path.join(personal, "AutoHotkey")
    if os.path.isdir(ahkscriptfolder):
        copySampleAhkScripts(sampleAhkDirectory, ahkscriptfolder)
        return
    print 'try to create the folder %s' % ahkscriptfolder
    os.mkdir(ahkscriptfolder)
    if os.path.isdir(ahkscriptfolder):
        copySampleAhkScripts(sampleAhkDirectory, ahkscriptfolder)
        return
    raise IOError(
        "GetAhkScriptFolder, cannot create AutoHotkey scripts folder: %s\nPlease try to do so yourself."
        % ahkscriptfolder)