initial commit

This commit is contained in:
Lance Edgar 2012-03-07 06:04:18 -06:00
commit 7aa259c009
13 changed files with 1492 additions and 0 deletions

58
edbob/files.py Normal file
View file

@ -0,0 +1,58 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
#
# edbob -- Pythonic software framework
# Copyright © 2010,2011,2012 Lance Edgar
#
# This file is part of edbob.
#
# edbob is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# edbob is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# edbob. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
``edbob.files`` -- Files & Folders
"""
import os
import tempfile
__all__ = ['count_lines', 'temp_path']
def count_lines(path):
"""
Convenience function to count the number of lines in a text file. Some
attempt is made to ensure cross-platform compatibility.
"""
f = open(path, 'rb')
lines = f.read().count('\n') + 1
f.close()
return lines
def temp_path(suffix='.tmp', prefix='edbob.'):
"""
Convenience function to return a temporary file path. The arguments'
meanings are the same as for ``tempfile.mkstemp()``.
"""
fd, path = tempfile.mkstemp(suffix=suffix, prefix=prefix)
os.close(fd)
os.remove(path)
return path