コード例 #1
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)
コード例 #2
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()]
コード例 #3
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)
コード例 #4
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()]
コード例 #5
0
ファイル: test_shell.py プロジェクト: qiao/shell.py
 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)
コード例 #6
0
ファイル: test_shell.py プロジェクト: qiao/shell.py
 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)
コード例 #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'))
コード例 #9
0
ファイル: test_shell.py プロジェクト: qiao/shell.py
 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)
コード例 #10
0
ファイル: test_shell.py プロジェクト: qiao/shell.py
 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')
コード例 #11
0
ファイル: test_shell.py プロジェクト: qiao/shell.py
 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)
コード例 #12
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)
コード例 #13
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')
コード例 #14
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)
コード例 #15
0
 def deluser(self, username):
     """Remove a virtual FTP user from PureFTP database"""
     _check_call(p('pure-pw userdel {}'.format(quote(username))))
コード例 #16
0
 def commit(self):
     """Commit any changes to the binary DB file"""
     _check_call(p('pure-pw mkdb'))