<commit_before>#!/usr/bin/python
# 
# Setup Settings
#
#==============================================================================#
# Imports
#==============================================================================#

# System Modules
import os
import sys
import glob
import json
from pprint import pprint

# Custom Modules
from lib.send2trash import send2trash # https://github.com/hsoft/send2trash

#==============================================================================#
# Global Variables
#==============================================================================#

mode = ""
# mode = "test"

# Name of the settings file
cfg_file = "sync_settings.json"

#==============================================================================#
# Functions
#==============================================================================#

# symlink(current directory, symlink source folder, symlink destination folder )
# Creates a symlink from a file/path to a give path
def symlink(cur, json, src, dst, title, overwrite_all=None):

  if (title): 
    print title

  # Grab the path from the json parent dir
  json = os.path.dirname(json)
  src = json + "/" + src
  
  # Expand the paths to the current user
  dst = os.path.expanduser(dst)

  if not any( [os.path.isfile(src), os.path.isdir(src), os.path.islink(src)] ):

    print "ERROR: The source doesn't exist"
    print src
    print
    return

  # If the target is an existing file or folder
  # Ask to overwrite it or to skip it
  if any( [os.path.isfile(dst), os.path.isdir(dst), os.path.islink(dst)] ):

    # TODO 001: Remove this unecessary if condition

    # When overwrite_all is "y" or in testing mode
    # Overwrite the file
    if any ( [overwrite_all] ):

      overwrite_all = 1

    else: 

      print "File " + dst + " already exists."
      
      # Check the prompt value for
      #
      # a: Overwrite all files and don't ask anymore if files should be overwritten
      # y: Continue the function and overwrite
      # n: Exit the function and don't overwrite
      #
      # On any other input repeat the prompt
      
      prompt = ""
      
      while all ([
                   prompt != "y", 
                   prompt != "n", 
                   prompt != "a"
                  ]):
        prompt = raw_input("Overwrite (y/n/a): ")

      if (prompt == "a"):
        overwrite_all = 1 # Overwrite All
      elif (prompt == "n"):
        return # Exit
      elif (prompt == "y"):
        pass # Overwrite only this file

  # Trash the resulting destination file or dir
  # And delete symlinks so they don't crowd the trashbin
  if (os.path.islink(dst)):
    os.unlink(dst)
  elif any ([os.path.isfile(dst), os.path.isdir(dst)]): 
    send2trash(dst)

  # Create the symlink
  os.symlink(src, dst)

  # Print the symlink creation information
  print "Creating SymLink: "
  print "  Src: " + src
  print "  Dst: " + dst + "\n"

  return overwrite_all

#==============================================================================#
# Main
#==============================================================================#

def main(argv=None):<commit_msg>Comemnted the output of correct symlinks for now<commit_after>#!/usr/bin/python
# 
# Setup Settings
#
#==============================================================================#
# Imports
#==============================================================================#

# System Modules
import os
import sys
import glob
import json
from pprint import pprint

# Custom Modules
from lib.send2trash import send2trash # https://github.com/hsoft/send2trash

#==============================================================================#
# Global Variables
#==============================================================================#

mode = ""
# mode = "test"

# Name of the settings file
cfg_file = "sync_settings.json"

#==============================================================================#
# Functions
#==============================================================================#

# symlink(current directory, symlink source folder, symlink destination folder )
# Creates a symlink from a file/path to a give path
def symlink(cur, json, src, dst, title, overwrite_all=None):

  if (title): 
    print title

  # Grab the path from the json parent dir
  json = os.path.dirname(json)
  src = json + "/" + src
  
  # Expand the paths to the current user
  dst = os.path.expanduser(dst)

  if not any( [os.path.isfile(src), os.path.isdir(src), os.path.islink(src)] ):

    print "ERROR: The source doesn't exist"
    print src
    print
    return

  # If the target is an existing file or folder
  # Ask to overwrite it or to skip it
  if any( [os.path.isfile(dst), os.path.isdir(dst), os.path.islink(dst)] ):

    # TODO 001: Remove this unecessary if condition

    # When overwrite_all is "y" or in testing mode
    # Overwrite the file
    if any ( [overwrite_all] ):

      overwrite_all = 1

    else: 

      print "File " + dst + " already exists."
      
      # Check the prompt value for
      #
      # a: Overwrite all files and don't ask anymore if files should be overwritten
      # y: Continue the function and overwrite
      # n: Exit the function and don't overwrite
      #
      # On any other input repeat the prompt
      
      prompt = ""
      
      while all ([
                   prompt != "y", 
                   prompt != "n", 
                   prompt != "a"
                  ]):
        prompt = raw_input("Overwrite (y/n/a): ")

      if (prompt == "a"):
        overwrite_all = 1 # Overwrite All
      elif (prompt == "n"):
        return # Exit
      elif (prompt == "y"):
        pass # Overwrite only this file

  # Trash the resulting destination file or dir
  # And delete symlinks so they don't crowd the trashbin
  if (os.path.islink(dst)):
    os.unlink(dst)
  elif any ([os.path.isfile(dst), os.path.isdir(dst)]): 
    send2trash(dst)

  # Create the symlink
  os.symlink(src, dst)

  # Print the symlink creation information
  # print "Creating SymLink: "
  # print "  Src: " + src
  # print "  Dst: " + dst + "\n"

  return overwrite_all

#==============================================================================#
# Main
#==============================================================================#

def main(argv=None):
{'fraction_non_alphanumeric': 0.2840283241542093, 'fraction_numerical': 0.002832415420928403, 'mean_word_length': 3.2916948008102636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '4356317', 'n_tokens_mistral': 1815, 'n_tokens_neox': 1669, 'n_words': 556}