MCPcopy Index your code
hub / github.com/diffgram/diffgram / process_csv_file

Method process_csv_file

walrus/methods/input/process_media.py:1989–2052  ·  view source on GitHub ↗

Purpose: Handle complete file input, including processing indvidiaul rows Arguments: session, object input, CSV file input temp_dir_path_and_filename, String Returns: True if completed

(self)

Source from the content-addressed store, hash-verified

1987 imageio_read_image = self.raw_numpy_image)
1988
1989 def process_csv_file(self):
1990 """
1991 Purpose:
1992 Handle complete file input, including processing indvidiaul rows
1993
1994 Arguments:
1995 session, object
1996 input, CSV file input
1997 temp_dir_path_and_filename, String
1998
1999 Returns:
2000 True if completed
2001
2002 """
2003 from shared.system_startup.start_media_queue import process_media_queue_manager
2004
2005 row_limit = 10000
2006 with open(self.input.temp_dir_path_and_filename) as csv_file:
2007
2008 csv_reader = csv.reader(csv_file)
2009
2010 for index, row in enumerate(csv_reader):
2011
2012 if index >= row_limit:
2013 print("Reached row limit")
2014 break
2015
2016 # TODO handle if row[0] is empty if that's possible
2017
2018 row_input = Input()
2019 self.session.add(row_input)
2020
2021 row_input.temp_dir = tempfile.mkdtemp()
2022 row_input.directory_id = self.input.directory_id
2023 row_input.project = self.project
2024 row_input.member = self.member
2025 row_input.url = row[0]
2026 row_input.allow_csv = False
2027 row_input.type = "from_url"
2028 row_input.media_type = None
2029 self.try_to_commit()
2030
2031 # Spawn a new instance for each url
2032 # To keep orginal instance seperate
2033
2034 item = PrioritizedItem(
2035 priority = 100,
2036 input_id = row_input.id)
2037 process_media_queue_manager.router(item)
2038
2039 # TODO how to handle removing from directory
2040 # When we end up adding process media things to a queue instead
2041 # of just firing them
2042
2043 # We did not remove the temporary directory
2044 # while looping so do it now
2045 # try:
2046 # shutil.rmtree(self.input.temp_dir)

Callers

nothing calls this directly

Calls 5

try_to_commitMethod · 0.95
InputClass · 0.90
PrioritizedItemClass · 0.90
routerMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected