88from __future__ import unicode_literals
99from collections import defaultdict
1010
11+ DEFAULT_HANDLER = 'title'
12+ """The default handler if none is specified"""
13+
14+
15+ def _get_short_docstring (docstring ):
16+ """
17+ Given a docstring return the first sentence of it.
18+
19+ @param: docstring: str, the docstring to parsde
20+ @return: str, the short docstring
21+ """
22+ return docstring .split ('.' )[0 ].strip ()
23+
1124
1225def title (pset , photo , suffix ):
1326 """
14- Name file after title. Falls back to photo id.
27+ Name file after title (falls back to photo id) .
1528
1629 @param pset: Flickr.Photoset, the photoset
1730 @param photo: Flickr.Photo, the photo
@@ -26,7 +39,7 @@ def title(pset, photo, suffix):
2639
2740def idd (pset , photo , suffix ):
2841 """
29- Name file after id
42+ Name file after photo id.
3043
3144 @param pset: Flickr.Photoset, the photoset
3245 @param photo: Flickr.Photo, the photo
@@ -38,7 +51,7 @@ def idd(pset, photo, suffix):
3851
3952def title_and_id (pset , photo , suffix ):
4053 """
41- Name file after title and photo id
54+ Name file after title and photo id.
4255
4356 @param pset: Flickr.Photoset, the photoset
4457 @param photo: Flickr.Photo, the photo
@@ -57,7 +70,7 @@ def title_and_id(pset, photo, suffix):
5770
5871def title_increment (pset , photo , suffix ):
5972 """
60- Name file after photo title, but add an incrementing counter on duplicates
73+ Name file after photo title, but add an incrementing counter on duplicates.
6174
6275 @param pset: Flickr.Photoset, the photoset
6376 @param photo: Flickr.Photo, the photo
@@ -83,10 +96,25 @@ def title_increment(pset, photo, suffix):
8396}
8497
8598
86- def get_filename_handler (name = 'title' ):
99+ def get_filename_handler (name ):
87100 """
88101 Returns the given filename handler as a function
89102 @param name: str, name of the handler to return
90103 @return: Function, handler
91104 """
92- return HANDLERS [name ]
105+ return HANDLERS [name or DEFAULT_HANDLER ]
106+
107+
108+ def get_filename_handler_help ():
109+ """
110+ Returns a description of each handler to be used for help output.
111+
112+ @return: str, help text
113+ """
114+ ret = []
115+ for name , func in HANDLERS .iteritems ():
116+ ret .append (' {handler} - {doc}{default}'
117+ .format (handler = name ,
118+ doc = _get_short_docstring (func .__doc__ ),
119+ default = (' (DEFAULT)' if name == DEFAULT_HANDLER else '' )))
120+ return 'Naming modes:\n ' + '\n ' .join (ret )
0 commit comments