Пример #1
0
    def __read(self, cursor: CSVLogCursor):
        reader = CSVReader.construct_for_file(
            cursor.file_path,
            empty_string_as_null=self.__empty_string_as_null,
            start_row=cursor.row)
        try:
            self.__read_rows(reader)

        finally:
            reader.close()

            return reader.read_count
Пример #2
0
    def __tail(self, cursor: CSVLogCursor):
        tail = Tail.construct(cursor.file_path)
        tail.open()

        reader = CSVReader(tail,
                           empty_string_as_null=self.__empty_string_as_null,
                           start_row=cursor.row)
        try:
            self.__read_rows(reader)

        except RuntimeError:
            pass  # Python 3.7 response to StopIteration

        except TimeoutError:
            if self.__reporter:
                self.__reporter.timeout(cursor, reader.read_count)

        finally:
            reader.close()
            tail.close()

            return reader.read_count
Пример #3
0
    def retrieve(cls):
        reader = CSVReader.construct_for_file(cls.archive_location(),
                                              numeric_cast=False)

        try:
            for row in reader.rows():
                instance = cls.construct_from_jdict(json.loads(row))

                if instance.pk in cls._retrieved:
                    raise KeyError("duplicate pk '%s' for instance:%s" %
                                   (instance.pk, instance))

                cls._retrieved[instance.pk] = instance

        finally:
            reader.close()
Пример #4
0
#!/usr/bin/env python3
"""
Created on 15 Feb 2018

@author: Bruno Beloff ([email protected])
"""

from scs_core.csv.csv_reader import CSVReader

# --------------------------------------------------------------------------------------------------------------------

dialects = CSVReader.list_dialects()

print(dialects)
Пример #5
0
    cmd = None
    csv = None

    try:
        # ------------------------------------------------------------------------------------------------------------
        # cmd...

        cmd = CmdCSVReader()

        if cmd.verbose:
            print(cmd, file=sys.stderr)

        # ------------------------------------------------------------------------------------------------------------
        # resources...

        csv = CSVReader(cmd.filename)

        if cmd.verbose:
            print(csv, file=sys.stderr)
            sys.stderr.flush()

        # ------------------------------------------------------------------------------------------------------------
        # run...

        for datum in csv.rows:
            print(datum)
            sys.stdout.flush()

    # ----------------------------------------------------------------------------------------------------------------
    # end...
Пример #6
0
    cmd = None
    reader = None

    try:
        # ------------------------------------------------------------------------------------------------------------
        # cmd...

        cmd = CmdCSVReader()

        if cmd.verbose:
            print("csv_reader: %s" % cmd, file=sys.stderr)

        # ------------------------------------------------------------------------------------------------------------
        # resources...

        reader = CSVReader(cmd.filename)

        if cmd.verbose:
            print("csv_reader: %s" % reader, file=sys.stderr)
            sys.stderr.flush()

        # ------------------------------------------------------------------------------------------------------------
        # run...

        for datum in reader.rows:
            print(datum)
            sys.stdout.flush()

    # ----------------------------------------------------------------------------------------------------------------
    # end...
Пример #7
0
    cmd = None
    reader = None

    try:
        # ------------------------------------------------------------------------------------------------------------
        # cmd...

        cmd = CmdCSVReader()

        if cmd.verbose:
            print("csv_reader: %s" % cmd, file=sys.stderr)

        # ------------------------------------------------------------------------------------------------------------
        # resources...

        reader = CSVReader.construct_for_file(cmd.filename)

        if cmd.verbose:
            print("csv_reader: %s" % reader, file=sys.stderr)
            sys.stderr.flush()

        # ------------------------------------------------------------------------------------------------------------
        # run...

        if cmd.array:
            print('[', end='')

        first = True

        for datum in reader.rows():
            if cmd.array:
Пример #8
0
    cmd = CmdCSVReader()

    if cmd.verbose:
        print("csv_reader: %s" % cmd, file=sys.stderr)

    if cmd.array:
        print('[', end='')

    try:
        for filename in cmd.filenames:

            # --------------------------------------------------------------------------------------------------------
            # resources...

            try:
                reader = CSVReader(filename=filename, cast=cmd.cast)
            except FileNotFoundError:
                print("csv_reader: file not found: %s" % filename, file=sys.stderr)
                exit(1)

            if cmd.verbose:
                print("csv_reader: %s" % reader, file=sys.stderr)
                sys.stderr.flush()


            # --------------------------------------------------------------------------------------------------------
            # run...

            for datum in reader.rows:
                if cmd.limit is not None and count >= cmd.limit:
                    break
Пример #9
0
@author: Bruno Beloff ([email protected])
"""

import os

from scs_core.sys.tail import Tail
from scs_core.csv.csv_reader import CSVReader

# --------------------------------------------------------------------------------------------------------------------

path = os.path.expanduser('~/SCS/scs_core/tests/sys/tail_test.json')

tail = Tail.construct(path)
tail.open()
print(tail)

reader = CSVReader(tail)
print(reader)
print("-")

try:
    for message in reader.rows():
        print("got: %s" % message)

finally:
    reader.close()
    tail.close()

    print("done")
Пример #10
0
    if not Join.is_valid_type(cmd.type):
        print("csv_join: invalid join type: %s" % cmd.type, file=sys.stderr)
        exit(2)

    if cmd.verbose:
        print("csv_join: %s" % cmd, file=sys.stderr)

    try:
        # ------------------------------------------------------------------------------------------------------------
        # resources...

        join = Join.construct(cmd.left_prefix, cmd.left_pk, cmd.right_prefix,
                              cmd.right_pk, cmd.iso8601)

        try:
            reader = CSVReader(filename=cmd.left_filename)
        except FileNotFoundError:
            print("csv_join: file not found: %s" % cmd.left_filename,
                  file=sys.stderr)
            exit(1)

        for row in reader.rows:
            jstr = row.strip()
            datum = PathDict.construct_from_jstr(row)

            if datum is None:
                continue

            left_document_count += 1

            if cmd.left_pk not in datum.paths():
Пример #11
0
#!/usr/bin/env python3
"""
Created on 22 Sep 2016

@author: Bruno Beloff ([email protected])
"""

from scs_core.csv.csv_reader import CSVReader

# --------------------------------------------------------------------------------------------------------------------

reader = CSVReader.construct_for_file('test.csv')
print(reader)
print("=")

for datum in reader.rows():
    print(datum)
    print("-")

reader.close()
Пример #12
0
#!/usr/bin/env python3

"""
Created on 22 Sep 2016

@author: Bruno Beloff ([email protected])
"""

from scs_core.csv.csv_reader import CSVReader


# --------------------------------------------------------------------------------------------------------------------

reader = CSVReader('test.csv')
print(reader)
print("=")

for datum in reader.rows:
    print(datum)
    print("-")

reader.close()