From d27da38aa704a76b9df64daa0f45d632d2dcc93c Mon Sep 17 00:00:00 2001 From: Lukasz Forynski Date: Thu, 15 Aug 2013 23:58:45 +0100 Subject: [PATCH] restructured to match distribution profile --- README.md | 7 ++ commands.txt | 3 + exception_info.py | 97 ------------------- multi_key_dict/README.txt | 15 +++ .../multi_key_dict.py | 0 multi_key_dict/setup.py | 27 ++++++ text_progress_bar/README.txt | 10 ++ text_progress_bar/setup.py | 27 ++++++ .../text_progress_bar.py | 0 9 files changed, 89 insertions(+), 97 deletions(-) create mode 100644 commands.txt delete mode 100644 exception_info.py create mode 100644 multi_key_dict/README.txt rename multi_key_dict.py => multi_key_dict/multi_key_dict.py (100%) create mode 100644 multi_key_dict/setup.py create mode 100644 text_progress_bar/README.txt create mode 100644 text_progress_bar/setup.py rename progress_bar.py => text_progress_bar/text_progress_bar.py (100%) diff --git a/README.md b/README.md index f760227..2b401df 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,10 @@ python_data_structures ====================== Some useful python data structures / concepts + +distributions can be found on pypi: + +* https://pypi.python.org/pypi?:action=display&name=multi_key_dict +* https://pypi.python.org/pypi?:action=display&name=text_progress_bar + + diff --git a/commands.txt b/commands.txt new file mode 100644 index 0000000..e566988 --- /dev/null +++ b/commands.txt @@ -0,0 +1,3 @@ +setup.py bdist_wininst sdist = to build it + +python setup.py register bdist bdist_wininst upload = uploading \ No newline at end of file diff --git a/exception_info.py b/exception_info.py deleted file mode 100644 index 4ba2f2a..0000000 --- a/exception_info.py +++ /dev/null @@ -1,97 +0,0 @@ -''' -Created on 9 Jun 2013 - -@author: lukasz.forynski - -@brief: Function to get some trace information about the exception-rising code, - when called from exception handler. - - This information includes: - - module name - - class name (if exception executed in the method) - - line number - - This might be more useful (and logical) than what's provided with traceback - which gives filenames, line numbers and code snippets - -https://github.com/formiaczek/python_data_structures -___________________________________ - - Copyright (c) 2013 Lukasz Forynski - -Permission is hereby granted, free of charge, to any person obtaining a copy of this -software and associated documentation files (the "Software"), to deal in the Software -without restriction, including without limitation the rights to use, copy, modify, merge, -publish, distribute, sub-license, and/or sell copies of the Software, and to permit persons -to whom the Software is furnished to do so, subject to the following conditions: - -- The above copyright notice and this permission notice shall be included in all copies -or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. -''' - - -import inspect -import sys -import os - - -def raising_code_info(): - code_info = '' - try: - frames = inspect.trace() - if(len(frames)): - full_method_name = frames[0][4][0].rstrip('\n\r').strip() - line_number = frames[1][2] - module_name = frames[0][0].f_globals['__name__'] - if(module_name == '__main__'): - module_name = os.path.basename(sys.argv[0]).replace('.py','') - class_name = '' - obj_name_dot_method = full_method_name.split('.', 1) - if len(obj_name_dot_method) > 1: - obj_name, full_method_name = obj_name_dot_method - try: - class_name = frames[0][0].f_locals[obj_name].__class__.__name__ - except: - pass - method_name = module_name + '.' - if len(class_name) > 0: - method_name += class_name + '.' - method_name += full_method_name - code_info = '%s, line %d' % (method_name, line_number) - finally: - del frames - sys.exc_clear() - return code_info - - -def function1(): - print 1/0 - -class AClass(object): - def method2(self): - a = [] - a[3] = 1 - -def try_it_out(): - # try it with a function - try: - function1() - except Exception, what: - print '%s: \"%s\"' % (raising_code_info(), what) - - # try it with a method - try: - my_obj_name = AClass() - my_obj_name.method2() - except Exception, what: - print '%s: \"%s\"' % (raising_code_info(), what) - -if __name__ == '__main__': - try_it_out() diff --git a/multi_key_dict/README.txt b/multi_key_dict/README.txt new file mode 100644 index 0000000..f6cce64 --- /dev/null +++ b/multi_key_dict/README.txt @@ -0,0 +1,15 @@ +multi_key_dict +====================== + + +Implementation of a multi-key dictionary. + +This kind of dictionary has a similar interface to the standard dictionary, + +and indeed if used with single key key elements - it's behaviour is the same as for a standard dict. + +However it also allows for creation of elements using multiple keys (using tuples/lists). Such elements can be accessed using either of those keys (e.g for read/update/deletion). +Multi-key dict provides also extended interface for iterating over items and keys (e.g. by the key type), which might be useful when creating, e.g. dictionaries with index-name key pair allowing to iterate over items using either: names or indexes. +It can be useful for many many other similar use-cases, and there is no limit to the number of keys used to map to the value. + +There are also methods to get other keys that map to the same element and others. Refer to examples and test code to see it in action. diff --git a/multi_key_dict.py b/multi_key_dict/multi_key_dict.py similarity index 100% rename from multi_key_dict.py rename to multi_key_dict/multi_key_dict.py diff --git a/multi_key_dict/setup.py b/multi_key_dict/setup.py new file mode 100644 index 0000000..a9f2691 --- /dev/null +++ b/multi_key_dict/setup.py @@ -0,0 +1,27 @@ +#!python + +from distutils.core import setup + +long_descr='' + +with open('README.txt') as readme: + long_descr = readme.read() + +setup(name='multi_key_dict', + version='1.0.2', + description='Multi key dictionary implementation', + author='Lukasz Forynski', + author_email='lukasz.forynski@gmail.com', + url='https://github.com/formiaczek/python_data_structures', + py_modules=['multi_key_dict'], + license=['License :: OSI Approved :: MIT License (http://opensource.org/licenses/MIT)'], + long_description=long_descr, + classifiers=[ + 'Programming Language :: Python', + 'License :: OSI Approved :: MIT License', + 'Development Status :: 4 - Beta', + 'Operating System :: OS Independent', + 'Intended Audience :: Developers', + 'Topic :: Software Development :: Libraries :: Python Modules' + ] + ) diff --git a/text_progress_bar/README.txt b/text_progress_bar/README.txt new file mode 100644 index 0000000..d86ad6c --- /dev/null +++ b/text_progress_bar/README.txt @@ -0,0 +1,10 @@ +text_progress_bar +====================== + + +Implementation of a simple text progress bar. + +It looks something like this: + +[================..............] : downloading xyz (186/335) + diff --git a/text_progress_bar/setup.py b/text_progress_bar/setup.py new file mode 100644 index 0000000..166af50 --- /dev/null +++ b/text_progress_bar/setup.py @@ -0,0 +1,27 @@ +#!python + +from distutils.core import setup + +long_descr='' + +with open('README.txt') as readme: + long_descr = readme.read() + +setup(name='text_progress_bar', + version='1.0.1', + description='Simple text progress bar', + author='Lukasz Forynski', + author_email='lukasz.forynski@gmail.com', + url='https://github.com/formiaczek/python_data_structures', + py_modules=['text_progress_bar'], + license=['License :: OSI Approved :: MIT License (http://opensource.org/licenses/MIT)'], + long_description=long_descr, + classifiers=[ + 'Programming Language :: Python', + 'License :: OSI Approved :: MIT License', + 'Development Status :: 4 - Beta', + 'Operating System :: OS Independent', + 'Intended Audience :: Developers', + 'Topic :: Software Development :: Libraries :: Python Modules' + ] + ) diff --git a/progress_bar.py b/text_progress_bar/text_progress_bar.py similarity index 100% rename from progress_bar.py rename to text_progress_bar/text_progress_bar.py