else
This commit is contained in:
parent
98667e75f3
commit
1e8786be61
4 changed files with 52 additions and 30 deletions
|
@ -1,30 +0,0 @@
|
|||
import bytestring
|
||||
import unittest
|
||||
|
||||
pairs = {
|
||||
100: '100.000 b',
|
||||
2 ** 10: '1.000 KiB',
|
||||
2 ** 20: '1.000 MiB',
|
||||
2 ** 30: '1.000 GiB',
|
||||
-(2 ** 30): '-1.000 GiB',
|
||||
(2 ** 30) + (512 * (2 ** 20)): '1.500 GiB',
|
||||
}
|
||||
|
||||
class BytestringTest(unittest.TestCase):
|
||||
def test_bytestring(self):
|
||||
for (number, text) in pairs.items():
|
||||
self.assertEqual(bytestring.bytestring(number), text)
|
||||
|
||||
def test_parsebytes(self):
|
||||
for (number, text) in pairs.items():
|
||||
self.assertEqual(bytestring.parsebytes(text), number)
|
||||
self.assertEqual(bytestring.parsebytes('100k'), 102400)
|
||||
self.assertEqual(bytestring.parsebytes('100 k'), 102400)
|
||||
self.assertEqual(bytestring.parsebytes('100 kb'), 102400)
|
||||
self.assertEqual(bytestring.parsebytes('100 kib'), 102400)
|
||||
self.assertEqual(bytestring.parsebytes('100.00KB'), 102400)
|
||||
self.assertEqual(bytestring.parsebytes('1.5 mb'), 1572864)
|
||||
self.assertEqual(bytestring.parsebytes('-1.5 mb'), -1572864)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -139,6 +139,7 @@ UNKNOWN_SIZE_STRING = '???'
|
|||
# This isn't meant to be a comprehensive filetype library, but it covers
|
||||
# enough of the typical opendir to speed things up.
|
||||
SKIPPABLE_FILETYPES = [
|
||||
'.3gp',
|
||||
'.aac',
|
||||
'.avi',
|
||||
'.bin',
|
||||
|
|
50
Templates/argparse.py
Normal file
50
Templates/argparse.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
## SINGLE
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
def example_argparse(args):
|
||||
print(args)
|
||||
|
||||
def main(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument('required_positional')
|
||||
parser.add_argument('optional_positional', nargs='?', default=None)
|
||||
parser.add_argument('-k', '--kwarg', dest='kwarg', default=None)
|
||||
parser.add_argument('-b', '--boolkwarg', dest='boolkwarg', action='store_true')
|
||||
parser.set_defaults(func=example_argparse)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
args.func(args)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv[1:])
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
|
||||
## MULTIPLE
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
def example_argparse(args):
|
||||
print(args)
|
||||
|
||||
def main(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers()
|
||||
|
||||
p_example = subparsers.add_parser('example1')
|
||||
p_example.add_argument('required_positional')
|
||||
p_example.add_argument('optional_positional', nargs='?', default=None)
|
||||
p_example.add_argument('-k', '--kwarg', dest='kwarg', default=None)
|
||||
p_example.add_argument('-b', '--boolkwarg', dest='boolkwarg', action='store_true')
|
||||
p_example.set_defaults(func=example_argparse)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
args.func(args)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv[1:])
|
|
@ -115,6 +115,7 @@ class Toddo():
|
|||
requestedtable = todo[SQL_TODOTABLE]
|
||||
if requestedtable.lower() != activetable.lower():
|
||||
raise ToddoExc('Todo %d is not part of the active table `%s`. It belongs to `%s`.' % (idnumber, activetable, requestedtable))
|
||||
print(self.display_one_todo(idnumber))
|
||||
self.cur.execute('DELETE FROM todos WHERE id=?', [idnumber])
|
||||
self.sql.commit()
|
||||
return idnumber
|
||||
|
|
Loading…
Reference in a new issue