<commit_before>#!/usr/bin/env python
# Copyright (c) 2013 <NAME>.
# License: GPL (http://www.gnu.org/licenses/gpl.html)

import os
import shutil
import urllib
import sublime
import sublime_plugin

# *** GLOBAL VARS ****

# This will represent the current directory of this application
currentdir = None

# This is the dictionary that will contain the extension-path key-value pair
# Ex.:
#     pdf - /path/to/template.pdf
#     js - /path/to/template.js
templateslist = {}

# *** GENERIC FUNCTIONS ****

def noop(fake):
    pass

def raise_error(msg):
    sublime.error_message("ProjectTreeTemplater: An error happened. Please look at the statusbar for extended details.")
    sublime.status_message(msg)

# *** TEMPLATE FUNCTIONS ****

def new_template_file(fullpath):
    # If the file has no templates
    if not copy_template(fullpath):
        # Touch the file
        open(fullpath,'w').close()

def add_template_to_list(spath):
    # Remove the - first character
    if spath[0] == '?':
        spath = spath.lstrip('?')

    global templateslist
    sx,sep,dx = spath.partition(':')
    # Remove the . before the name of the extension (if it is present)
    sx = sx.lstrip('.')
    # Remove the root if inserted
    dx = dx.lstrip('/')
    # Add the extension  to the template list
    templateslist[sx] = currentdir + '/' + dx

def copy_template(spath):
    bret = False

    # Get path to file, and its extension
    spath,ext = os.path.splitext(spath)
    ext = ext.lstrip('.') #Remove the . if present

    # if any template was defined before, let's copy it with the path the user chose
    if ext in templateslist:
        templatepath = templateslist[ext]
        fullpath = spath + '.' + ext
        if 'http://' in templatepath or 'https://' in templatepath:
            try:
                urllib.urlretrieve(templatepath,fullpath)
            except Exception:
                raise_error("The template for file '" + spath + "' does not exists or you do not have the rights to write in the specified path. Will continue with an empty file or generic template (if defined).")
                new_template_file(fullpath)
        else:
            try:
                shutil.copyfile(templatepath,fullpath)
                bret = True
            except Exception:
                raise_error("The path of the template for the extension '" + ext + "' does not exists or isn't accessible. Will continue with an empty file.")<commit_msg>Fixed try...catch for the URLs management<commit_after>#!/usr/bin/env python
# Copyright (c) 2013 <NAME>.
# License: GPL (http://www.gnu.org/licenses/gpl.html)

import os
import shutil
import urllib
import sublime
import sublime_plugin

# *** GLOBAL VARS ****

# This will represent the current directory of this application
currentdir = None

# This is the dictionary that will contain the extension-path key-value pair
# Ex.:
#     pdf - /path/to/template.pdf
#     js - /path/to/template.js
templateslist = {}

# *** GENERIC FUNCTIONS ****

def noop(fake):
    pass

def raise_error(msg):
    sublime.error_message("ProjectTreeTemplater: An error happened. Please look at the statusbar for extended details.")
    sublime.status_message(msg)

# *** TEMPLATE FUNCTIONS ****

def new_template_file(fullpath):
    # If the file has no templates
    if not copy_template(fullpath):
        # Touch the file
        open(fullpath,'w').close()

def add_template_to_list(spath):
    # Remove the - first character
    if spath[0] == '?':
        spath = spath.lstrip('?')

    global templateslist
    sx,sep,dx = spath.partition(':')
    # Remove the . before the name of the extension (if it is present)
    sx = sx.lstrip('.')
    # Remove the root if inserted
    dx = dx.lstrip('/')
    # Add the extension  to the template list
    templateslist[sx] = currentdir + '/' + dx

def copy_template(spath):
    bret = False

    # Get path to file, and its extension
    spath,ext = os.path.splitext(spath)
    ext = ext.lstrip('.') #Remove the . if present

    # if any template was defined before, let's copy it with the path the user chose
    if ext in templateslist:
        templatepath = templateslist[ext]
        fullpath = spath + '.' + ext
        if 'http://' in templatepath or 'https://' in templatepath:
            try:
                urllib.urlretrieve(templatepath,fullpath)
                bret = True
            except Exception:
                raise_error("The path of the template for the extension '" + ext + "' does not exists or isn't accessible. Will continue with an empty file.")
        else:
            try:
                shutil.copyfile(templatepath,fullpath)
                bret = True
            except Exception:
                raise_error("The path of the template for the extension '" + ext + "' does not exists or isn't accessible. Will continue with an empty file.")
{'fraction_non_alphanumeric': 0.10343409418054698, 'fraction_numerical': 0.002056343820686819, 'mean_word_length': 2.6516516516516515, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5412452', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1393, 'n_words': 488}