# Path: moa/sysConf.py
# USERCONFIGFILE = os.path.join(os.path.expanduser('~'),
#                               '.config', 'moa', 'config')
# SYSCONFIGFILE = os.path.join('etc', 'moa', 'config')
# def _interpret_var(v):
#     def __init__(self):
#     def getUser(self):
#     def saveUser(self, conf):
#     def getVersion(self):
# class SysConf(Yaco.Yaco):


import os
import re
import lockfile
import random
import Yaco
import moa.logger
from moa.sysConf import sysConf

def _getUniqueId(project_dir):
    pud_file = os.path.join(project_dir, '.moa', 'project_uid')
    puds = []

    if not os.path.exists(pud_file):
        #touch a new file - if necessary
        with open(pud_file, 'w') as F:
            pass

    with lockfile.FileLock(pud_file):
        if os.path.exists(pud_file):
            with open(pud_file) as F:
                puds = F.read().strip().split()

        pud_candidate = _generateCandidatePud()
        while pud_candidate in puds:
            pud_candidate = _generateCandidatePud()

        puds.append(pud_candidate)
        with open(pud_file, 'w') as F:
            F.write("\n".join(puds))
    return pud_candidate


def hook_postNew():
    """Handle all git changes post New - if this is a project - add a pud
    """

    # was a 'project' created? If not return

# Path: moa/sysConf.py
# USERCONFIGFILE = os.path.join(os.path.expanduser('~'),
#                               '.config', 'moa', 'config')
# SYSCONFIGFILE = os.path.join('etc', 'moa', 'config')
# def _interpret_var(v):
#     def __init__(self):
#     def getUser(self):
#     def saveUser(self, conf):
#     def getVersion(self):
# class SysConf(Yaco.Yaco):


# Path: moa/plugin/system/project.py
import os
import re
import lockfile
import random
import Yaco
import moa.logger
from moa.sysConf import sysConf


def _getUniqueId(project_dir):
    pud_file = os.path.join(project_dir, '.moa', 'project_uid')
    puds = []

    if not os.path.exists(pud_file):
        #touch a new file - if necessary
        with open(pud_file, 'w') as F:
            pass

    with lockfile.FileLock(pud_file):
        if os.path.exists(pud_file):
            with open(pud_file) as F:
                puds = F.read().strip().split()

        pud_candidate = _generateCandidatePud()
        while pud_candidate in puds:
            pud_candidate = _generateCandidatePud()

        puds.append(pud_candidate)
        with open(pud_file, 'w') as F:
            F.write("\n".join(puds))
    return pud_candidate


def hook_postNew():
    """Handle all git changes post New - if this is a project - add a pud
    """

    # was a 'project' created? If not return

    if sysConf.job.template.name != 'project':