Exemple #1
0
class Quickly:
    def __init__(self, path=None):
        self.setting = Settings(path)
        self.config = self.setting.getConfig()

    def add(self, key, path):
        path = os.path.abspath(path)
        if not os.path.exists(path):
            raise OSError("{path} does not exists".format(path=path))

        self.config['PATH'][key] = path

    def remove(self, key):
        self.config.remove_option('PATH', key)

    def edit(self, key, path):
        self.add(key, path)

    def list(self):
        return self.config['PATH']

    def listKeys(self, prefix, **kwargs):
        return (v for v in self.config['PATH'].keys() if v.startswith(prefix))

    def sync(self):
        self.setting.writeConfig(self.config)

    def cd(self, key):
        if key in self.config['PATH']:
            if (os.path.exists(self.config['PATH'][key])):
                print(self.config['PATH'][key])
            else:
                print("The path for {} which is {} cannot be found".format(key, self.config['PATH'][key]))
        else:
            print("{} has not been added. Cannot continue process".format(key))
Exemple #2
0
    def testWritingSettings(self):
        s = Settings(self.path)
        config = s.getConfig()

        # write something new
        config['PATH'] = {'python': "/some/path/python", 'php': "/some/path/php"}
        s.writeConfig(config)

        # now test wether the last config has been saved properly
        c = s.getConfig()
        self.assertTrue(c['PATH']['python'], "/some/path/python")
Exemple #3
0
    def testDeleteConfigKey(self):
        s = Settings(self.path)
        config = s.getConfig()

        # write something new
        config['PATH'] = {'python': "/some/path/python", 'php': "/some/path/php"}
        s.writeConfig(config)
        config = s.getConfig()

        # lets delete something
        config.remove_option('PATH', 'python')
        s.writeConfig(config)
        config = s.getConfig()

        self.assertFalse('python' in config['PATH'])
        self.assertTrue('php' in config['PATH'])
Exemple #4
0
 def __init__(self, path=None):
     self.setting = Settings(path)
     self.config = self.setting.getConfig()
Exemple #5
0
    def testGetSettings(self):
        s = Settings(self.path)
        config = s.getConfig()

        self.assertEqual(config['DEFAULT']['name'], 'quickly')
        self.assertTrue('PATH' in config)