]>
gitweb.michael.orlitzky.com - dead/pictar.git/blob - Pictar.py
67a056fb42a08dc5e0e4ab5df947208c4e68fea7
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
):
34 # Create a list of the item paths based on which
35 # of the files in the target directory match at least
36 # one of the item regular expressions.
37 target_dir
= Configuration
.GetAbsTargetDir()
41 dir_contents
= os
.listdir(target_dir
)
43 for file_name
in dir_contents
:
44 for regex_obj
in self
.item_regexes
:
45 if (regex_obj
.search(file_name
) != None):
46 absolute_item_path
= os
.path
.join(target_dir
, file_name
)
47 encoded_path
= urllib
.quote(absolute_item_path
)
48 item_paths
.append(encoded_path
)
54 def GetItemData(self
, item_paths
):
55 # Build the pictar markup
57 current_item_number
= 0
59 for item_path
in item_paths
:
60 current_item_number
+= 1
61 item_extension
= os
.path
.splitext(item_path
)[1]
62 item_template
= Template(self
.__data
_parser
.GetTemplateByExtension(item_extension
))
63 item_mimetype
= self
.__data
_parser
.GetNameByExtension(item_extension
)
65 current_item_data
= item_template
.substitute(header
=item_path
,
67 item_number
=current_item_number
,
68 height
=Configuration
.Defaults
.ITEM_HEIGHT
,
69 width
=Configuration
.Defaults
.ITEM_WIDTH
,
70 mimetype
=item_mimetype
);
72 item_data
+= current_item_data
78 def GetPageData(self
, item_data
):
79 # Fill in the template with our markup
80 stylesheet_file_name
= Configuration
.GetStyleSheetPath()
81 page_template
= self
.template_parser
.GetPageTemplate()
82 page_data
= page_template
.substitute(stylesheet
=stylesheet_file_name
,
83 pictar_markup
=item_data
)
89 def LaunchBrowser(self
, url
='about:blank'):
90 launch_result
= os
.spawnl(os
.P_WAIT
, Configuration
.GetBrowserCommand(), Configuration
.GetBrowserCommand(), url
)
95 def WritePage(self
, page_data
):
96 # Write the output file
97 outfile_path
= Configuration
.GetOutfilePath()
99 outfile
= open(outfile_path
, "w")
100 outfile
.write(page_data
)