From 34c95920f0b99e14b33330002a86d1da7bd1aef2 Mon Sep 17 00:00:00 2001 From: Anthony Oliver Date: Tue, 14 Feb 2012 11:32:59 -0500 Subject: [PATCH 1/5] Trying to get to work as a module --- MANIFEST | 6 + README.markdown => README | 0 build/lib.linux-x86_64-2.7/zxing/__init__.py | 0 .../lib.linux-x86_64-2.7/zxing/tests.py | 3 +- .../lib.linux-x86_64-2.7/zxing/zxing.py | 5 + dist/zxing-0.1.tar.gz | Bin 0 -> 2945 bytes setup.py | 13 ++ zxing/__init__.py | 0 zxing/__init__.pyc | Bin 0 -> 104 bytes sample.png => zxing/sample.png | Bin zxing/tests.py | 49 ++++++++ zxing/zxing.py | 114 ++++++++++++++++++ 12 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 MANIFEST rename README.markdown => README (100%) create mode 100644 build/lib.linux-x86_64-2.7/zxing/__init__.py rename tests.py => build/lib.linux-x86_64-2.7/zxing/tests.py (93%) rename zxing.py => build/lib.linux-x86_64-2.7/zxing/zxing.py (97%) create mode 100644 dist/zxing-0.1.tar.gz create mode 100644 setup.py create mode 100644 zxing/__init__.py create mode 100644 zxing/__init__.pyc rename sample.png => zxing/sample.png (100%) create mode 100644 zxing/tests.py create mode 100644 zxing/zxing.py diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..1b2228d --- /dev/null +++ b/MANIFEST @@ -0,0 +1,6 @@ +# file GENERATED by distutils, do NOT edit +README +setup.py +zxing/__init__.py +zxing/tests.py +zxing/zxing.py diff --git a/README.markdown b/README similarity index 100% rename from README.markdown rename to README diff --git a/build/lib.linux-x86_64-2.7/zxing/__init__.py b/build/lib.linux-x86_64-2.7/zxing/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests.py b/build/lib.linux-x86_64-2.7/zxing/tests.py similarity index 93% rename from tests.py rename to build/lib.linux-x86_64-2.7/zxing/tests.py index c4e3cdf..0b37051 100644 --- a/tests.py +++ b/build/lib.linux-x86_64-2.7/zxing/tests.py @@ -37,7 +37,8 @@ def test_barcode_parser(): def test_codereader(): - zx = BarCodeReader(zxing_location) + #~ zx = BarCodeReader(zxing_location) + zx = BarCodeReader() barcode = zx.decode(testimage) diff --git a/zxing.py b/build/lib.linux-x86_64-2.7/zxing/zxing.py similarity index 97% rename from zxing.py rename to build/lib.linux-x86_64-2.7/zxing/zxing.py index 9d0a122..87a29b9 100644 --- a/zxing.py +++ b/build/lib.linux-x86_64-2.7/zxing/zxing.py @@ -9,6 +9,7 @@ # otherwise you must specify the location as a parameter to the constructor # +__version__ = '0.2' import subprocess, re, os class BarCodeReader(): @@ -107,3 +108,7 @@ def __init__(self, zxing_output): self.points.append((float(m.group(2)), float(m.group(3)))) return + + +if __name__ == "__main__": + print "Zxing module" diff --git a/dist/zxing-0.1.tar.gz b/dist/zxing-0.1.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..e26dd6a473d7a0b5b08c11e84fa0227c73333530 GIT binary patch literal 2945 zcmV-{3x4z;iwFpkiaJjM|72-%bT4{%X>MmNFfK7JbYXG;?HX%y+qltRkG}#(e=yZZ z)WfoTrx{J_B+k{7#OHC`G>z?QAPTbRPy`Pk{hCgHdv_P$L$Vy_+Qez6++-{Y3oI7< z!tPRcH(`9y>iFIE#y5iw!0zr2es*_vI@Qk{HoD#2?qH|0)9dv%I^FF~Z?M63Hl6@7 zopQz4#tmP{o6pR944)q)|NI|;yF&lR`+G0n?td%&4+i~*^xyAvc1ZtyQ2TDLkNV$* zA=at&|IHz}P3JOhkr}WSb7=1FW`8OD19og<4E$UZcjzZ!|0DOUx*R$*y{QN|1M03Rxo8I z48b6y5gwsH1%&5Q5AE^uecVy5^2_5geeOm84G*@&fxDnn-Eh{>J-Ew z+f|GAVM5MAb)3dxsYNPu%J7f&lUuam!sO9vbqEM1XDq#zurJpd?dCaGFF+#4pm)$1 zT8SM2^RQ1W;R@zDXt^>=lPooAA=zwc_QKfl8!+SJERKN;7`y~e$k)rsr3g}XJr9F9 z;DRUv;~E;(OxVcC)3>ud*L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)hI+Ynj3-}aDVVkjZNB>B|HXf`Z zJj@$akq1Zn4N`U%hahs{m2F4T#(B}DADcP@M-3fcCsCMs?paI~lY;8pX0;?{} z4}fpN)=_aA6-NTs)&de!$W#x@o+33A!L5k|B;8eKB9?QZVxO^5LB(kpXZAhO%GA7Y zF{JEYiznMhfAbqizXW+ZP(rE zgsvKk!7_;+*T*hXM3{Fv_8hqis;GO40J7r=IO3-z`=%m#x(a7%{pvcQogW{SZIBRICG7zxFWLauN%D48W*_hD1{ z5BHAP2sBga0k{=rssb)t{UIin8Hgy%Eq4vv)pMdDlzm2Ty4hPiISBV~AIc--^pNifs7vW|8Enm%Bo*(SSr@X=u9vP!Or~ z2OP%f*c^!yIaPOreg-(lA2*f*U&T zKA@pE4t;p$ms0qu5TS`WF;6)KEhWHPlc;4K>tI rLk%_5P(uwh)KEhWHPlc;4K>tILk%_5P(uwhd>{B1`5p+n08jt`YU`|- literal 0 HcmV?d00001 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..be70c8e --- /dev/null +++ b/setup.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +from distutils.core import setup + +setup( + name='zxing', + version='0.1', + description="wrapper for zebra crossing (zxing) barcode library", + url='http://simplecv.org', + author='Ingenuitas', + author_email='public.relations@ingenuitas.com', + packages=['zxing'], +) diff --git a/zxing/__init__.py b/zxing/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/zxing/__init__.pyc b/zxing/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d54e1a67992d5421c26c815efd8e200bd1291b2a GIT binary patch literal 104 zcmZSn%*$0U&CoxY0SXv_v;zH6{UnR%Hd b@$q^El_eZNQJdWSl+v73JCNRDAZ7pn^M??Z literal 0 HcmV?d00001 diff --git a/sample.png b/zxing/sample.png similarity index 100% rename from sample.png rename to zxing/sample.png diff --git a/zxing/tests.py b/zxing/tests.py new file mode 100644 index 0000000..0b37051 --- /dev/null +++ b/zxing/tests.py @@ -0,0 +1,49 @@ +from zxing import * + +zxing_location = ".." +testimage = "sample.png" + + + + +def test_barcode_parser(): + text = """ +file:/home/oostendo/Pictures/datamatrix/4-contrastcrop.bmp (format: DATA_MATRIX, type: TEXT): +Raw result: +36MVENBAEEAS04403EB0284ZB +Parsed result: +36MVENBAEEAS04403EB0284ZB +Also, there were 4 result points. + Point 0: (24.0,18.0) + Point 1: (21.0,196.0) + Point 2: (201.0,198.0) + Point 3: (205.23952,21.0) +""" + + barcode = BarCode(text) + if (barcode.format != "DATA_MATRIX"): + return 0 + + if (barcode.raw != "36MVENBAEEAS04403EB0284ZB"): + return 0 + + if (barcode.data != "36MVENBAEEAS04403EB0284ZB"): + return 0 + + if (len(barcode.points) != 4 and barcode.points[0][0] != 24.0): + return 0 + + return 1 + + +def test_codereader(): + #~ zx = BarCodeReader(zxing_location) + zx = BarCodeReader() + + barcode = zx.decode(testimage) + + if re.match("http://", barcode.data): + return 1 + + return 0 + diff --git a/zxing/zxing.py b/zxing/zxing.py new file mode 100644 index 0000000..87a29b9 --- /dev/null +++ b/zxing/zxing.py @@ -0,0 +1,114 @@ +######################################################################## +# +# zxing.py -- a quick and dirty wrapper for zxing for python +# +# this allows you to send images and get back data from the ZXing +# library: http://code.google.com/p/zxing/ +# +# by default, it will expect to be run from the zxing source code directory +# otherwise you must specify the location as a parameter to the constructor +# + +__version__ = '0.2' +import subprocess, re, os + +class BarCodeReader(): + location = "" + command = "java" + libs = ["javase/javase.jar", "core/core.jar"] + args = ["-cp", "LIBS", "com.google.zxing.client.j2se.CommandLineRunner"] + + def __init__(self, loc=""): + if not len(loc): + if (os.environ.has_key("ZXING_LIBRARY")): + loc = os.environ["ZXING_LIBRARY"] + else: + loc = ".." + + self.location = loc + + def decode(self, files, try_harder = False): + cmd = [self.command] + cmd += self.args[:] #copy arg values + if (try_harder): + cmd.append("--try_harder") + + libraries = [self.location + "/" + l for l in self.libs] + + cmd = [ c if c != "LIBS" else ":".join(libraries) for c in cmd ] + + #send one file, or multiple files in a list + SINGLE_FILE = False + if type(files) != type(list()): + cmd.append(files) + SINGLE_FILE = True + else: + cmd += files + + (stdout, stderr) = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate() + codes = [] + file_results = stdout.split("\nfile:") + for result in file_results: + lines = stdout.split("\n") + if (re.search("No barcode found", lines[0])): + codes.append(None) + continue + + codes.append(BarCode(result)) + + if (SINGLE_FILE): + return codes[0] + else: + return codes + +#this is the barcode class which has +class BarCode: + format = "" + points = [] + data = "" + raw = "" + + def __init__(self, zxing_output): + lines = zxing_output.split("\n") + raw_block = False + parsed_block = False + point_block = False + + for l in lines: + m = re.search("format:\s([^,]+)", l) + if (not raw_block and not parsed_block and not point_block and m): + self.format = m.group(1) + continue + + if (not raw_block and not parsed_block and not point_block and l == "Raw result:"): + raw_block = True + continue + + if (raw_block and l != "Parsed result:"): + self.raw += l + "\n" + continue + + if (raw_block and l == "Parsed result:"): + raw_block = False + parsed_block = True + continue + + if (parsed_block and not re.match("Also, there were", l)): + self.data += l + "\n" + continue + + if (parsed_block and re.match("Also, there were", l)): + parsed_block = False + point_block = True + continue + + if (point_block): + m = re.search("Point\s(\d+):\s\(([\d\.]+),([\d\.]+)\)", l) + if (m): + self.points.append((float(m.group(2)), float(m.group(3)))) + + return + + +if __name__ == "__main__": + print "Zxing module" From 4c52dc61786cd79e045e9d2207ff712dc4bc823e Mon Sep 17 00:00:00 2001 From: Anthony Oliver Date: Tue, 14 Feb 2012 12:23:03 -0500 Subject: [PATCH 2/5] Removed build dirs --- build/lib.linux-x86_64-2.7/zxing/__init__.py | 0 build/lib.linux-x86_64-2.7/zxing/tests.py | 49 -------- build/lib.linux-x86_64-2.7/zxing/zxing.py | 114 ------------------- dist/zxing-0.1.tar.gz | Bin 2945 -> 0 bytes 4 files changed, 163 deletions(-) delete mode 100644 build/lib.linux-x86_64-2.7/zxing/__init__.py delete mode 100644 build/lib.linux-x86_64-2.7/zxing/tests.py delete mode 100644 build/lib.linux-x86_64-2.7/zxing/zxing.py delete mode 100644 dist/zxing-0.1.tar.gz diff --git a/build/lib.linux-x86_64-2.7/zxing/__init__.py b/build/lib.linux-x86_64-2.7/zxing/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/build/lib.linux-x86_64-2.7/zxing/tests.py b/build/lib.linux-x86_64-2.7/zxing/tests.py deleted file mode 100644 index 0b37051..0000000 --- a/build/lib.linux-x86_64-2.7/zxing/tests.py +++ /dev/null @@ -1,49 +0,0 @@ -from zxing import * - -zxing_location = ".." -testimage = "sample.png" - - - - -def test_barcode_parser(): - text = """ -file:/home/oostendo/Pictures/datamatrix/4-contrastcrop.bmp (format: DATA_MATRIX, type: TEXT): -Raw result: -36MVENBAEEAS04403EB0284ZB -Parsed result: -36MVENBAEEAS04403EB0284ZB -Also, there were 4 result points. - Point 0: (24.0,18.0) - Point 1: (21.0,196.0) - Point 2: (201.0,198.0) - Point 3: (205.23952,21.0) -""" - - barcode = BarCode(text) - if (barcode.format != "DATA_MATRIX"): - return 0 - - if (barcode.raw != "36MVENBAEEAS04403EB0284ZB"): - return 0 - - if (barcode.data != "36MVENBAEEAS04403EB0284ZB"): - return 0 - - if (len(barcode.points) != 4 and barcode.points[0][0] != 24.0): - return 0 - - return 1 - - -def test_codereader(): - #~ zx = BarCodeReader(zxing_location) - zx = BarCodeReader() - - barcode = zx.decode(testimage) - - if re.match("http://", barcode.data): - return 1 - - return 0 - diff --git a/build/lib.linux-x86_64-2.7/zxing/zxing.py b/build/lib.linux-x86_64-2.7/zxing/zxing.py deleted file mode 100644 index 87a29b9..0000000 --- a/build/lib.linux-x86_64-2.7/zxing/zxing.py +++ /dev/null @@ -1,114 +0,0 @@ -######################################################################## -# -# zxing.py -- a quick and dirty wrapper for zxing for python -# -# this allows you to send images and get back data from the ZXing -# library: http://code.google.com/p/zxing/ -# -# by default, it will expect to be run from the zxing source code directory -# otherwise you must specify the location as a parameter to the constructor -# - -__version__ = '0.2' -import subprocess, re, os - -class BarCodeReader(): - location = "" - command = "java" - libs = ["javase/javase.jar", "core/core.jar"] - args = ["-cp", "LIBS", "com.google.zxing.client.j2se.CommandLineRunner"] - - def __init__(self, loc=""): - if not len(loc): - if (os.environ.has_key("ZXING_LIBRARY")): - loc = os.environ["ZXING_LIBRARY"] - else: - loc = ".." - - self.location = loc - - def decode(self, files, try_harder = False): - cmd = [self.command] - cmd += self.args[:] #copy arg values - if (try_harder): - cmd.append("--try_harder") - - libraries = [self.location + "/" + l for l in self.libs] - - cmd = [ c if c != "LIBS" else ":".join(libraries) for c in cmd ] - - #send one file, or multiple files in a list - SINGLE_FILE = False - if type(files) != type(list()): - cmd.append(files) - SINGLE_FILE = True - else: - cmd += files - - (stdout, stderr) = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate() - codes = [] - file_results = stdout.split("\nfile:") - for result in file_results: - lines = stdout.split("\n") - if (re.search("No barcode found", lines[0])): - codes.append(None) - continue - - codes.append(BarCode(result)) - - if (SINGLE_FILE): - return codes[0] - else: - return codes - -#this is the barcode class which has -class BarCode: - format = "" - points = [] - data = "" - raw = "" - - def __init__(self, zxing_output): - lines = zxing_output.split("\n") - raw_block = False - parsed_block = False - point_block = False - - for l in lines: - m = re.search("format:\s([^,]+)", l) - if (not raw_block and not parsed_block and not point_block and m): - self.format = m.group(1) - continue - - if (not raw_block and not parsed_block and not point_block and l == "Raw result:"): - raw_block = True - continue - - if (raw_block and l != "Parsed result:"): - self.raw += l + "\n" - continue - - if (raw_block and l == "Parsed result:"): - raw_block = False - parsed_block = True - continue - - if (parsed_block and not re.match("Also, there were", l)): - self.data += l + "\n" - continue - - if (parsed_block and re.match("Also, there were", l)): - parsed_block = False - point_block = True - continue - - if (point_block): - m = re.search("Point\s(\d+):\s\(([\d\.]+),([\d\.]+)\)", l) - if (m): - self.points.append((float(m.group(2)), float(m.group(3)))) - - return - - -if __name__ == "__main__": - print "Zxing module" diff --git a/dist/zxing-0.1.tar.gz b/dist/zxing-0.1.tar.gz deleted file mode 100644 index e26dd6a473d7a0b5b08c11e84fa0227c73333530..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;4K>tILk%_5P(uwhd>{B1`5p+n08jt`YU`|- From fd2ef85c89317ae3774218a0376c51b4132b7ca1 Mon Sep 17 00:00:00 2001 From: Anthony Oliver Date: Tue, 14 Feb 2012 12:23:36 -0500 Subject: [PATCH 3/5] Added git ignore file --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..531fe65 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +build +build/* +dist +dist/* + From 60593b369a8f51c9c2fc6d81be9f6baccab9c616 Mon Sep 17 00:00:00 2001 From: Anthony Oliver Date: Tue, 14 Feb 2012 15:28:58 -0500 Subject: [PATCH 4/5] Fixed module so it works now --- zxing/__init__.py | 114 +++++++++++++++++++++++++++++++++++++++++++++ zxing/__init__.pyc | Bin 104 -> 2957 bytes zxing/zxing.py | 114 --------------------------------------------- 3 files changed, 114 insertions(+), 114 deletions(-) delete mode 100644 zxing/zxing.py diff --git a/zxing/__init__.py b/zxing/__init__.py index e69de29..87a29b9 100644 --- a/zxing/__init__.py +++ b/zxing/__init__.py @@ -0,0 +1,114 @@ +######################################################################## +# +# zxing.py -- a quick and dirty wrapper for zxing for python +# +# this allows you to send images and get back data from the ZXing +# library: http://code.google.com/p/zxing/ +# +# by default, it will expect to be run from the zxing source code directory +# otherwise you must specify the location as a parameter to the constructor +# + +__version__ = '0.2' +import subprocess, re, os + +class BarCodeReader(): + location = "" + command = "java" + libs = ["javase/javase.jar", "core/core.jar"] + args = ["-cp", "LIBS", "com.google.zxing.client.j2se.CommandLineRunner"] + + def __init__(self, loc=""): + if not len(loc): + if (os.environ.has_key("ZXING_LIBRARY")): + loc = os.environ["ZXING_LIBRARY"] + else: + loc = ".." + + self.location = loc + + def decode(self, files, try_harder = False): + cmd = [self.command] + cmd += self.args[:] #copy arg values + if (try_harder): + cmd.append("--try_harder") + + libraries = [self.location + "/" + l for l in self.libs] + + cmd = [ c if c != "LIBS" else ":".join(libraries) for c in cmd ] + + #send one file, or multiple files in a list + SINGLE_FILE = False + if type(files) != type(list()): + cmd.append(files) + SINGLE_FILE = True + else: + cmd += files + + (stdout, stderr) = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate() + codes = [] + file_results = stdout.split("\nfile:") + for result in file_results: + lines = stdout.split("\n") + if (re.search("No barcode found", lines[0])): + codes.append(None) + continue + + codes.append(BarCode(result)) + + if (SINGLE_FILE): + return codes[0] + else: + return codes + +#this is the barcode class which has +class BarCode: + format = "" + points = [] + data = "" + raw = "" + + def __init__(self, zxing_output): + lines = zxing_output.split("\n") + raw_block = False + parsed_block = False + point_block = False + + for l in lines: + m = re.search("format:\s([^,]+)", l) + if (not raw_block and not parsed_block and not point_block and m): + self.format = m.group(1) + continue + + if (not raw_block and not parsed_block and not point_block and l == "Raw result:"): + raw_block = True + continue + + if (raw_block and l != "Parsed result:"): + self.raw += l + "\n" + continue + + if (raw_block and l == "Parsed result:"): + raw_block = False + parsed_block = True + continue + + if (parsed_block and not re.match("Also, there were", l)): + self.data += l + "\n" + continue + + if (parsed_block and re.match("Also, there were", l)): + parsed_block = False + point_block = True + continue + + if (point_block): + m = re.search("Point\s(\d+):\s\(([\d\.]+),([\d\.]+)\)", l) + if (m): + self.points.append((float(m.group(2)), float(m.group(3)))) + + return + + +if __name__ == "__main__": + print "Zxing module" diff --git a/zxing/__init__.pyc b/zxing/__init__.pyc index d54e1a67992d5421c26c815efd8e200bd1291b2a..e1a1b1a3dd607e7c8de5727bd366d9f8ad4e22f1 100644 GIT binary patch literal 2957 zcmai0ZBH9V5S~51VPirHY6*&(5-DvCB^X3skWdvhkc84AN{>ou2+8U2E#{1UXLiq! zwDu?RLn7s4|3&*TKPDgg1KMZiY;dc-SiZTr*_qjAXLp{v-0u^Wx4*4^SEs=*hx=E! z>=8srvQ&^y|LSga3R3KfXutdiW znUKOU+W0y~c87M|ah{QvWxQUfS~2h)}46;@ItU1A8VkCC_QmXRyPMQI+Q8Jq_8y`iEP+mahHuB8nTedMna#T5B#_U0YAu?H~@fqF8&~ zIL6u>gbc5B==K2w@bna&E3zw;Dr!2^#PY;qY6A-%XZwmyR(Rb|P*KG6h6U(#JYHoq&VV@Szu`RJ_2{#>|Mka|xKMJgWtY4;M?3UDnG)iKZ zePzj3w+^!mN!^8!L`d~y<%_-_#Zl_}wN92|`20S6ZG|ILRZXd@PT8q5k}J3vmek=) zVL{jsqK2Y=j(YgxQPGVRe!@{&VjF6c6-J=|jVvTb51!3XKQ95OhC?&GJk30J=wy}p z1#x4a+te>o4@Wac$2l^mtjAS8JIw<13cLXv^PHzoi_|X>s*-IC6jbFLXI@F{uLCUE zs7lN19ajXkB1W86s5#EhXb;w_2vyAq&asaT9HV}jf%OqHM$IeSKgiu5rx#DCHx9Jl zQ@=VKE6LadrIXaW%E!4k!EHEuja1DdcEciNPQ|$e+a&Z!^#NqjnQ@A0%*n`-*}(VXpsjsh7VZ1(BA%5euWR~P8S73$`Y*I5W|9D*CD zDKBr$*TO%!OK0;|Mhikd(24R*OpE|UGb@f?8gYF$bOkxQ8?FX)mLK}$$=p=Dj4@`N zY#CLUBx`vjYk4H%+rLK`Sh5-+_rNLA?R(o!B+ z4xNm)-YAp||HmU##e11i&S7HOLAttc-KWp*KD#p?@sQ!!vdP`K^hg^$cLrfUVL#>_o<>ptBN_iM;~_d?sBkN6}--19DfD0m;T zkVDVC=6wVqo!T%-w+LF)3k%{YiV zOkTM@sJPQjy#@AU%0W{90I%+2p^%O&d0^n0NaF0-`1U|64WEX7^Hv3CG&ro&32DhGr)JtnO>e=s;WN$87d@o delta 72 zcmeAb&(LE2%*$0U&CoxY0SXv_v;z Date: Tue, 14 Feb 2012 15:29:38 -0500 Subject: [PATCH 5/5] Added *.pyc to gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 531fe65..3217691 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ build build/* dist dist/* - +*.pyc