]>
gitweb.michael.orlitzky.com - dead/pictar.git/blob - Pictar.py
8 from string
import Template
9 from TemplateParser
import *
10 from Mime
.XmlDataParser
import XmlDataParser
16 self
.template_parser
= TemplateParser()
17 self
.__data
_parser
= XmlDataParser(Configuration
.GetMimetypesFilePath())
20 # Compile the regular expressions only once
21 self
.item_regexes
= []
23 extensions
= self
.__data
_parser
.GetAllExtensions()
25 for extension
in extensions
:
26 pattern
= '\\' + extension
+ '$'
27 self
.item_regexes
.append(re
.compile(pattern
, re
.IGNORECASE
))
33 def GetItemPaths(self
):
35 Create a list of the item paths based on which
36 of the files in the target directory match at least
37 one of the item regular expressions.
39 target_dir
= Configuration
.GetAbsTargetDir()
43 dir_contents
= os
.listdir(target_dir
)
45 for file_name
in dir_contents
:
46 for regex_obj
in self
.item_regexes
:
47 if (regex_obj
.search(file_name
) != None):
48 absolute_item_path
= os
.path
.join(target_dir
, file_name
)
49 encoded_path
= urllib
.quote(absolute_item_path
)
50 item_paths
.append(encoded_path
)
56 def GetItemData(self
, item_paths
):
57 """ Build the pictar markup. """
59 current_item_number
= 0
61 for item_path
in item_paths
:
62 current_item_number
+= 1
63 item_extension
= os
.path
.splitext(item_path
)[1]
64 item_template
= Template(self
.__data
_parser
.GetTemplateByExtension(item_extension
))
65 item_mimetype
= self
.__data
_parser
.GetNameByExtension(item_extension
)
67 current_item_data
= item_template
.substitute(header
=item_path
,
69 item_number
=current_item_number
,
70 height
=Configuration
.Defaults
.ITEM_HEIGHT
,
71 width
=Configuration
.Defaults
.ITEM_WIDTH
,
72 mimetype
=item_mimetype
);
74 item_data
+= current_item_data
80 def GetPageData(self
, item_data
):
81 """ Fill in the template with our markup. """
82 stylesheet_file_name
= Configuration
.GetStyleSheetPath()
83 page_template
= self
.template_parser
.GetPageTemplate()
84 page_data
= page_template
.substitute(stylesheet
=stylesheet_file_name
,
85 pictar_markup
=item_data
)
91 def LaunchBrowser(self
, url
='about:blank'):
92 launch_result
= os
.spawnl(os
.P_WAIT
, Configuration
.GetBrowserCommand(), Configuration
.GetBrowserCommand(), url
)
97 def WritePage(self
, page_data
):
98 # Write the output file
99 outfile_path
= Configuration
.GetOutfilePath()
101 outfile
= open(outfile_path
, "w")
102 outfile
.write(page_data
)