<commit_before>import getpass
from collections import OrderedDict
from pkg_resources import resource_filename
from datetime import datetime as d
from OrthoEvol.Tools.logit import LogIt
from OrthoEvol.Manager.config import templates


class BasePBSJob(object):
    """Base class for PBS jobs."""

    def __init__(self, author=getpass.getuser(), project_name="OrthoEvol", description="This is a basic pbs job",
                 date_format='%a %b %d %I:%M:%S %p %Y', chunk_resources=None, cput='72:00:00', walltime='48:00:00',
                 job_name=None, pbs_work_dir=None, script_cmd=None, email=None, directive_list=None):

        self.pbs_log = LogIt().default(logname="PBS JOB", logfile=None)
        self.temp_pbs = resource_filename(templates.__name__, "temp.pbs")
        # Set up commented script header
        self.author = author
        self.project_name = project_name
        self.description = description
        self.current_date = d.now().strftime(date_format)

        # Set up PBS directives/attributes
        # resources
        if chunk_resources is None:
            chunk_resources = OrderedDict({
                "select": 1,
                "ncpus": 1,
                "memgb": "6gb"
            })

        resource_list = []
        for k, v in chunk_resources.items():
            if v is not None:
                resource_list.append("%s=%s" % (k, v))
        self.resource_str = ":".join(resource_list)
        self.cputime = cput
        self.walltime = walltime
        # other attributes
        self.job_name = job_name
        self.directive_list = directive_list

        # Set up PBS variables
        self.pbs_work_dir = pbs_work_dir
        self.script_cmd = script_cmd
        self.email = email
<commit_msg>Added get_base_job_name method.<commit_after>import getpass
import string
import random
from collections import OrderedDict
from pkg_resources import resource_filename
from datetime import datetime as d
from OrthoEvol.Tools.logit import LogIt
from OrthoEvol.Manager.config import templates


class BasePBSJob(object):
    """Base class for PBS jobs."""

    def __init__(self, author=getpass.getuser(), project_name="OrthoEvol", description="This is a basic pbs job",
                 date_format='%a %b %d %I:%M:%S %p %Y', chunk_resources=None, cput='72:00:00', walltime='48:00:00',
                 job_name=None, pbs_work_dir=None, script_cmd=None, email=None, directive_list=None):

        self.pbs_log = LogIt().default(logname="PBS JOB", logfile=None)
        self.temp_pbs = resource_filename(templates.__name__, "temp.pbs")
        # Set up commented script header
        self.author = author
        self.project_name = project_name
        self.description = description
        self.current_date = d.now().strftime(date_format)

        # Set up PBS directives/attributes
        # resources
        if chunk_resources is None:
            chunk_resources = OrderedDict({
                "select": 1,
                "ncpus": 1,
                "memgb": "6gb"
            })

        resource_list = []
        for k, v in chunk_resources.items():
            if v is not None:
                resource_list.append("%s=%s" % (k, v))
        self.resource_str = ":".join(resource_list)
        self.cputime = cput
        self.walltime = walltime
        # other attributes
        self.base_name = job_name
        self.base_id, self.job_name = self.get_base_job_name()
        self.directive_list = directive_list

        # Set up PBS variables
        self.pbs_work_dir = pbs_work_dir
        self.script_cmd = script_cmd
        self.email = email

    def get_base_job_name(self, length=5):
        base_id = ''.join(random.sample(string.ascii_letters + string.digits, length))
        job_name = self.base_name + "_%s" % base_id

        return base_id, job_name
{'fraction_non_alphanumeric': 0.09958289885297185, 'fraction_numerical': 0.00808133472367049, 'mean_word_length': 2.526654411764706, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '5255127', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1127, 'n_words': 279}