Permalink
Browse files

add new rvars module to hold runtime variables

  • Loading branch information...
ilmiont committed Nov 25, 2017
1 parent c565065 commit 134c8bb4934e07bc44a9e3cafe020a9ffa8c9de9
Showing with 95 additions and 0 deletions.
  1. +95 −0 rvars.py
@@ -0,0 +1,95 @@
# -*- coding: utf-8 -*-
#'''
#ipm
#/rvars.py
#By James Walker.
#Copyright ©James Walker 2017. Licensed under the MIT License.
#
#This file contains the rvars runtime variables module for ipm.
#'''
import licenses, strings, time
#'''
#CLASS RuntimeVariables()
#ipm runtime variables.
#'''
class RuntimeVariables():
#'''
#FUNCTION RuntimeVariables.__init__(self)
#Initialises runtime variables.
#'''
def __init__(self):
self.file = ""
self.header = ""
self.license_intro = ""
self.license_phrase = ""
self.license_overview = ""
self.license_synopsis = ""
self.license_text = ""
self.contributions = ""
self.year = time.strftime("%Y")
#'''
#FUNCTION RuntimeVariables.init(self, project)
#Load default variable values from project.
#'''
def init(self, project):
self.make_header(project.title)
self.prepare_license(project.license)
self.get_contributions(project.contributions, project.open_source)
#'''
#FUNCTION RuntimeVariables.get(self, key, value)
#Gets the value of the runtime variable {self}.<key>.
#'''
def get(self, key, value):
return getattr(self, key, value)
#'''
#FUNCTION RuntimeVariables.set(self, key, value)
#Sets the runtime variable {self}.<key> to <value>.
#'''
def set(self, key, value):
return setattr(self, key, value)
#'''
#FUNCTION RuntimeVariables.make_header(self, title)
#Creates the project header string.
#'''
def make_header(self, title):
self.header = title + "\n" + "-" * len(title)
#'''
#FUNCTION RuntimeVariables.prepare_license(self, license)
#Prepares license strings from the project license type.
#'''
def prepare_license(self, license):
if license not in licenses.licenses:
license = "(default)"
self.license_intro = licenses.intros[license]
self.license_phrase = licenses.phrases[license]
self.license_overview = licenses.overviews[license]
self.license_synopsis = licenses.synopsise[license]
with open("licenses/vendor-lib/" + license + ".txt", "r") as license_file:
self.license_text = license_file.read()
#'''
#FUNCTION RuntimeVariables.get_contributions(self, contributions, open_source)
#Generates project contributions string.
def get_contributions(self, contributions, open_source):
if contributions:
self.contributions = strings.CONTRIBUTIONS_Y
else:
if open_source:
self.contributions = strings.CONTRIBUTIONS_N_OS
else:
self.contributions = strings.CONTRIBUTIONS_N
rvars = RuntimeVariables()
#'''
#End of file.
#'''

0 comments on commit 134c8bb

Please sign in to comment.