<commit_before>'''
 ====================================================================
 Copyright (c) 2003-2016 <NAME>.  All rights reserved.

 This software is licensed as described in the file LICENSE.txt,
 which you should have received as part of this distribution.

 ====================================================================

    wb_git_ui_components.py.py

'''
import os
import time
import shutil
import urllib.parse

import wb_log_history_options_dialog
import wb_platform_specific

import wb_git_ui_actions
import wb_git_project
import wb_git_commit_dialog
import wb_git_log_history
import wb_git_askpass_server
import wb_git_credentials_dialog

import git
import git.exc

#
#   Add tool bars and menu for use in the Main Window
#
#   add the commit code at this level to avoid import loops
#
class GitMainWindowComponents(wb_git_ui_actions.GitMainWindowActions):
    def __init__( self ):
        super().__init__()

        self.askpass_server = None
        self.saved_password = SavedPassword()

    def createProject( self, project ):
        if shutil.which( 'git' ) is None:
            self.app.log.error( '"git" command line tool not found' )
            return None

        try:
            return wb_git_project.GitProject( self.app, project, self )

        except git.exc.InvalidGitRepositoryError as e:
            self.app.log.error( 'Failed to add Git repo %r' % (project.path,) )
            self.app.log.error( 'Git error: %s' % (e,) )
            return None

    def addProjectInitWizardHandler( self, wc_path ):
        self.log.error( 'Under construction %r' % (wc_path,) )
        return False

    def addProjectCloneWizardHandler( self, url, wc_path ):
        self.log.error( 'Under construction %r -> %r' % (url, wc_path) )
        return False

    def setTopWindow( self, top_window ):
        super().setTopWindow( top_window )

        prefs = self.app.prefs.git
        if prefs.program is not None:
            git.Git.GIT_PYTHON_GIT_EXECUTABLE = str(prefs.program)

        self.log.info( 'Git using program %s' % (git.Git.GIT_PYTHON_GIT_EXECUTABLE,) )

        self.askpass_server = wb_git_askpass_server.WbGitAskPassServer( self.app, self )

        devel_fallback = False
        self.askpass_server.start()
        if wb_platform_specific.isWindows():
            askpass  = wb_platform_specific.getAppDir() / 'scm-workbench-askpass.exe'
            if not askpass.exists():
                self.log.info( 'Cannot find %s' % (askpass,) )
                # assume in development environment
                askpass = wb_platform_specific.getAppDir() / 'scm-workbench-askpass.py'

        else:
            askpass = wb_platform_specific.getAppDir() / 'scm-workbench-askpass'

        if not askpass.exists():
            self.log.error( 'Cannot find %s' % (askpass,) )
            return

        os.environ['GIT_ASKPASS'] = str(askpass)

    def about( self ):
        if shutil.which( 'git' ) is None:
            git_ver = '"git" command line tool not found'
<commit_msg>Do not override the user's GIT_ASKPASS config.<commit_after>'''
 ====================================================================
 Copyright (c) 2003-2016 <NAME>.  All rights reserved.

 This software is licensed as described in the file LICENSE.txt,
 which you should have received as part of this distribution.

 ====================================================================

    wb_git_ui_components.py.py

'''
import os
import time
import shutil
import urllib.parse

import wb_log_history_options_dialog
import wb_platform_specific

import wb_git_ui_actions
import wb_git_project
import wb_git_commit_dialog
import wb_git_log_history
import wb_git_askpass_server
import wb_git_credentials_dialog

import git
import git.exc

#
#   Add tool bars and menu for use in the Main Window
#
#   add the commit code at this level to avoid import loops
#
class GitMainWindowComponents(wb_git_ui_actions.GitMainWindowActions):
    def __init__( self ):
        super().__init__()

        self.askpass_server = None
        self.saved_password = <PASSWORD>()

    def createProject( self, project ):
        if shutil.which( 'git' ) is None:
            self.app.log.error( '"git" command line tool not found' )
            return None

        try:
            return wb_git_project.GitProject( self.app, project, self )

        except git.exc.InvalidGitRepositoryError as e:
            self.app.log.error( 'Failed to add Git repo %r' % (project.path,) )
            self.app.log.error( 'Git error: %s' % (e,) )
            return None

    def addProjectInitWizardHandler( self, wc_path ):
        self.log.error( 'Under construction %r' % (wc_path,) )
        return False

    def addProjectCloneWizardHandler( self, url, wc_path ):
        self.log.error( 'Under construction %r -> %r' % (url, wc_path) )
        return False

    def setTopWindow( self, top_window ):
        super().setTopWindow( top_window )

        prefs = self.app.prefs.git
        if prefs.program is not None:
            git.Git.GIT_PYTHON_GIT_EXECUTABLE = str(prefs.program)

        self.log.info( 'Git using program %s' % (git.Git.GIT_PYTHON_GIT_EXECUTABLE,) )

        if 'GIT_ASKPASS' in os.environ:
            self.log.info( "Using user's GIT_ASKPASS program %s" % (os.environ[ 'GIT_ASKPASS' ],)
            return

        self.askpass_server = wb_git_askpass_server.WbGitAskPassServer( self.app, self )

        devel_fallback = False
        self.askpass_server.start()
        if wb_platform_specific.isWindows():
            askpass  = wb_platform_specific.getAppDir() / 'scm-workbench-askpass.exe'
            if not askpass.exists():
                self.log.info( 'Cannot find %s' % (askpass,) )
                # assume in development environment
                askpass = wb_platform_specific.getAppDir() / 'scm-workbench-askpass.py'

        else:
            askpass = wb_platform_specific.getAppDir() / 'scm-workbench-askpass'

        if not askpass.exists():
            self.log.error( 'Cannot find %s' % (askpass,) )
            return

        os.environ['GIT_ASKPASS'] = str(askpass)
        self.log.info( "Using Workbench's GIT_ASKPASS program"

    def about( self ):
        if shutil.which( 'git' ) is None:
            git_ver = '"git" command line tool not found'

{'fraction_non_alphanumeric': 0.13265790723444673, 'fraction_numerical': 0.0025328478708247586, 'mean_word_length': 2.7719402985074626, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '800210', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1883, 'n_words': 498}