
import os

from hera_mc import mc


ap = mc.get_mc_argument_parser()
ap.description = """Check that listed files are safely in librarian."""
ap.add_argument("files", type=str, default=None, nargs="*", help="list of files")


args = ap.parse_args()
db = mc.connect_to_mc_db(args)

found_files = []
for pathname in args.files:
    filename = os.path.basename(pathname)
    with db.sessionmaker() as session:
        out = session.get_lib_files(filename)
        if len(out) > 0:
            print(pathname)  # if we have a file, say so


import os

from hera_mc import mc


ap = mc.get_mc_argument_parser()
ap.description = """Check that listed files are safely in librarian."""
ap.add_argument("files", type=str, default=None, nargs="*", help="list of files")


args = ap.parse_args()
db = mc.connect_to_mc_db(args)

found_files = []
with db.sessionmaker() as session:
    for pathname in args.files:
        filename = os.path.basename(pathname)
        out = session.get_lib_files(filename)
        if len(out) > 0:
            print(pathname)  # if we have a file, say so

Move sessionmaker outside of loop
Move sessionmaker outside of loop

  
  import os
  
  from hera_mc import mc
  
  
  ap = mc.get_mc_argument_parser()
  ap.description = """Check that listed files are safely in librarian."""
  ap.add_argument("files", type=str, default=None, nargs="*", help="list of files")
  
  
  args = ap.parse_args()
  db = mc.connect_to_mc_db(args)
  
  found_files = []
+ with db.sessionmaker() as session:
- for pathname in args.files:
+     for pathname in args.files:
-     filename = os.path.basename(pathname)
+         filename = os.path.basename(pathname)
-     with db.sessionmaker() as session:
          out = session.get_lib_files(filename)
          if len(out) > 0:
              print(pathname)  # if we have a file, say so
  
Move sessionmaker outside of loop
## Code Before:

import os

from hera_mc import mc


ap = mc.get_mc_argument_parser()
ap.description = """Check that listed files are safely in librarian."""
ap.add_argument("files", type=str, default=None, nargs="*", help="list of files")


args = ap.parse_args()
db = mc.connect_to_mc_db(args)

found_files = []
for pathname in args.files:
    filename = os.path.basename(pathname)
    with db.sessionmaker() as session:
        out = session.get_lib_files(filename)
        if len(out) > 0:
            print(pathname)  # if we have a file, say so

## Instruction:
Move sessionmaker outside of loop
## Code After:

import os

from hera_mc import mc


ap = mc.get_mc_argument_parser()
ap.description = """Check that listed files are safely in librarian."""
ap.add_argument("files", type=str, default=None, nargs="*", help="list of files")


args = ap.parse_args()
db = mc.connect_to_mc_db(args)

found_files = []
with db.sessionmaker() as session:
    for pathname in args.files:
        filename = os.path.basename(pathname)
        out = session.get_lib_files(filename)
        if len(out) > 0:
            print(pathname)  # if we have a file, say so
