vsgen package

Module contents

Main __init__.py for the vsgen package

class vsgen.VSGSolution(**kwargs)[source]

Bases: vsgen.writer.VSGWritable, vsgen.writer.VSGJinjaRenderer

VSGSolution encapsulates the logic needed to create a .sln file.

Variables:
  • GUID (uuid) – The GUI of the solution; if not provided one is generated automatically.
  • FileName (str) – The absolute filename of the solution file; if not provided the value is “”
  • Name (str) – The display name of the solution; if not provide the value is “”.
  • Projects (list) – The list of VSGProject derived classes; if not provide the value is [].
write()[source]

Writes the .sln file to disk.

class vsgen.VSGProject(**kwargs)[source]

Bases: object

VSGProject encapsulates the data and logic needed to act as a base project.

Variables:
  • GUID (uuid) – The GUID of the project; if not provided one is generated automatically.
  • FileName (str) – The absolute filename of the project file; if not provided the value is “”
  • Name (str) – The display name of the project; if not provide the value is “”.
  • WorkingDirectory (str) – The absolute directory that will be the working directory of the project; if not provide the value is “”
  • OutputPath (str) – The absolute directory that will be the output directory of the project; if not provide the value is “”.
  • RootNamespace (str) – The name of the root namespace of the project; if not provide the value is “”. Ignored.
  • ProjectHome (str) – The absolute directory of the project’s source root folder; if not provide the value is “”
  • StartupFile (str) – The absolute path to the Startup file; if not provide the value is “”
  • CompileFiles (list) – The list of absolute files that will comprise the projects compile group; if not provide the value is [].
  • ContentFiles (list) – The list of absolute files that will comprise the projects content group; if not provide the value is [].
  • Directories (list) – The list of absolute directories that will comprise the projects directory group; if not provide the value is [].
  • DirectoryInFilter (list) – A list of fnmatch expressions to match directories to be included during the item generation step; if not provided the value is [].
  • DirectoryExFilter (list) – A list of fnmatch expressions to match directories to be excludes during the item generation step; if not provided the value is [].
  • CompileInFilter (list) – A list of fnmatch expressions to match compile files to be included during the item generation step; if not provide the value is [].
  • CompileExFilter (list) – A list of fnmatch expressions to match compile files to be excluded during the item generation step; if not provide the value is [].
  • ContentInFilter (list) – A list of fnmatch expressions to match content files to be included during the item generation step; if not provide the value is [].
  • ContentExFilter (list) – A list of fnmatch expressions to match content files to be excluded during the item generation step; if not provide the value is [].
  • VSVersion (float) – The Visual Studio version; if not provide the value is None.
CompileFilesRelative

Returns a generator iterating over the each file in ContentFiles relative to ProjectHome directory.

ContentFilesRelative

Returns a generator iterating over the each file in ContentFiles relative to ProjectHome directory.

DirectoriesRelative

Returns a generator iterating over the each directory referenced by the project, relative to ProjectHome directory.

OutputPathRelative

Returns the OutputPath relative to ProjectHome directory.

ProjectHomeRelative

Returns the ProjectHome relative to FileName directory.

StartupFileRelative

Returns the StartupFile relative to ProjectHome directory.

WorkingDirectoryRelative

Returns the WorkingDirectory relative to ProjectHome directory.

classmethod from_section(config, section, **kwargs)[source]

Creates a VSGProject from a ConfigParser section.

Parameters:
Returns:

A valid VSGProject instance if succesful; None otherwise.

insert_files(rootpath, directoryInFilter=None, directoryExFilter=None, compileInFilter=None, compileExFilter=None, contentInFilter=None, contentExFilter=None)[source]

Inserts files by recursive traversing the rootpath and inserting files according the addition filter parameters.

