Go to the documentation of this file.00001
00002 import sys,rp
00003
00004 rule=['init sqs_range="" ',
00005 'sqs ::= SELECT "*" FROM fileid WHERE range operator value ',
00006 ' @sqs_fileid="$fileid"',
00007 ' @sqs_ope="$operator" ',
00008
00009 'range::= n "-" "*" @sqs_range=[$n-1,999] ',
00010 ' | n "-" m @sqs_range=[$n-1,$m] ',
00011 ' | n "." m @sqs_range=[$n-1,($m+$n-1)] ',
00012 ' | n "-" @sqs_range=[$n-1,999] ',
00013 'n ::= r"[0-9]"* ',
00014 'm ::= r"[0-9]"* ',
00015 'value::= "\'" car* "\'" @sqs_valtype=1 @sqs_value="$car" ',
00016 ' | numeric @sqs_valtype=2 @sqs_value=numeric ',
00017 'operator::= LIKE ',
00018 ' | "=" ',
00019 ' | ">" ',
00020 ' | "<" ',
00021 'car ::= r"[^\']" ',
00022 'numeric::= r"[0-9]"* ',
00023 'fileid::= r"\S"* ']
00024 parms=' '.join(sys.argv[1:])
00025
00026 cmp=rp.match(rule,parms)
00027 if cmp==None:
00028 print "Error in parsing:"
00029 else:
00030 id=None
00031 try:
00032 id=open(cmp.sqs_fileid)
00033 for l in id.readlines():
00034 data=l[cmp.sqs_range[0]:cmp.sqs_range[1]]
00035 found=False
00036 if cmp.sqs_valtype==1:
00037 if cmp.sqs_ope.upper()=='LIKE':
00038 if cmp.sqs_value.startswith('%'):
00039 found=data.endswith(cmp.sqs_value[1:])
00040 elif cmp.sqs_value.endswith('%'):
00041 found=data.startswith(cmp.sqs_value[:-1])
00042 else:
00043 found=(data.find(cmp.sqs_value)>-1)
00044 elif cmp.sqs_ope=='=':
00045 found=(data == cmp.sqs_value)
00046 else:
00047 raise Exception('Operator not allowed with alpha')
00048 else:
00049 try:
00050 v1=int(data.strip())
00051 v2=int(cmp.sqs_value.strip())
00052 if cmp.sqs_ope=='=': found=(v1==v2)
00053 elif cmp.sqs_ope=='>': found=(v1>v2)
00054 elif cmp.sqs_ope=='<': found=(v1<v2)
00055 except:
00056 pass
00057 if found:
00058 print l[:-1]
00059 except Exception,e:
00060 print e
00061 else:
00062 if id!=None: id.close()
00063