                  scriptpath = os.path.realpath(os.path.dirname(sys.argv[0]))
                  img = '.gui_preview.png'
                  imgfile = os.path.join(scriptpath, img)
                  cv2.imwrite(imgfile, image)
              elif self.arguments.preview:
                  with self.lock:
                      self.preview_buffer[name] = image
              elif self.arguments.write_image:
                  cv2.imwrite('_sample_{}.jpg'.format(name), image)
          except Exception as e:
 
</s> remove             if self.arguments.redirect_gui:
                scriptpath = os.path.realpath(os.path.dirname(sys.argv[0]))
                img = '.gui_preview.png'
 </s> add             scriptpath = os.path.realpath(os.path.dirname(sys.argv[0]))
            if self.args.write_image:
                img = "_sample_{}.jpg".format(name)
                imgfile = os.path.join(scriptpath, img)
                cv2.imwrite(imgfile, image)

            if self.args.redirect_gui:
                img = ".gui_preview.png" </s> remove             elif self.arguments.write_image:
                cv2.imwrite('_sample_{}.jpg'.format(name), image)
        except Exception as e:
 </s> add         except Exception as err: </s> remove     preview_buffer = {}

    def show(self, image, name=''):
 </s> add     def show(self, image, name=""):
        """ Generate the preview and write preview file output """ </s> remove             raise e
 </s> add             raise err </s> remove         self.read_alignments()
        is_have_alignments = self.have_alignments()
        for filename in tqdm(self.read_directory()):
            image = cv2.imread(filename)

            if is_have_alignments:
                if self.have_face(filename):
                    faces = self.get_faces_alignments(filename, image)
                else:
                    tqdm.write ('no alignment found for {}, skipping'.format(os.path.basename(filename)))
                    continue
            else:
                faces = self.get_faces(image)
 </s> add         """ Prepare the images for conversion """
        filename = ""
        for filename in tqdm(self.images.input_images):
            if not self.check_alignments(filename):
                continue
            image = Utils.cv2_read_write('read', filename)
            faces = self.faces.get_faces_alignments(filename, image)
            if not faces:
                continue

            elif self.args.preview:
                  scriptpath = os.path.realpath(os.path.dirname(sys.argv[0]))
                  img = '.gui_preview.png'
                  imgfile = os.path.join(scriptpath, img)
                  cv2.imwrite(imgfile, image)
            elif self.args.preview:
                  with self.lock:
                      self.preview_buffer[name] = image
              elif self.arguments.write_image:
                  cv2.imwrite('_sample_{}.jpg'.format(name), image)
          except Exception as e:
keep keep keep keep replace keep keep keep keep keep
 cli/scripts Refactor (#367)

* Refactor for PEP 8 and split process function

* Remove backwards compatibility for skip frames

* Split optional functions into own class. Make functions more modular

* Conform scripts folder to PEP 8

* train.py - Fix write image bug. Make more modular

* extract.py - Make more modular, Put optional actions into own class

* cli.py - start PEP 8

* cli,py - Pep 8. Refactor and make modular. Bugfixes

* 1st round refactor. Completely untested and probably broken.

* convert.py: Extract alignments from frames if they don't exist

* BugFix: SkipExisting broken since face name refactor

* Extract.py tested

* Minor formatting

* convert.py + train.py amended not tested

* train.py - Semi-fix for hang on reaching target iteration. Now quits on preview mode
Make tensorflow / system warning less verbose

* 2nd pass refactor. Semi tested

bugfixes

* Remove obsolete code. imread/write to Utils

* rename inout.py to fsmedia.py

* Final bugfixes 
scripts/train.py