-
Notifications
You must be signed in to change notification settings - Fork 0
/
all.py
67 lines (47 loc) · 1.85 KB
/
all.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from printer import TruthTable,KMap,Minterms
from graycode import *
import click
# global equation
# equation = None
@click.group()
def cli():
pass
@cli.command(help="<Equation in terms of Literals> [--kmap] [--table]")
@click.argument('eqn',type=str)
@click.option('--kmap',is_flag=True,help="For showing kmap")
@click.option('--table',is_flag=True,help="For showing table")
def equation(eqn,kmap,table):
if kmap:
myfunc = KMap(eqn)
click.echo(myfunc.printKMap())
if table:
myfunc = TruthTable(eqn)
click.echo(myfunc.printTable())
@cli.command(help="[OPTION for convertion] <number>")
@click.option('-bd','--bindec',type=str,help="Converting binary number to decimal")
@click.option('-db','--decbin',type=int,help="Converting decimal number to binary")
@click.option('-bg','--bingray',type=str,help="Converting binary number to Graycode")
def conv(bindec,decbin,bingray):
if bindec:
click.echo("Binary to decimal of {} : ".format(bindec) + str(binTodec(bindec)))
if decbin:
click.echo("Decimal to binary of {} : ".format(bindec) + str(decTobin(decbin)))
if bingray:
click.echo("Binary to graycode of {} : ".format(bingray) + str(conv_grayCode(bingray)))
@cli.command(help="<Number of Literals> <Minterms seperated by ','> [--kmap] [--table]")
@click.argument('no',type=int)
@click.argument('mins',type=str)
@click.option('--kmap',is_flag=True,help="For showing KMap")
@click.option('--table',is_flag=True,help="For showing Table")
def minterms(no,mins,kmap,table):
# print(no)
s = mins
s = s.split(',')
s = [int(j) for j in s]
t1 = Minterms(no,s)
if table:
click.echo(t1.generateTable())
if kmap:
click.echo(t1.printKMap())
if __name__ == "__main__":
cli()