Beispiel #1
0
def _main(filepath, options):
    try:
        if options.lines > 0:
            with open(filepath, 'rb') as f:
                if options.head:
                    if options.follow:
                        sys.stderr.write('Cannot follow from top of file.\n')
                        sys.exit(1)
                    lines = head(f, options.lines)
                else:
                    lines = tail(f, options.lines)

                encoding = locale.getpreferredencoding()
                for line in lines:
                    print(line.decode(encoding))

        if options.follow:
            for line in follow_path(filepath):
                if line is not None:
                    print(line)
                else:
                    time.sleep(options.sleep)
    except KeyboardInterrupt:
        # Escape silently
        pass
Beispiel #2
0
def is_text_file(filepath, only_known_types=False):
    filepath = str(filepath)
    filetype = guess_type(filepath)[0]
    if not filetype == None:
        if filetype.startswith("text"):
            return True
        if sys.platform == "win32":
            return False

    if only_known_types == False:
        _file = None
        try:
            _file = file(filepath)
            headlines = head(_file, lines=3)
            for line in headlines:
                line.strip("\r\n").strip("\n").decode("ascii")
            return True
        except UnicodeError:
            pass
        except IOError:
            pass
        finally:
            if not _file == None:
                _file.close()
    return False
Beispiel #3
0
def is_text_file(filepath, only_known_types=False):
    filepath = str(filepath)
    filetype = guess_type(filepath)[0]
    if not filetype == None:
        if filetype.startswith('text'):
            return True
        if sys.platform == 'win32':
            return False

    if only_known_types == False:
        _file = None
        try:
            _file = file(filepath)
            headlines = head(_file, lines=3)
            for line in headlines:
                line.strip('\r\n').strip('\n').decode('ascii')
            return True
        except UnicodeError:
            pass
        except IOError:
            pass
        finally:
            if not _file == None:
                _file.close()
    return False
Beispiel #4
0
def _main(filepath, options):
    try:
        if options.lines > 0:
            with open(filepath, 'rb') as f:
                if options.head:
                    if options.follow:
                        sys.stderr.write('Cannot follow from top of file.\n')
                        sys.exit(1)
                    lines = head(f, options.lines)
                else:
                    lines = tail(f, options.lines)

                encoding = locale.getpreferredencoding()
                for line in lines:
                    print(line.decode(encoding))

        if options.follow:
            for line in follow_path(filepath):
                if line is not None:
                    print(line)
                else:
                    time.sleep(options.sleep)
    except KeyboardInterrupt:
        # Escape silently
        pass
Beispiel #5
0
def show_file_contents(fname, head=0, tail=0):
    for line in tailer.head(open(fname), head):
        print(line)
    print('\t...')
    print('\t...')
    for line in tailer.tail(open(fname), tail):
        print(line)
Beispiel #6
0
def show_file_contents(fname, head=0, tail=0):
    # Display catalog file content
    for line in tailer.head(open(fname), head):
        print(line)
    print('\t...')
    print('\t...')
    for line in tailer.tail(open(fname), tail):
        print(line)
Beispiel #7
0
 	def __init__(self, theFile):
 		self.theFile = theFile
 		self.first = tl.head(open(theFile),1)[0].split()
 		print "the top left corner has position: " + self.first[0] + "\t"+ self.first[1]
 		self.last = tl.tail(open(theFile),1)[0].split()
 		print "the bottom right corner has position: " + self.last[0] + "\t" + self.last[1]
		self.yrange=abs((float(self.last[1])-float(self.first[1]))/DELTAS)
		self.height=self.yrange*DELTAS
		print "the  y-range of our map in boxes: " + str(self.yrange)+ " And the height in wg84 is "+str(self.height)
		self.xrange=abs((float(self.last[0])-float(self.first[0]))/DELTAS)
		self.length=self.xrange*DELTAS
		print "the  x-range of our map in boxes: " + str(self.xrange)+ " And the length in wg84 is "+str(self.length)
Beispiel #8
0
def get_current_temperatures(filename=None, separator=','):
    if filename is None:
        _, filenames = get_temperature_log_file_list()
        filename = filenames[-1]
    with open(filename) as f:
        header = [s.strip() for s in tailer.head(f, 1).pop().split(separator)]
        current_strings = [s.strip() for s in tailer.tail(f, 1).pop().split(separator)]
    current = []
    for s in current_strings:
        try:
            current.append(float(s))
        except ValueError:
            current.append(s)
    return dict(zip(header, current))
Beispiel #9
0
    def __init__(self, file_path, _separator=None, number_of_lines=5):
        headlines = []
        try:
            _file = file(fs.join(*file_path) if hasattr(file_path, "__iter__") else file_path)
            headlines = head(_file, number_of_lines)
            if len(headlines) > number_of_lines:
                headlines = headlines[:number_of_lines]
            _file.close()
        except UnicodeError:
            pass
        except IOError:
            pass

        # get lines with letters [a-z, A-Z]
        self.headers = [line for line in headlines if len(line) > 0 and contains_letter(line)]

        # get lines without letters [a-z, A-Z], national signs could be a problem @IgnorePep8
        self.data = [line for line in headlines if len(line) > 0 and not contains_letter(line)]

        self.initialize()
        self.separator = _separator
Beispiel #10
0
    def __init__(self, file_path, _separator=None, number_of_lines=5):
        headlines = []
        try:
            _file = file(fs.join(*file_path)
                     if hasattr(file_path, '__iter__') else file_path)
            headlines = head(_file, number_of_lines)
            if len(headlines) > number_of_lines:
                headlines = headlines[:number_of_lines]
            _file.close()
        except UnicodeError:
            pass
        except IOError:
            pass

        #get lines with letters [a-z, A-Z]
        self.headers = [line for line in headlines \
                        if len(line) > 0 and contains_letter(line)]

        #get lines without letters [a-z, A-Z], national signs could be a problem @IgnorePep8
        self.data = [line for line in headlines \
                        if len(line) > 0 and not contains_letter(line)]

        self.initialize()
        self.separator = _separator