예제 #1
0
def getProjectTemplateFile():
    " Provides the name of the project template file "
    project = GlobalData().project
    if project.isLoaded():
        # Project is loaded - use from the project dir
        projectDir = os.path.dirname( project.fileName )
        if not projectDir.endswith( os.path.sep ):
            projectDir += os.path.sep
        return projectDir + templateFileName
    return None
예제 #2
0
def getProjectTemplateFile():
    " Provides the name of the project template file "
    project = GlobalData().project
    if project.isLoaded():
        # Project is loaded - use from the project dir
        projectDir = os.path.dirname(project.fileName)
        if not projectDir.endswith(os.path.sep):
            projectDir += os.path.sep
        return projectDir + templateFileName
    return None
예제 #3
0
def getNewFileTemplate():
    " Searches for the template file and fills fields in it "

    templateFile = getProjectTemplateFile()
    if templateFile is None:
        templateFile = getIDETemplateFile()
    elif not os.path.exists( templateFile ):
        templateFile = getIDETemplateFile()

    if not os.path.exists( templateFile ):
        return ""

    # read the file content
    content = []
    f = open( templateFile, "r" )
    for line in f:
        content.append( line.rstrip() )
    f.close()

    # substitute the fields
    project = GlobalData().project
    projectLoaded = project.isLoaded()
    if projectLoaded:
        subs = [ ( re.compile( re.escape( '$projectdate' ), re.I ),
                   project.creationDate ),
                 ( re.compile( re.escape( '$author' ), re.I ),
                   project.author ),
                 ( re.compile( re.escape( '$license' ), re.I ),
                   project.license ),
                 ( re.compile( re.escape( '$copyright' ), re.I ),
                   project.copyright ),
                 ( re.compile( re.escape( '$version' ), re.I ),
                   project.version ),
                 ( re.compile( re.escape( '$email' ), re.I ),
                   project.email ) ]
    else:
        subs = []

    # Common substitutions
    subs.append( ( re.compile( re.escape( '$date' ), re.I ),
                   getLocaleDate() ) )
    subs.append( ( re.compile( re.escape( '$time' ), re.I ),
                   getLocaleTime() ) )
    subs.append( ( re.compile( re.escape( '$user' ), re.I ),
                   getpass.getuser() ) )

    if projectLoaded:
        # description could be multilined so it is a different story
        descriptionRegexp = re.compile( re.escape( '$description' ), re.I )
        description = project.description.split( '\n' )

    result = []
    for line in content:
        for key, value in subs:
            line = re.sub( key, value, line )
        if projectLoaded:
            # description part if so
            match = re.search( descriptionRegexp, line )
            if match is not None:
                # description is in the line
                leadingPart = line[ : match.start() ]
                trailingPart = line[ match.end() : ]
                for dline in description:
                    result.append( leadingPart + dline + trailingPart )
            else:
                result.append( line )
        else:
            result.append( line )

    return "\n".join( result )
예제 #4
0
def getNewFileTemplate():
    " Searches for the template file and fills fields in it "

    templateFile = getProjectTemplateFile()
    if templateFile is None:
        templateFile = getIDETemplateFile()
    elif not os.path.exists(templateFile):
        templateFile = getIDETemplateFile()

    if not os.path.exists(templateFile):
        return ""

    # read the file content
    content = []
    f = open(templateFile, "r")
    for line in f:
        content.append(line.rstrip())
    f.close()

    # substitute the fields
    project = GlobalData().project
    projectLoaded = project.isLoaded()
    if projectLoaded:
        subs = [(re.compile(re.escape('$projectdate'),
                            re.I), project.creationDate),
                (re.compile(re.escape('$author'), re.I), project.author),
                (re.compile(re.escape('$license'), re.I), project.license),
                (re.compile(re.escape('$copyright'), re.I), project.copyright),
                (re.compile(re.escape('$version'), re.I), project.version),
                (re.compile(re.escape('$email'), re.I), project.email)]
    else:
        subs = []

    # Common substitutions
    subs.append((re.compile(re.escape('$date'), re.I), getLocaleDate()))
    subs.append((re.compile(re.escape('$time'), re.I), getLocaleTime()))
    subs.append((re.compile(re.escape('$user'), re.I), getpass.getuser()))

    if projectLoaded:
        # description could be multilined so it is a different story
        descriptionRegexp = re.compile(re.escape('$description'), re.I)
        description = project.description.split('\n')

    result = []
    for line in content:
        for key, value in subs:
            line = re.sub(key, value, line)
        if projectLoaded:
            # description part if so
            match = re.search(descriptionRegexp, line)
            if match is not None:
                # description is in the line
                leadingPart = line[:match.start()]
                trailingPart = line[match.end():]
                for dline in description:
                    result.append(leadingPart + dline + trailingPart)
            else:
                result.append(line)
        else:
            result.append(line)

    return "\n".join(result)