File: ziptools/ziptools/docetc/1.1-upgrades/autoglobs-errortests.txt

##########################################################################################
# Demo 1.1 auto-globs (filename expansion), and some of its new error checks
##########################################################################################


# Prerun
~/Desktop$ export Z=/MY-STUFF/Code/ziptools
~/Desktop$ date
Tue Mar 24 15:43:31 PDT 2020


##########################################################################################
# Create auto-globs: '' in a Unix bash shell simulates a Windows DOS Command Prompt
##########################################################################################


~/Desktop$ py3 $Z/zip-create.py site '*.JPG'
No existing source files provided, run cancelled.
Usage: <python> zip-create.py [zipfile source [source...] [-skipcruft] [-atlinks]]


~/Desktop$ py3 $Z/zip-create.py site 'UNION/*.JPG'
Zipping ['UNION/2011-losalamos-1.JPG', 'UNION/backyard.JPG', 'UNION/DSC00565.JPG', 'UNION/DSC03853.JPG', 'UNION/DSC03890.JPG', 'UNION/pp1e-first.JPG'] to site.zip
Adding  file  UNION/2011-losalamos-1.JPG
Adding  file  UNION/backyard.JPG
Adding  file  UNION/DSC00565.JPG
Adding  file  UNION/DSC03853.JPG
Adding  file  UNION/DSC03890.JPG
Adding  file  UNION/pp1e-first.JPG
Create finished: files=6, folders=0, links=0, unknowns=0, crufts=0.


~/Desktop$ cd UNION
~/Desktop/UNION$ py3 $Z/zip-create.py site '*.JPG'
Zipping ['2011-losalamos-1.JPG', 'backyard.JPG', 'DSC00565.JPG', 'DSC03853.JPG', 'DSC03890.JPG', 'pp1e-first.JPG'] to site.zip
Adding  file  2011-losalamos-1.JPG
Adding  file  backyard.JPG
Adding  file  DSC00565.JPG
Adding  file  DSC03853.JPG
Adding  file  DSC03890.JPG
Adding  file  pp1e-first.JPG
Create finished: files=6, folders=0, links=0, unknowns=0, crufts=0.


~/Desktop/UNION$ cd ..
~/Desktop$ py3 $Z/zip-create.py site 'UNION/wcall*' UNION/vector.py 'UNION/*.JPG' -skipcruft
Zipping ['UNION/wcall.py', 'UNION/wcall_find.py', 'UNION/wcall_find_patt.py', 'UNION/wcall_visitor.py', 'UNION/vector.py', 'UNION/2011-losalamos-1.JPG', 'UNION/backyard.JPG', 'UNION/DSC00565.JPG', 'UNION/DSC03853.JPG', 'UNION/DSC03890.JPG', 'UNION/pp1e-first.JPG'] to site.zip
Cruft patterns: {'keep': ['.htaccess'], 'skip': ['.*', '[dD]esktop.ini', 'Thumbs.db', '~*', '$*', '*.py[co]']}
Adding  file  UNION/wcall.py
Adding  file  UNION/wcall_find.py
Adding  file  UNION/wcall_find_patt.py
Adding  file  UNION/wcall_visitor.py
Adding  file  UNION/vector.py
Adding  file  UNION/2011-losalamos-1.JPG
Adding  file  UNION/backyard.JPG
Adding  file  UNION/DSC00565.JPG
Adding  file  UNION/DSC03853.JPG
Adding  file  UNION/DSC03890.JPG
Adding  file  UNION/pp1e-first.JPG
Create finished: files=11, folders=0, links=0, unknowns=0, crufts=0.


