示例#1
0
    def list(self):
        """A list of usernames currently in the password database"""
        try:
            proc = _check_call(p('pure-pw list'))
            out = proc.stdout().decode('utf-8')
        except CalledProcessError as e:
            if e.returncode != 2 or \
                'Unable to open the passwd file:' not in e.stderr:
                raise
            # DB doesn't exist, so no users
            out = ''

        return [l.split('\t')[0] for l in out.splitlines()]
示例#2
0
 def test_pipe_with_cmd_list(self):
     pipeline = shell.pipe_all(['cat {0}'.format(self.ifconfig_out_path),
                                'grep -A 1 eth0',
                                'grep inet',
                                'awk "{print $2}"',
                                'cut -d: -f 2'])
     self.assertEqual(pipeline.stdout(), '192.168.116.101\n')
     self.assertEqual(pipeline.re(), 0)
     pipeline = shell.p(['cat {0}'.format(self.ifconfig_out_path),
                         'grep -A 1 eth0',
                         'grep inet',
                         'awk "{print $2}"',
                         'cut -d: -f 2'])
     self.assertEqual(pipeline.stdout(), '192.168.116.101\n')
     self.assertEqual(pipeline.re(), 0)
示例#3
0
 def test_chain_of_pipe(self):
     pipeline = shell.p('cat {0}'.format(self.ifconfig_out_path))\
                     .p("grep -A 1 eth0")\
                     .p("grep inet")\
                     .p("awk '{print $2}'")\
                     .p("cut -d: -f 2")
     self.assertEqual(pipeline.stdout(), '192.168.116.101\n')
     self.assertEqual(pipeline.re(), 0)
     pipeline = (shell
                 .p('cat {0}'.format(self.ifconfig_out_path))
                 .p("grep -A 1 lo")
                 .p("grep inet")
                 .p("awk '{print $2}'")
                 .p("cut -d: -f 2"))
     self.assertEqual(pipeline.stdout(), '127.0.0.1\n')
     self.assertEqual(pipeline.re(), 0)
示例#4
0
 def test_simple_pipe_run(self):
     pipeline = shell.p('echo yes no').p("awk '{print $1}'")
     pipeline.run()
     self.assertEqual(pipeline.stdout(), 'yes\n')
     self.assertEqual(pipeline.re(), 0)
示例#5
0
 def test_single_run_stdout(self):
     re = shell.p('echo hello shell.py').stdout()
     self.assertEqual(re, 'hello shell.py\n')
     re = shell.ex('echo 你好 shell.py').stdout()
     self.assertEqual(re, '你好 shell.py\n')
示例#6
0
 def test_single_run_retcode(self):
     self.assertEqual(shell.p('echo hello shell.py').re(), 0)
     self.assertNotEqual(shell.p('ls wtf#noneexist#dir#yay').re(), 0)
示例#7
0
 def deluser(self, username):
     """Remove a virtual FTP user from PureFTP database"""
     _check_call(p('pure-pw userdel {}'.format(quote(username))))
示例#8
0
 def commit(self):
     """Commit any changes to the binary DB file"""
     _check_call(p('pure-pw mkdb'))