Parameters:
  • rootpath (str) – The absolute path to the root directory.
  • directoryInFilter (list) – A list of fnmatch expressions to match directories to be included. A None value will default to DirectoryInFilter.
  • directoryExFilter (list) – A list of fnmatch expressions to match directories to be excluded. A None value will default to DirectoryExFilter.
  • compileInFilter (list) – A list of fnmatch expressions to match compile files to be included. A None value will default to CompileInFilter.
  • compileExFilter (list) – A list of fnmatch expressions to match compile files to be excludes. A None value will default to CompileExFilter.
  • contentInFilter (list) – A list of fnmatch expressions to match content files to be includes. A None value will default to ContentInFilter.
  • contentExFilter (list) – A list of fnmatch expressions to match content files to be excludes. A None value will default to ContentExFilter.
class vsgen.VSGRegisterable[source]

Bases: object

An interface class defining methods necessary for VSGRegisterable

lower(value)[source]

Converts a value to lower case in a way compatible with Python2 and Python 3.

Parameters:value (object) – The value to convert.
Returns:The value as lower case text.
register()[source]

Interface method to ‘register’ the object.

text(value)[source]

Converts a value to text in a way compatible with Python2 and Python 3.

Parameters:value (object) – The value to convert.
Returns:The value as text.
upper(value)[source]

Converts a value to upper case text in a way compatible with Python2 and Python 3.

Parameters:value (object) – The value to convert.
Returns:The value as upper case text.
class vsgen.VSGRegisterCommand(logname, registerables)[source]

Bases: object

The VSGRegisterCommand class presents a simple command object to execute the register methods of a collection of VSGRegisterable objects.

execute()[source]

Executes the command.

class vsgen.VSGWriter(pylist)[source]

Bases: threading.Thread

VSGWriter encapsulates the logic needed to write any VSG object to disk.

run()[source]

The Thread’s execution function.

static write(pylist, parallel=True)[source]

Utility method to spawn a VSGWriter for each element in a collection.

Parameters:
  • pylist (list) – A list of VSG objects (PrProjects, VSGSolutions, etc)
  • parallel (bool) – Flag to enable asynchronous writing.
class vsgen.VSGWritable[source]

Bases: object

An interface class defining methods necessary for VSGWriter

lower(value)[source]

Converts a value to lower case in a way compatible with Python2 and Python 3.

Parameters:value (object) – The value to convert.
Returns:The value as lower case text.
text(value)[source]

Converts a value to text in a way compatible with Python2 and Python 3.

Parameters:value (object) – The value to convert.
Returns:The value as text.
upper(value)[source]

Converts a value to upper case text in a way compatible with Python2 and Python 3.

Parameters:value (object) – The value to convert.
Returns:The value as upper case text.
write()[source]

Interface method to ‘write’ the object.

class vsgen.VSGWriteCommand(logname, writables, parallel=True)[source]

Bases: object

The VSGWriteCommand class presents a simple command object to execute the writing methods of a collection of VSGWritable objects.

execute()[source]

Executes the command.

class vsgen.VSGSuite(config)[source]

Bases: object

The VSGSuite class groups a collection of solutions and projects into a single class.

classmethod from_args(**kwargs)[source]

Generates one or more VSGSuite instances from command line arguments.

Parameters:kwargs – List of additional keyworded arguments to be passed into the VSGSuite defined in the make_parser() method.
classmethod from_directory(directory, type, **kwargs)[source]

Creates an VSGSuite instance from a filename.

Parameters:
  • filename (str) – The fully qualified path to the VSG configuration file.
  • type (str) – The configuration type to generate.
  • kwargs – List of additional keyworded arguments to be passed into the VSGSuite.
classmethod from_file(filename)[source]

Creates an VSGSuite instance from a filename.

Parameters:filename (str) – The fully qualified path to the VSG configuration file.
classmethod make_parser(**kwargs)[source]

Creates a ArgumentParser instances to work with VSGSuite classes.

Parameters:kwargs – List of additional keyworded arguments to be passed into the ArgumentParser.
Returns:A ArgumentParser instance.
write(parallel=True)[source]

Writes the configuration to disk.

class vsgen.VSGLogger(filepath=None, threshold=20)[source]

Bases: object

The VSG Logger manages messages associate with various priority level.