# Shell's globbing same
~/Desktop$ py3 $Z/zip-create.py site UNION/wcall* UNION/vector.py UNION/*.JPG -skipcruft
Zipping ['UNION/wcall.py', 'UNION/wcall_find.py', 'UNION/wcall_find_patt.py', 'UNION/wcall_visitor.py', 'UNION/vector.py', 'UNION/2011-losalamos-1.JPG', 'UNION/DSC00565.JPG', 'UNION/DSC03853.JPG', 'UNION/DSC03890.JPG', 'UNION/backyard.JPG', 'UNION/pp1e-first.JPG'] to site.zip
Cruft patterns: {'skip': ['.*', '[dD]esktop.ini', 'Thumbs.db', '~*', '$*', '*.py[co]'], 'keep': ['.htaccess']}
Adding  file  UNION/wcall.py
Adding  file  UNION/wcall_find.py
Adding  file  UNION/wcall_find_patt.py
Adding  file  UNION/wcall_visitor.py
Adding  file  UNION/vector.py
Adding  file  UNION/2011-losalamos-1.JPG
Adding  file  UNION/DSC00565.JPG
Adding  file  UNION/DSC03853.JPG
Adding  file  UNION/DSC03890.JPG
Adding  file  UNION/backyard.JPG
Adding  file  UNION/pp1e-first.JPG
Create finished: files=11, folders=0, links=0, unknowns=0, crufts=0.



##########################################################################################
# Error checking, scripts only (command-line and interactive modes)
##########################################################################################


#
# Creates
#


~/Desktop$ py3 $Z/zip-create.py site
Too few arguments, run cancelled.
Usage: <python> zip-create.py [zipfile source [source...] [-skipcruft] [-atlinks]]

~/Desktop$ py3 $Z/zip-create.py site.zip nonesuch
Source file "nonesuch" does not exist, run cancelled.
Usage: <python> zip-create.py [zipfile source [source...] [-skipcruft] [-atlinks]]

~/Desktop$ py3 $Z/zip-create.py site.zip . -skipstuff
Source file "-skipstuff" does not exist, run cancelled.
Usage: <python> zip-create.py [zipfile source [source...] [-skipcruft] [-atlinks]]

~/Desktop$ py3 $Z/zip-create.py site.zip -skipcruft
Too few arguments, run cancelled.
Usage: <python> zip-create.py [zipfile source [source...] [-skipcruft] [-atlinks]]

~/Desktop$ py3 $Z/zip-create.py site.zip x y z*
Source file "x" does not exist, run cancelled.
Usage: <python> zip-create.py [zipfile source [source...] [-skipcruft] [-atlinks]]

~/Desktop$ py3 $Z/zip-create.py site.zip x y 'z*'
Source file "x" does not exist, run cancelled.
Usage: <python> zip-create.py [zipfile source [source...] [-skipcruft] [-atlinks]]

~/Desktop$ py3 $Z/zip-create.py site.zip '*.xxx' -skipcruft
No existing source files provided, run cancelled.
Usage: <python> zip-create.py [zipfile source [source...] [-skipcruft] [-atlinks]]

~/Desktop$ py3 $Z/zip-create.py
Zip file to create? 
Items to zip (comma separated)? 
Skip cruft items (y=yes)? 
Follow links to targets (y=yes)? 
About to ZIP
	[''],
	to _default.zip,
	keeping cruft,
	not following links
Confirm with 'y'? y
Source file "" does not exist, run cancelled.
Usage: <python> zip-create.py [zipfile source [source...] [-skipcruft] [-atlinks]]

~/Desktop$ py3 $Z/zip-create.py
Zip file to create? 
Items to zip (comma separated)? 
Skip cruft items (y=yes)? 
Follow links to targets (y=yes)? 
About to ZIP
	[''],
	to _default.zip,
	keeping cruft,
	not following links
Confirm with 'y'? 
Run cancelled.


#
# Extracts
#


~/Desktop$ py3 $Z/zip-extract.py -permissions
Too few or too many arguments, run cancelled.
Usage: <python> zip-extract.py [zipfile [unzipto] [-nofixlinks] [-permissions]]
 
~/Desktop$ py3 $Z/zip-extract.py site.zip unzipped -permis
Too few or too many arguments, run cancelled.
Usage: <python> zip-extract.py [zipfile [unzipto] [-nofixlinks] [-permissions]]

~/Desktop$ py3 $Z/zip-extract.py site.zip -permis
Too few or too many arguments, run cancelled.
Usage: <python> zip-extract.py [zipfile [unzipto] [-nofixlinks] [-permissions]]

~/Desktop$ py3 $Z/zip-extract.py nonesuch.zip unzipped
Zipfile "nonesuch.zip" does not exist, run cancelled.
Usage: <python> zip-extract.py [zipfile [unzipto] [-nofixlinks] [-permissions]]

~/Desktop$ py3 $Z/zip-extract.py nonesuch unzipped
Zipfile "nonesuch.zip" does not exist, run cancelled.
Usage: <python> zip-extract.py [zipfile [unzipto] [-nofixlinks] [-permissions]]

~/Desktop$ py3 $Z/zip-extract.py
Zip file to extract? 
Folder to extract in (use . for here) ? 
Do not localize symlinks (y=yes)? 
Retain access permissions (y=yes)? 
About to UNZIP
	_default.zip,
	to .,
	localizing any links,
	not retaining permissions
Confirm with 'y'? y
Zipfile "_default.zip" does not exist, run cancelled.
Usage: <python> zip-extract.py [zipfile [unzipto] [-nofixlinks] [-permissions]]

~/Desktop$ py3 $Z/zip-extract.py
Zip file to extract? 
Folder to extract in (use . for here) ? 
Do not localize symlinks (y=yes)? 
Retain access permissions (y=yes)? 
About to UNZIP
	_default.zip,
	to .,
	localizing any links,
	not retaining permissions
Confirm with 'y'? 
Run cancelled.

~/Desktop$ py3 $Z/zip-extract.py site.zip testziptools/nonesuch
Unzipping from site.zip to testziptools/nonesuch
...etc...
Extract finished: files=11, folders=0, links=0, unknowns=0.


##########################################################################################
# Devs: the issue fixed for unnested symlinks extracted to "." (ignore empty parent dirs)
##########################################################################################


>>> os.path.dirname(os.path.normpath('./folder/link'))
'folder'
>>> os.path.dirname(os.path.normpath('./link'))
''
>>> os.makedirs(os.path.dirname(os.path.normpath('./link')))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/os.py", line 241, in makedirs
    mkdir(name, mode)
FileNotFoundError: [Errno 2] No such file or directory: ''



[Home page] Books Code Blog Python Author Train Find ©M.Lutz