sdputils.py #2

  • //
  • guest/
  • russell_jackson/
  • sdp/
  • Maintenance/
  • sdputils.py
  • View
  • Commits
  • Open Download .zip Download (2 KB)
#!/usr/bin/env python
# ==============================================================================
# Copyright and license info is available in the LICENSE file included with
# the Server Deployment Package (SDP), and also available online:
# https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE
# ------------------------------------------------------------------------------

"""
This module is a convenience for other modules in this directory
"""

# Python 2.7/3.3 compatibility.
from __future__ import print_function

import os
import sys
import platform

class Options:
    server = None
    p4user = None
    passwd = None
    weeks = None
    rawconfig = None

    def get(self, varname):
        return self.rawconfig.get(self.sdp_instance, varname)

class SDPUtils:

    def __init__(self, sdp_instance):
        self.config = Options()
        self.sdp_instance = sdp_instance
        self.config.sdp_instance = sdp_instance

        # Python 2.7/3.3 compatibility.
        if sys.version_info[0] >= 3:
            import configparser
            self.rawconfig = configparser.RawConfigParser()
        else:
            import ConfigParser
            self.rawconfig = ConfigParser.RawConfigParser()

        self.config.rawconfig = self.rawconfig

        ##########################################################################
        #####                                                                #####
        #####  CONFIGURATION VARIABLES: Modify in maintenance.cfg as needed. #####
        #####                                                                #####
        self.rawconfig.read('maintenance.cfg')
        self.config = Options()
        self.config.server = self.rawconfig.get(self.sdp_instance, 'server')
        self.config.p4user = self.rawconfig.get(self.sdp_instance, 'p4user')
        self.config.passwd = self.rawconfig.get(self.sdp_instance, 'passwd')
        self.config.weeks = int(self.rawconfig.get(self.sdp_instance, 'weeks'))

        if platform.system() == "Windows":
            self.p4 = "p4.exe -p %s -u %s" % (self.config.server, self.config.p4user)
        else:
            self.p4 = "/p4/%s/bin/p4_%s  -p %s -u %s" % (self.sdp_instance, self.sdp_instance,
                                                         self.config.server, self.config.p4user)

    def get(self, varname):
        return self.rawconfig.get(self.sdp_instance, varname)

    def login(self):
        os.system('echo %s| %s login -a' % (self.config.passwd, self.p4))
# Change User Description Committed
#6 31825 Russell C. Jackson (Rusty) Converted to use P4 api and to use only python 3.
#5 25025 Russell C. Jackson (Rusty) Fixed typo in sdputils.py and forced cfgweeks to be an int.
#4 24964 Russell C. Jackson (Rusty) Corrected type and ordering issue.
#3 24675 Russell C. Jackson (Rusty) Fixed bugs in sdputils.py and scripts using it.
Converted to standard 2 space spacing, removed copyright stuff.
#2 24648 Russell C. Jackson (Rusty) Updated p4deleteuser to support deleting workspaces off edge servers.
Added -a to login in sdputils.
#1 22693 Russell C. Jackson (Rusty) Branched a Unix only version of the SDP.
Removed extra items to create a cleaner tree.
Moved a few items around to make more sense without Windows in the mix.
//guest/perforce_software/sdp/dev/Maintenance/sdputils.py
#2 22337 Russell C. Jackson (Rusty) Added +x to file types.
#1 16638 C. Thomas Tyler Routine merge down to dev from main using:
p4 merge -b perforce_software-sdp-dev
//guest/perforce_software/sdp/main/Maintenance/sdputils.py
#1 16581 Robert Cowham Standardised processing and formatting.
Made python 2/3 compatible.
These need automated testing!