Optional, it can redirect the messages to any output channel (usually a file).

BASENAME = 'VSG'
class LevelFilter(levels=None)[source]

Bases: logging.Filter

The LevelFilter class implements a Filter Object specific to the VSGLogger

filter(record)[source]

Returns NoneZero if the recorsd should be logger; zero otherwise.

close()[source]

Closes and unregisters all logging handlers.

classmethod critical(name, message, *args)[source]

Convenience function to log a message at the CRITICAL level.

Parameters:
  • name – The name of the logger instance in the VSG namespace (VSG.<name>)
  • message – A message format string.
  • args – The arguments that are are merged into msg using the string formatting operator.
..note:

The native logger’s kwargs are not used in this function.

classmethod debug(name, message, *args)[source]

Convenience function to log a message at the DEBUG level.

Parameters:
  • name – The name of the logger instance in the VSG namespace (VSG.<name>)
  • message – A message format string.
  • args – The arguments that are are merged into msg using the string formatting operator.
..note:

The native logger’s kwargs are not used in this function.

classmethod error(name, message, *args)[source]

Convenience function to log a message at the ERROR level.

Parameters:
  • name – The name of the logger instance in the VSG namespace (VSG.<name>)
  • message – A message format string.
  • args – The arguments that are are merged into msg using the string formatting operator.
..note:

The native logger’s kwargs are not used in this function.

classmethod exception(name, message, *args)[source]

Convenience function to log a message at the ERROR level with additonal exception information.

Parameters:
  • name – The name of the logger instance in the VSG namespace (VSG.<name>)
  • message – A message format string.
  • args – The arguments that are are merged into msg using the string formatting operator.
..note:

This method should only be called from an exception handler.

classmethod getLogger(name=None)[source]

Retrieves the Python native logger

Parameters:name – The name of the logger instance in the VSG namespace (VSG.<name>); a None value will use the VSG root.
Returns:The instacne of the Python logger object.
classmethod info(name, message, *args)[source]

Convenience function to log a message at the INFO level.

Parameters:
  • name – The name of the logger instance in the VSG namespace (VSG.<name>)
  • message – A message format string.
  • args – The arguments that are are merged into msg using the string formatting operator.
..note:

The native logger’s kwargs are not used in this function.

classmethod warning(name, message, *args)[source]

Convenience function to log a message at the WARNING level.

Parameters:
  • name – The name of the logger instance in the VSG namespace (VSG.<name>)
  • message – A message format string.
  • args – The arguments that are are merged into msg using the string formatting operator.
..note:

The native logger’s kwargs are not used in this function.

class vsgen.VSGTimer(message=None)[source]

Bases: object

The VSGTimer class presents a simply timer using Python’s native time module.

pprint(seconds)[source]

Pretty Prints seconds as Hours:Minutes:Seconds.MilliSeconds

Parameters:seconds – The time in seconds.
start(message)[source]

Manually starts timer with the message.

Parameters:message – The display message.
stop(message)[source]

Manually stops timer with the message.

Parameters:message – The display message.
class vsgen.VSGConfigParser(*args, **kwargs)[source]

Bases: configparser.ConfigParser

The VSG ConfigParser extends Python’s ConfigParser class with VSG specific functionality.

Note:VSGConfigParser uses ExtendedInterpolation as the default interpolation.
getdir(section, option, raw=False, vars=None, fallback='', validate=False)[source]

A convenience method which coerces the option in the specified section to a directory.

getdirs(section, option, raw=False, vars=None, fallback=[])[source]

A convenience method which coerces the option in the specified section to a list of directories.

getfile(section, option, raw=False, vars=None, fallback='', validate=False)[source]

A convenience method which coerces the option in the specified section to a file.

getlist(section, option, raw=False, vars=None, fallback=[], delimiters=', ')[source]

A convenience method which coerces the option in the specified section to a list of strings.

set(section, option, value=None)[source]

Extends set() by auto formatting byte strings into unicode strings.

update(**kwargs)[source]

Extends set() by auto formatting byte strings into unicode strings.