mirror of
https://github.com/aykhans/AzSuicideDataVisualization.git
synced 2025-07-05 15:42:33 +00:00
first commit
This commit is contained in:
@ -0,0 +1,94 @@
|
||||
# BrandProject.py
|
||||
#
|
||||
# Brand a VSS project with a "build number", then optionally
|
||||
# stamp DLL/EXE files with version information.
|
||||
|
||||
import win32api, os, string, sys
|
||||
import vssutil
|
||||
import bulkstamp
|
||||
|
||||
|
||||
def BrandProject(
|
||||
vssProjectName,
|
||||
descFile,
|
||||
stampPath,
|
||||
filesToSubstitute,
|
||||
buildDesc=None,
|
||||
auto=0,
|
||||
bRebrand=0,
|
||||
):
|
||||
# vssProjectName -- The name of the VSS project to brand.
|
||||
# descFile -- A test file containing descriptions of the files in the release.
|
||||
# stampPath -- The full path to where the files referenced in descFile can be found.
|
||||
path = win32api.GetFullPathName(stampPath)
|
||||
|
||||
build = vssutil.MakeNewBuildNo(vssProjectName, buildDesc, auto, bRebrand)
|
||||
if build is None:
|
||||
print("Cancelled")
|
||||
return
|
||||
|
||||
bulkstamp.scan(build, stampPath, descFile)
|
||||
for infile, outfile in filesToSubstitute:
|
||||
SubstituteVSSInFile(vssProjectName, infile, outfile)
|
||||
return 1
|
||||
|
||||
|
||||
def usage(msg):
|
||||
print(msg)
|
||||
print(
|
||||
"""\
|
||||
%s Usage:
|
||||
%s [options] vssProject descFile stampPath
|
||||
|
||||
Automatically brand a VSS project with an automatically incremented
|
||||
build number, and stamp DLL/EXE files with the build number.
|
||||
|
||||
Checks that no files are checked out in the project, and finds the last
|
||||
build number, and suggests the next number.
|
||||
|
||||
Options:
|
||||
-a - Auto increment the build number, and brand (otherwise prompt
|
||||
for the build number after looking for the previous)
|
||||
-r - Restamp the files with the existing build number.
|
||||
-d - A description for the VSS Label.
|
||||
-f infile=outfile - Substitute special VSS labels in the specified text
|
||||
file with the text extracted from VSS.
|
||||
"""
|
||||
% (os.path.basename(sys.argv[0]), os.path.basename(sys.argv[0]))
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
import getopt
|
||||
|
||||
opts, args = getopt.getopt(sys.argv[1:], "af:d:r")
|
||||
except getopts.error as msg:
|
||||
usage(msg)
|
||||
bAuto = bRebrand = 0
|
||||
stampFiles = []
|
||||
desc = None
|
||||
for opt, val in opts:
|
||||
if opt == "-a":
|
||||
bAuto = 1
|
||||
if opt == "-f":
|
||||
infile, outfile = string.split(val, "=", 2)
|
||||
stampFiles.append((infile, outfile))
|
||||
if opt == "-d":
|
||||
desc = val
|
||||
if opt == "-r":
|
||||
bRebrand = 1
|
||||
if len(args) < 3:
|
||||
usage("You must specify the required arguments")
|
||||
vssProjectName = "$\\" + args[0]
|
||||
descFile = args[1]
|
||||
path = args[2]
|
||||
try:
|
||||
os.stat(descFile)
|
||||
except IOError:
|
||||
usage("The description file '%s' can not be found" % (descFile))
|
||||
if not os.path.isdir(path):
|
||||
usage("The path to the files to stamp '%s' does not exist" % (path))
|
||||
|
||||
BrandProject(vssProjectName, descFile, path, stampFiles, desc, bAuto, bRebrand)
|
148
.venv/Lib/site-packages/win32/scripts/VersionStamp/bulkstamp.py
Normal file
148
.venv/Lib/site-packages/win32/scripts/VersionStamp/bulkstamp.py
Normal file
@ -0,0 +1,148 @@
|
||||
#
|
||||
# bulkstamp.py:
|
||||
# Stamp versions on all files that can be found in a given tree.
|
||||
#
|
||||
# USAGE: python bulkstamp.py <version> <root directory> <descriptions>
|
||||
#
|
||||
# Example: python bulkstamp.py 103 ..\win32\Build\ desc.txt
|
||||
#
|
||||
# <version> corresponds to the build number. It will be concatenated with
|
||||
# the major and minor version numbers found in the description file.
|
||||
#
|
||||
# Description information is pulled from an input text file with lines of
|
||||
# the form:
|
||||
#
|
||||
# <basename> <white space> <description>
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# PyWinTypes.dll Common types for Python on Win32
|
||||
# etc
|
||||
#
|
||||
# The product's name, major, and minor versions are specified as:
|
||||
#
|
||||
# name <white space> <value>
|
||||
# major <white space> <value>
|
||||
# minor <white space> <value>
|
||||
#
|
||||
# The tags are case-sensitive.
|
||||
#
|
||||
# Any line beginning with "#" will be ignored. Empty lines are okay.
|
||||
#
|
||||
|
||||
import sys
|
||||
import os
|
||||
import verstamp
|
||||
import fnmatch
|
||||
import win32api
|
||||
|
||||
numStamped = 0
|
||||
|
||||
g_patterns = [
|
||||
"*.dll",
|
||||
"*.pyd",
|
||||
"*.exe",
|
||||
"*.ocx",
|
||||
]
|
||||
|
||||
|
||||
def walk(arg, dirname, names):
|
||||
global numStamped
|
||||
vars, debug, descriptions = arg
|
||||
for name in names:
|
||||
for pat in g_patterns:
|
||||
if fnmatch.fnmatch(name, pat):
|
||||
# Handle the "_d" thing.
|
||||
pathname = os.path.join(dirname, name)
|
||||
base, ext = os.path.splitext(name)
|
||||
if base[-2:] == "_d":
|
||||
name = base[:-2] + ext
|
||||
is_dll = ext.lower() != ".exe"
|
||||
if os.path.normcase(name) in descriptions:
|
||||
desc = descriptions[os.path.normcase(name)]
|
||||
try:
|
||||
verstamp.stamp(vars, pathname, desc, is_dll=is_dll)
|
||||
numStamped = numStamped + 1
|
||||
except win32api.error as exc:
|
||||
print(
|
||||
"Could not stamp",
|
||||
pathname,
|
||||
"Error",
|
||||
exc.winerror,
|
||||
"-",
|
||||
exc.strerror,
|
||||
)
|
||||
else:
|
||||
print("WARNING: description not provided for:", name)
|
||||
# skip branding this - assume already branded or handled elsewhere
|
||||
|
||||
|
||||
# print "Stamped", pathname
|
||||
|
||||
|
||||
def load_descriptions(fname, vars):
|
||||
retvars = {}
|
||||
descriptions = {}
|
||||
|
||||
lines = open(fname, "r").readlines()
|
||||
|
||||
for i in range(len(lines)):
|
||||
line = lines[i].strip()
|
||||
if line != "" and line[0] != "#":
|
||||
idx1 = line.find(" ")
|
||||
idx2 = line.find("\t")
|
||||
if idx1 == -1 or idx2 < idx1:
|
||||
idx1 = idx2
|
||||
if idx1 == -1:
|
||||
print("ERROR: bad syntax in description file at line %d." % (i + 1))
|
||||
sys.exit(1)
|
||||
|
||||
key = line[:idx1]
|
||||
val = line[idx1:].strip()
|
||||
if key in vars:
|
||||
retvars[key] = val
|
||||
else:
|
||||
descriptions[key] = val
|
||||
|
||||
if "product" not in retvars:
|
||||
print("ERROR: description file is missing the product name.")
|
||||
sys.exit(1)
|
||||
if "major" not in retvars:
|
||||
print("ERROR: description file is missing the major version number.")
|
||||
sys.exit(1)
|
||||
if "minor" not in retvars:
|
||||
print("ERROR: description file is missing the minor version number.")
|
||||
sys.exit(1)
|
||||
|
||||
return retvars, descriptions
|
||||
|
||||
|
||||
def scan(build, root, desc, **custom_vars):
|
||||
global numStamped
|
||||
numStamped = 0
|
||||
try:
|
||||
build = int(build)
|
||||
except ValueError:
|
||||
print("ERROR: build number is not a number: %s" % build)
|
||||
sys.exit(1)
|
||||
|
||||
debug = 0 ### maybe fix this one day
|
||||
|
||||
varList = ["major", "minor", "sub", "company", "copyright", "trademarks", "product"]
|
||||
|
||||
vars, descriptions = load_descriptions(desc, varList)
|
||||
vars["build"] = build
|
||||
vars.update(custom_vars)
|
||||
|
||||
arg = vars, debug, descriptions
|
||||
os.path.walk(root, walk, arg)
|
||||
|
||||
print("Stamped %d files." % (numStamped))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 4:
|
||||
print("ERROR: incorrect invocation. See script's header comments.")
|
||||
sys.exit(1)
|
||||
|
||||
scan(*tuple(sys.argv[1:]))
|
201
.venv/Lib/site-packages/win32/scripts/VersionStamp/vssutil.py
Normal file
201
.venv/Lib/site-packages/win32/scripts/VersionStamp/vssutil.py
Normal file
@ -0,0 +1,201 @@
|
||||
import win32con, string, traceback
|
||||
import win32com.client, win32com.client.gencache
|
||||
import pythoncom
|
||||
import time
|
||||
import os
|
||||
|
||||
constants = win32com.client.constants
|
||||
|
||||
win32com.client.gencache.EnsureModule("{783CD4E0-9D54-11CF-B8EE-00608CC9A71F}", 0, 5, 0)
|
||||
|
||||
error = "vssutil error"
|
||||
|
||||
|
||||
def GetSS():
|
||||
ss = win32com.client.Dispatch("SourceSafe")
|
||||
# SS seems a bit weird. It defaults the arguments as empty strings, but
|
||||
# then complains when they are used - so we pass "Missing"
|
||||
ss.Open(pythoncom.Missing, pythoncom.Missing, pythoncom.Missing)
|
||||
return ss
|
||||
|
||||
|
||||
def test(projectName):
|
||||
ss = GetSS()
|
||||
project = ss.VSSItem(projectName)
|
||||
|
||||
for item in project.GetVersions(constants.VSSFLAG_RECURSYES):
|
||||
print(item.VSSItem.Name, item.VersionNumber, item.Action)
|
||||
|
||||
|
||||
# item=i.Versions[0].VSSItem
|
||||
# for h in i.Versions:
|
||||
# print `h.Comment`, h.Action, h.VSSItem.Name
|
||||
|
||||
|
||||
def SubstituteInString(inString, evalEnv):
|
||||
substChar = "$"
|
||||
fields = string.split(inString, substChar)
|
||||
newFields = []
|
||||
for i in range(len(fields)):
|
||||
didSubst = 0
|
||||
strVal = fields[i]
|
||||
if i % 2 != 0:
|
||||
try:
|
||||
strVal = eval(strVal, evalEnv[0], evalEnv[1])
|
||||
newFields.append(strVal)
|
||||
didSubst = 1
|
||||
except:
|
||||
traceback.print_exc()
|
||||
print("Could not substitute", strVal)
|
||||
if not didSubst:
|
||||
newFields.append(strVal)
|
||||
return string.join(map(str, newFields), "")
|
||||
|
||||
|
||||
def SubstituteInFile(inName, outName, evalEnv):
|
||||
inFile = open(inName, "r")
|
||||
try:
|
||||
outFile = open(outName, "w")
|
||||
try:
|
||||
while 1:
|
||||
line = inFile.read()
|
||||
if not line:
|
||||
break
|
||||
outFile.write(SubstituteInString(line, evalEnv))
|
||||
finally:
|
||||
outFile.close()
|
||||
finally:
|
||||
inFile.close()
|
||||
|
||||
|
||||
def VssLog(project, linePrefix="", noLabels=5, maxItems=150):
|
||||
lines = []
|
||||
num = 0
|
||||
labelNum = 0
|
||||
for i in project.GetVersions(constants.VSSFLAG_RECURSYES):
|
||||
num = num + 1
|
||||
if num > maxItems:
|
||||
break
|
||||
commentDesc = itemDesc = ""
|
||||
if i.Action[:5] == "Added":
|
||||
continue
|
||||
if len(i.Label):
|
||||
labelNum = labelNum + 1
|
||||
itemDesc = i.Action
|
||||
else:
|
||||
itemDesc = i.VSSItem.Name
|
||||
if str(itemDesc[-4:]) == ".dsp":
|
||||
continue
|
||||
if i.Comment:
|
||||
commentDesc = "\n%s\t%s" % (linePrefix, i.Comment)
|
||||
lines.append(
|
||||
"%s%s\t%s%s"
|
||||
% (
|
||||
linePrefix,
|
||||
time.asctime(time.localtime(int(i.Date))),
|
||||
itemDesc,
|
||||
commentDesc,
|
||||
)
|
||||
)
|
||||
if labelNum > noLabels:
|
||||
break
|
||||
return string.join(lines, "\n")
|
||||
|
||||
|
||||
def SubstituteVSSInFile(projectName, inName, outName):
|
||||
import win32api
|
||||
|
||||
if win32api.GetFullPathName(inName) == win32api.GetFullPathName(outName):
|
||||
raise RuntimeError("The input and output filenames can not be the same")
|
||||
sourceSafe = GetSS()
|
||||
project = sourceSafe.VSSItem(projectName)
|
||||
# Find the last label
|
||||
label = None
|
||||
for version in project.Versions:
|
||||
if version.Label:
|
||||
break
|
||||
else:
|
||||
print("Couldnt find a label in the sourcesafe project!")
|
||||
return
|
||||
# Setup some local helpers for the conversion strings.
|
||||
vss_label = version.Label
|
||||
vss_date = time.asctime(time.localtime(int(version.Date)))
|
||||
now = time.asctime(time.localtime(time.time()))
|
||||
SubstituteInFile(inName, outName, (locals(), globals()))
|
||||
|
||||
|
||||
def CountCheckouts(item):
|
||||
num = 0
|
||||
if item.Type == constants.VSSITEM_PROJECT:
|
||||
for sub in item.Items:
|
||||
num = num + CountCheckouts(sub)
|
||||
else:
|
||||
if item.IsCheckedOut:
|
||||
num = num + 1
|
||||
return num
|
||||
|
||||
|
||||
def GetLastBuildNo(project):
|
||||
i = GetSS().VSSItem(project)
|
||||
# Find the last label
|
||||
lab = None
|
||||
for version in i.Versions:
|
||||
lab = str(version.Label)
|
||||
if lab:
|
||||
return lab
|
||||
return None
|
||||
|
||||
|
||||
def MakeNewBuildNo(project, buildDesc=None, auto=0, bRebrand=0):
|
||||
if buildDesc is None:
|
||||
buildDesc = "Created by Python"
|
||||
ss = GetSS()
|
||||
i = ss.VSSItem(project)
|
||||
num = CountCheckouts(i)
|
||||
if num > 0:
|
||||
msg = (
|
||||
"This project has %d items checked out\r\n\r\nDo you still want to continue?"
|
||||
% num
|
||||
)
|
||||
import win32ui
|
||||
|
||||
if win32ui.MessageBox(msg, project, win32con.MB_YESNO) != win32con.IDYES:
|
||||
return
|
||||
|
||||
oldBuild = buildNo = GetLastBuildNo(project)
|
||||
if buildNo is None:
|
||||
buildNo = "1"
|
||||
oldBuild = "<None>"
|
||||
else:
|
||||
try:
|
||||
buildNo = string.atoi(buildNo)
|
||||
if not bRebrand:
|
||||
buildNo = buildNo + 1
|
||||
buildNo = str(buildNo)
|
||||
except ValueError:
|
||||
raise error("The previous label could not be incremented: %s" % (oldBuild))
|
||||
|
||||
if not auto:
|
||||
from pywin.mfc import dialog
|
||||
|
||||
buildNo = dialog.GetSimpleInput(
|
||||
"Enter new build number", buildNo, "%s - Prev: %s" % (project, oldBuild)
|
||||
)
|
||||
if buildNo is None:
|
||||
return
|
||||
i.Label(buildNo, "Build %s: %s" % (buildNo, buildDesc))
|
||||
if auto:
|
||||
print("Branded project %s with label %s" % (project, buildNo))
|
||||
return buildNo
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# UpdateWiseExeName("PyWiseTest.wse", "PyWiseTest-10.exe")
|
||||
|
||||
# MakeVersion()
|
||||
# test(tp)
|
||||
# MakeNewBuildNo(tp)
|
||||
tp = "\\Python\\Python Win32 Extensions"
|
||||
SubstituteVSSInFile(
|
||||
tp, "d:\\src\\pythonex\\win32\\win32.txt", "d:\\temp\\win32.txt"
|
||||
)
|
Reference in New Issue
Block a user