Changeset 3436 for pkpgcounter/trunk/pkpgpdls/plain.py
- Timestamp:
- 10/06/08 00:22:07 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/plain.py
r3410 r3436 8 8 # the Free Software Foundation, either version 3 of the License, or 9 9 # (at your option) any later version. 10 # 10 # 11 11 # This program is distributed in the hope that it will be useful, 12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 # GNU General Public License for more details. 15 # 15 # 16 16 # You should have received a copy of the GNU General Public License 17 17 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 29 29 totiffcommands = [ 'enscript --quiet --portrait --no-header --columns 1 --output - "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -', 30 30 'a2ps --borders 0 --quiet --portrait --no-header --columns 1 --output - "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -', 31 ] 31 ] 32 32 required = [ "a2ps | enscript", "gs" ] 33 openmode = "rU" 33 openmode = "rU" 34 34 format = "plain text" 35 def isValid(self) : 35 def isValid(self) : 36 36 """Returns True if data is plain text, else False. 37 37 38 38 It's hard to detect a plain text file, so we just try to 39 39 extract lines from the first block (sufficiently large). 40 40 If it's impossible to find one we consider it's not plain text. 41 """ 41 """ 42 42 lines = self.firstblock.split("\r\n") 43 43 if len(lines) == 1 : … … 47 47 if len(lines) > 1 : 48 48 return True 49 else : 49 else : 50 50 return False 51 51 52 52 def getJobSize(self) : 53 53 """Counts pages in a plain text document.""" … … 58 58 for line in self.infile : 59 59 if line.endswith("\n") : 60 linecount += 1 60 linecount += 1 61 61 if (linecount > pagesize) : 62 62 pagecount += 1 63 63 linecount = 0 64 else : 64 else : 65 65 cnt = line.count("\f") 66 66 if cnt : 67 67 pagecount += cnt 68 68 linecount = 0 69 else : 69 else : 70 70 raise pdlparser.PDLParserError, "Unsupported file format. Please send the file to %s" % version.__authoremail__ 71 71 return pagecount + 1 # NB : empty files are catched in isValid()