Skip to content

Commit 83299ee

Browse files
authored
Version 0.6.0 (#17)
* Removing argparse / command line option. Adding first tests and docs to new functions. * Adding defaults confignamespace methods, adding change_logger_level, fixes * [skip ci] Adding cross version run command * Adding tests, docstrings and updates for run. * Fixing nix tests * Fixing timeout version discrepancies. * PY2 vs PY3 testing * Python 2.6 is dumb * [ci skip] Fix import error in wrappers * Fix setup.py error * [skip ci] Adding new tasker ability * [skip ci] Adding new download function * Making logger safer, expanding run_in_pool * Pythox 2.x fixes * [skip ci] Adding pushd and popd as well as timed example of find fines compared to find * [skip ci] Command line helpers * [skip ci] Adding match specifications and readme updates * [skip ci] Expanding readme * [skip ci] Better command for running stuff from interpreter, expansion of readme * Overhauled tasker, should be working * Rename tasker to something meaningful. Adding ability to stop when tasklist finished * Adding basic file server * Making clear that it is a file server * Testing a bit more of download * Adding reusable tests * Fixing called process errors for non 3.5 pythons * maybe 2.6 will work this time * Windows and pypy fixes. * python 2.6 subprocess fix * Adding new documentation. Improving testing. * Adding bad size documentation * Threaded instead of MP FileServer * Increase test coverage * Preparations for Version 0.6.0 * Updating documentation for Version 0.6.0 * Trying out new documentation * [ci skip] hopefully last doc fixes
1 parent b23f33b commit 83299ee

17 files changed

+843
-78
lines changed

.coveragerc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ omit =
77
*/nose/*
88
exclude_lines =
99
pragma: no cover
10-
except Exception as err
10+
except Exception
1111
conn.close
1212
raise BrowserException
1313
object.__setattr__
1414
raise AttributeError
15-
raise AttributeError
1615
object.__delattr__
1716
elif "darwin"
1817
return "mac"
@@ -21,3 +20,8 @@ exclude_lines =
2120
except OSError as err
2221
raise err
2322
except NameError
23+
def _background_runner
24+
raise TypeError
25+
self.free_tasks
26+
self.busy_tasks
27+
self.current_tasks

.noserc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[nosetests]
2+
nocapture=1

CHANGES.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Changelog
22
=========
33

4+
Version 0.6.0
5+
-------------
6+
7+
- Adding multiprocessing helpers, Tasker class and run_in_pool
8+
- Adding download and cmd helper functions
9+
- Adding ThreadedServer class, for running a server (defaults to local file server) in the background
10+
- Adding terminal analogue functions: cd, pwd, ls, pushd, popd
11+
- Adding match_case option for find_all_files and count_all_files
12+
- Fix 'run' call to CalledProcessError on older python versions
13+
- Changing logger to _logger to be hidden by default (should not be breaking, if so you coded wrong)
14+
415
Version 0.5.2
516
-------------
617

README.rst

Lines changed: 93 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
Reusables
22
=========
33

4-
**Commonly Consumed Code Commodities** |BuildStatus| |CoverageStatus| |DocStatus| |PyPi| |License|
4+
|BuildStatus| |CoverageStatus| |License| |PyPi| |DocStatus|
5+
6+
**Commonly Consumed Code Commodities**
57

68
Overview
79
--------
@@ -11,7 +13,6 @@ programmers may find themselves often recreating.
1113

1214
It includes:
1315

14-
- Cookie Management for Firefox and Chrome
1516
- Archive extraction (zip, tar, rar)
1617
- Path (file and folders) management
1718
- Fast logging setup
@@ -20,6 +21,10 @@ It includes:
2021
- Config to dict parsing
2122
- Common regular expressions and file extensions
2223
- Unique function wrappers
24+
- Bash analogues
25+
- Easy downloading
26+
- Multiprocessing helpers
27+
- Cookie Management for Firefox and Chrome
2328

2429
Reusables is designed to not require any imports outside the standard library,
2530
but can be supplemented with those found in the requirements.txt file for
@@ -45,15 +50,15 @@ General Helpers and File Management
4550
4651
import reusables
4752
53+
reusables.find_all_files(".", ext=reusables.exts.pictures)
54+
# ['/home/user/background.jpg', '/home/user/private.png']
55+
4856
reusables.extract_all("test/test_structure.zip", "my_archive")
4957
# All files in the zip will be extracted into directory "my_archive"
5058
5159
reusables.config_dict('my_config.cfg')
5260
# {'Section 1': {'key 1': 'value 1', 'key2': 'Value2'}, 'Section 2': {}}
5361
54-
reusables.find_all_files(".", ext=reusables.exts.pictures)
55-
# ['/home/user/background.jpg', '/home/user/private.png']
56-
5762
reusables.count_all_files(".")
5863
# 405
5964
@@ -63,23 +68,8 @@ General Helpers and File Management
6368
reusables.safe_path('/home/user/eViL User\0\\/newdir$^&*/new^%file.txt')
6469
# '/home/user/eViL User__/newdir____/new__file.txt'
6570
66-
67-
Cookie Management
68-
~~~~~~~~~~~~~~~~~
69-
70-
Firefox and Chrome Cookie management. (Chrome requires SQLite 3.8 or greater.)
71-
72-
.. code:: python
73-
74-
fox = reusables.FirefoxCookies()
75-
# Automatically uses the DB of the default profile, can specify db=<path>
76-
77-
fox.add_cookie("example.com", "MyCookie", "Cookie contents!")
78-
79-
fox.find_cookies(host="Example")
80-
# [{'host': u'example.com', 'name': u'MyCookie', 'value': u'Cookie contents!'}]
81-
82-
fox.delete_cookie("example.com", "MyCookie")
71+
reusables.run("echo 'hello there!'", shell=True)
72+
# CompletedProcess(args="echo 'hello there!'", returncode=0, stdout='hello there!\n')
8373
8474
Namespace
8575
~~~~~~~~~
@@ -108,7 +98,46 @@ that sub-dictionaries are recursively made into namespaces.
10898
# {'spam': <Namespace: {'eggs': {'sausage': {'bacon': '...>}
10999
# This is NOT the same as .to_dict() as it is not recursive
110100
101+
Command line helpers
102+
--------------------
103+
104+
Use the Python interpreter as much as a shell? Here's some handy helpers to
105+
fill the void. (Please don't do 'import *' in production code, this is used
106+
as an easy to use example using the interpreter interactively.)
107+
108+
.. code:: python
109+
110+
from reusables import *
111111
112+
cd("~") # Automatic user expansion unlike os.chdir()
113+
114+
pwd()
115+
# '/home/user'
116+
117+
pushd("Downloads")
118+
# ['Downloads', '/home/user']
119+
120+
pwd()
121+
# '/home/user/Downloads'
122+
123+
popd()
124+
# ['/home/user']
125+
126+
ls("-lah") # Uses 'ls' on linux and 'dir' on windows
127+
# total 1.5M
128+
# drwxr-xr-x 49 james james 4.0K Nov 1 20:09 .
129+
# drwxr-xr-x 3 root root 4.0K Aug 21 2015 ..
130+
# -rw-rw-r-- 1 james james 22K Aug 22 13:21 picture.jpg
131+
# -rw------- 1 james james 17K Nov 1 20:08 .bash_history
132+
133+
cmd("ifconfig") # Shells, decodes and prints 'reusables.run' output
134+
# eth0 Link encap:Ethernet HWaddr de:ad:be:ef:00:00
135+
# inet addr:10.0.2.5 Bcast:10.0.2.255 Mask:255.255.255.0
136+
# ...
137+
138+
download('https://www.python.org/ftp/python/README.html', save_to_file=False)
139+
# 2016-11-02 10:37:23,644 - reusables.web INFO Downloading https://www.python.org/ftp/python/README.html (2.3 KB) to memory
140+
# b'<PRE>\nPython Distribution...
112141
113142
DateTime
114143
~~~~~~~~
@@ -228,11 +257,14 @@ That's right, str.endswith_ (as well as str.startswith_) accept a tuple to searc
228257
File Type Extensions
229258
===================== ===================
230259
pictures .jpeg .jpg .png .gif .bmp .tif .tiff .ico .mng .tga .psd .xcf .svg .icns
231-
video .mkv .avi .mp4 .mov .flv .mpeg .mpg .3gp .m4v .ogv .asf .m1v .m2v .mpe .ogv .wmv .rm .qt
260+
video .mkv .avi .mp4 .mov .flv .mpeg .mpg .3gp .m4v .ogv .asf .m1v .m2v .mpe .ogv .wmv .rm .qt .3g2 .asf .vob
232261
music .mp3 .ogg .wav .flac .aif .aiff .au .m4a .wma .mp2 .m4a .m4p .aac .ra .mid .midi .mus .psf
233-
documents .doc .docx .pdf .xls .xlsx .ppt .pptx .csv .epub .gdoc .odt .rtf .txt .info .xps .gslides .gsheet
262+
documents .doc .docx .pdf .xls .xlsx .ppt .pptx .csv .epub .gdoc .odt .rtf .txt .info .xps .gslides .gsheet .pages .msg .tex .wpd .wps .csv
234263
archives .zip .rar .7z .tar.gz .tgz .gz .bzip .bzip2 .bz2 .xz .lzma .bin .tar
235264
cd_images .iso .nrg .img .mds .mdf .cue .daa
265+
scripts .py .sh .bat
266+
binaries .msi .exe
267+
markup .html .htm .xml .yaml .json .raml .xhtml .kml
236268
===================== ===================
237269

238270

@@ -250,12 +282,44 @@ different take that requires the function returns a result not yet provided.
250282
return random.randint(0, 100)
251283
252284
285+
Cookie Management
286+
~~~~~~~~~~~~~~~~~
287+
288+
Firefox and Chrome Cookie management. (Chrome requires SQLite 3.8 or greater.)
289+
290+
.. code:: python
291+
292+
fox = reusables.FirefoxCookies()
293+
# Automatically uses the DB of the default profile, can specify db=<path>
294+
295+
fox.add_cookie("example.com", "MyCookie", "Cookie contents!")
296+
297+
fox.find_cookies(host="Example")
298+
# [{'host': u'example.com', 'name': u'MyCookie', 'value': u'Cookie contents!'}]
299+
300+
fox.delete_cookie("example.com", "MyCookie")
301+
302+
303+
FAQ
304+
---
305+
306+
**How can I help? / Why doesn't it do what I want it too?**
307+
308+
Please feel free to make suggestions in the 'issues' section of github, or to be super duper helpful go ahead and submit a PR for the
309+
functionality you want to see! Only requirements are that it's well thought out and is more in place here rather than it's own project
310+
(to be merged will need documentation and basic unittests as well, but not a requirement for opening the PR).
311+
Please don't hesitate if you're new to python! Even the smallest PR contributions will earn a mention in a brand new Contributors section.
312+
313+
314+
**Why all the underscored imports?**
253315

254-
Common Issues
255-
-------------
316+
The rational behind this is just like the standard library, so that the user is sure anything they have access to is solely from this library
317+
and not one of it's imports. Several variables are also hidden like this, as they are only to be used by the library itself. For example, loggers
318+
should not have their objects modified by direct reference, but rather obtained through 'logging.getLogger('reusables')', as it helps sort out those who
319+
know what they are doing.
256320

257-
**UnRAR path issues**
258321

322+
**Unrar not installed?**
259323

260324
A common error to see, especially on Windows based systems, is: "rarfile.RarCannotExec: Unrar not installed? (rarfile.UNRAR_TOOL='unrar')"
261325

@@ -318,5 +382,7 @@ improve existing code is warmly welcomed!
318382
log
319383
datetime
320384
namespace
385+
web
386+
multiprocess_helpers
321387
wrappers
322388
changelog

doc/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
shutil.copy(os.path.join("..", "..", "README.rst"), "index.rst")
3232
shutil.copy(os.path.join("..", "..", "CHANGES.rst"), "changelog.rst")
3333

34-
with open(os.path.join("..", "..", "reusables", "reusables.py"), "r") as reuse_file:
34+
with open(os.path.join("..", "..", "reusables", "__init__.py"), "r") as reuse_file:
3535
reuse_content = reuse_file.read()
3636

3737

doc/source/multiprocess_helpers.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Multiprocess Helpers
2+
====================
3+
4+
.. automodule:: reusables.multiprocess_helpers
5+
:members:
6+
:undoc-members:

doc/source/web.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Web Based Helpers
2+
=================
3+
4+
.. automodule:: reusables.web
5+
:members:
6+
:undoc-members:

reusables/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from .log import *
66
from .browser import *
77
from .wrappers import *
8+
from .multiprocess_helpers import *
9+
from .web import *
810

911
__author__ = "Chris Griffith"
10-
__version__ = "0.5.2"
12+
__version__ = "0.6.0"

0 commit comments

Comments
 (0)