예제 #1
0
def main():
    # Parse the options provided.
    helpstring = "python preparetest.py [-t] [-v] [-c] [-r] <target>"
    parser = optparse.OptionParser(usage=helpstring)

    parser.add_option("-t",
                      "--testfiles",
                      action="store_true",
                      dest="include_tests",
                      default=False,
                      help="Include files required to run the unit tests ")
    parser.add_option(
        "-v",
        "--verbose",
        action="store_true",
        dest="verbose",
        default=False,
        help="Show more output on failure to process a .mix file")
    parser.add_option("-c",
                      "--checkapi",
                      action="store_true",
                      dest="copy_checkapi",
                      default=False,
                      help="Include checkAPI files")
    parser.add_option(
        "-r",
        "--randomports",
        action="store_true",
        dest="randomports",
        default=False,
        help=
        "Replace the default ports with random ports between 52000 and 53000. "
    )

    (options, args) = parser.parse_args()

    # Extract the target directory.
    if len(args) == 0:
        help_exit("Please pass the target directory as a parameter.", parser)
    else:
        target_dir = args[0]

    # Make sure they gave us a valid directory
    if not os.path.isdir(target_dir):
        help_exit("Supplied target is not a directory", parser)

    # Set variables according to the provided options.
    repytest = options.include_tests
    RANDOMPORTS = options.randomports
    verbose = options.verbose
    copy_checkapi = options.copy_checkapi

    # This script's parent directory is the root dir of all repositories
    repos_root_dir = os.path.dirname(os.getcwd())

    # Set working directory to the target
    os.chdir(target_dir)
    files_to_remove = glob.glob("*")

    # Empty the destination
    for entry in files_to_remove:
        if os.path.isdir(entry):
            shutil.rmtree(entry)
        else:
            os.remove(entry)

    # Create directories for each Repy version under the target
    repy_dir = {
        "v1": os.path.join(target_dir, "repyV1"),
        "v2": os.path.join(target_dir, "repyV2")
    }

    for dir_name in repy_dir.values():
        if not os.path.exists(dir_name):
            os.makedirs(dir_name)

    # Return to the repo root
    os.chdir(repos_root_dir)

    # Copy the necessary files to the respective target folders:
    # Affix framework and components
    copy_to_target("affix/*", target_dir)
    copy_to_target("affix/components/*", target_dir)
    copy_to_target("affix/services/tcp_relay/*", target_dir)

    # Nodemanager and RepyV2 runtime
    copy_to_target("repy_v2/*", target_dir)
    copy_to_target("nodemanager/*", target_dir)
    copy_to_target("portability/*", target_dir)
    copy_to_target("seattlelib_v2/*", target_dir)

    # RepyV2 runtime for vessels
    copy_to_target("portability/*", repy_dir["v2"])
    copy_to_target("repy_v2/*", repy_dir["v2"])
    copy_to_target("seattlelib_v2/dylink.r2py", repy_dir["v2"])
    copy_to_target("seattlelib_v2/textops.py", repy_dir["v2"])
    copy_to_target("nodemanager/servicelogger.py", repy_dir["v2"])

    # RepyV1 runtime for vessels
    copy_to_target("repy_v1/*", repy_dir["v1"])

    # Seash
    copy_to_target("seash/*", target_dir)
    copy_tree_to_target("seash/pyreadline/",
                        os.path.join(target_dir, 'pyreadline/'),
                        ignore=".git")
    copy_tree_to_target("seash/modules/",
                        os.path.join(target_dir, 'modules/'),
                        ignore=".git")

    # Clearinghouse XML-RPC interface
    copy_to_target("common/seattleclearinghouse_xmlrpc.py", target_dir)

    # Software updater
    copy_to_target("softwareupdater/*", target_dir)
    copy_to_target("dist/update_crontab_entry.py", target_dir)

    # The license must be included in anything we distribute.
    copy_to_target("common/LICENSE", target_dir)

    if repytest:
        # Only copy the tests if they were requested.
        copy_to_target("repy_v2/tests/restrictions.*", target_dir)
        copy_to_target("utf/*.py", target_dir)
        copy_to_target("utf/tests/*.py", target_dir)
        copy_to_target(
            "repy_v2/testsV2/*",
            target_dir)  # XXX Scheduled for merge with repy_v2/tests
        copy_to_target("nodemanager/tests/*", target_dir)
        copy_to_target("portability/tests/*", target_dir)
        copy_to_target("seash/tests/*", target_dir)
        copy_tree_to_target("seash/tests/modules/",
                            os.path.join(target_dir, 'modules/'),
                            ignore=".git")
        copy_to_target("seattlelib_v2/tests/*", target_dir)

        # The web server is used in the software updater tests
        #copy_to_target("assignments/webserver/*", target_dir)
        #copy_to_target("softwareupdater/test/*", target_dir)

    # Set working directory to the target
    os.chdir(target_dir)

    # Set up dynamic port information
    if RANDOMPORTS:
        print "\n[ Randomports option was chosen ]\n" + '-' * 50
        ports_as_ints = random.sample(range(52000, 53000), 5)
        ports_as_strings = []
        for port in ports_as_ints:
            ports_as_strings.append(str(port))

        print "Randomly chosen ports: ", ports_as_strings
        testportfiller.replace_ports(ports_as_strings, ports_as_strings)

        # Replace the string <nodemanager_port> with a random port
        random_nodemanager_port = random.randint(53000, 54000)
        print "Chosen random nodemanager port: " + str(random_nodemanager_port)
        print '-' * 50 + "\n"
        replace_string("<nodemanager_port>", str(random_nodemanager_port),
                       "*nm*")
        replace_string("<nodemanager_port>", str(random_nodemanager_port),
                       "*securitylayers*")

    else:
        # Otherwise use the default ports...
        testportfiller.replace_ports(
            ['12345', '12346', '12347', '12348', '12349'],
            ['12345', '12346', '12347', '12348', '12349'])

        # Use default port 1224 for the nodemanager port if --random flag is not provided.
        replace_string("<nodemanager_port>", '1224', "*nm*")
        replace_string("<nodemanager_port>", '1224', "*securitylayers*")

    os.chdir("repyV1")
    process_mix("repypp.py", verbose)

    # Change back to root project directory
    os.chdir(repos_root_dir)
예제 #2
0
def main():
    repytest = False
    RANDOMPORTS = False
    force_install = False
    clean_install = False

    target_dir = None
    for arg in sys.argv[1:]:
        # -t means we will copy repy tests
        if arg == '-t':
            repytest = True

        # The user wants us to fill in the port numbers randomly.
        elif arg == '-randomports':
            RANDOMPORTS = True

        # Force install if target_dir does not exists
        elif arg == '-f':
            force_install = True

        elif arg == '-clean':
            clean_install = True

        # Not a flag? Assume it's the target directory
        else:
            target_dir = arg

    # We need a target dir. If one isn't found in argv, quit.
    if target_dir is None:
        help_exit("Please pass the target directory as a parameter.")

    #store root directory
    current_dir = os.getcwd()

    # Make sure they gave us a valid directory
    if not os.path.isdir(target_dir) and not force_install:
        help_exit("given foldername is not a directory")

    # Remove existing file
    if os.path.isfile(target_dir):
        os.remove(target_dir)

    # Make target directory
    if not os.path.exists(target_dir):
        os.mkdir(target_dir)

    if clean_install:
        #set working directory to the test folder
        os.chdir(target_dir)
        files_to_remove = glob.glob("*")

        #clean the test folder
        for f in files_to_remove:
            if os.path.isdir(f):
                shutil.rmtree(f)
            else:
                os.remove(f)

    #go back to root project directory
    os.chdir(current_dir)

    #now we copy the necessary files to the test folder
    copy_to_target("repy/*", target_dir)
    copy_to_target("nodemanager/*", target_dir)
    copy_to_target("portability/*", target_dir)
    copy_to_target("seattlelib/*", target_dir)
    copy_to_target("seattlelib/fs/*", target_dir)
    copy_to_target("seattlelib/sys/*", target_dir)
    copy_to_target("seattlelib/net/*", target_dir)
    copy_to_target("seattlelib/lind/*", target_dir)
    copy_to_target("seattlelib/xmplrpc/*", target_dir)
    copy_to_target("seattlelib/librepy/*", target_dir)
    copy_to_target("seash/*", target_dir)
    copy_to_target("shims/*", target_dir)
    copy_to_target("fuse/lind_fuse.py", target_dir)
    copy_to_target("softwareupdater/*", target_dir)
    copy_to_target("autograder/nm_remote_api.mix", target_dir)
    copy_to_target("keydaemon/*", target_dir)
    copy_to_target("tools/*", target_dir)
    # The license must be included in anything we distribute.
    copy_to_target("LICENSE.TXT", target_dir)

    if repytest:
        # Only copy the tests if they were requested.
        copy_to_target("repy/tests/restrictions.*", target_dir)
        copy_to_target("utf/*.py", target_dir)
        copy_to_target("repy/testsV2/*", target_dir)
        #copy_to_target("nodemanager/tests/*", target_dir)
        #copy_to_target("portability/tests/*", target_dir)
        #copy_to_target("seash/tests/*", target_dir)
        copy_to_target("seattlelib/testdir/tests/*", target_dir)
        #copy_to_target("keydaemon/tests/*", target_dir)
        copy_to_target("dist/update_crontab_entry.py", target_dir)
        copy_to_target("shims/tests/*", target_dir)
        copy_to_target("fuse/test_fuse.sh", target_dir)

        # The web server is used in the software updater tests
        #copy_to_target("assignments/webserver/*", target_dir)
        #copy_to_target("softwareupdater/test/*", target_dir)

    #insatll lind test files
    setup_lind_tests(target_dir)

    #set working directory to the test folder
    os.chdir(target_dir)

    #call the process_mix function to process all mix files in the target directory
    process_mix("repypp.py")

    # set up dynamic port information
    if RANDOMPORTS:
        portstouseasints = random.sample(range(52000, 53000), 3)
        portstouseasstr = []
        for portint in portstouseasints:
            portstouseasstr.append(str(portint))

        print "Randomly chosen ports: ", portstouseasstr
        testportfiller.replace_ports(portstouseasstr, portstouseasstr)
    else:
        # if this isn't specified, just use the default ports...
        testportfiller.replace_ports(['12345', '12346', '12347'],
                                     ['12345', '12346', '12347'])

    #go back to root project directory
    os.chdir(current_dir)
예제 #3
0
def main():
  repytest = False
  RANDOMPORTS = False
  verbose = False
	
  target_dir = None

  # Parse the options provided.
  parser = optparse.OptionParser()

  parser.add_option("-t", "--include-test-files", action="store_true",
                    dest="include_tests", help="Include the test " +
                    "files in the output directory.")
  parser.add_option("-v", "--verbose", action="store_true",
                    dest="verbose", help="Show more output on failure")
  parser.add_option("-r", "--randomports", action="store_true", 
                    dest="randomports", help="Fill in the ports randomly")

  (options, args) = parser.parse_args()

  # Set certain variables according to the options provided.
  if options.include_tests:
    repytest = True
  if options.randomports:
    RANDOMPORTS = True
  if options.verbose:
    verbose = True

  # Extract the target directory if available.
  if len(args) == 0:
    help_exit("Please pass the target directory as a parameter.", parser)
  else:
    target_dir = args[0]


  #store root directory
  current_dir = os.getcwd()

  # Make sure they gave us a valid directory
  if not( os.path.isdir(target_dir) ):
    help_exit("given foldername is not a directory", parser)

  #set working directory to the test folder
  os.chdir(target_dir)	
  files_to_remove = glob.glob("*")

  #clean the test folder
  for f in files_to_remove: 
    if os.path.isdir(f):
      shutil.rmtree(f)		
    else:
      os.remove(f)

  #go back to root project directory
  os.chdir(current_dir) 

  #now we copy the necessary files to the test folder
  copy_to_target("repy/*", target_dir)
  copy_to_target("nodemanager/*", target_dir)
  copy_to_target("portability/*", target_dir)
  copy_to_target("seattlelib/*", target_dir)
  copy_to_target("seash/*", target_dir)
  copy_to_target("softwareupdater/*", target_dir)
  copy_to_target("autograder/nm_remote_api.mix", target_dir)
  copy_to_target("keydaemon/*", target_dir)
  # The license must be included in anything we distribute.
  copy_to_target("LICENSE.TXT", target_dir)

  if USE_SHIMS:
    # Copy over the files needed for using shim.
    copy_to_target("production_nat_new/src/*", target_dir)
    copy_to_target("production_nat_new/src/nmpatch/nmmain.py", target_dir)
    copy_to_target("production_nat_new/src/nmpatch/nminit.mix", target_dir)
    copy_to_target("production_nat_new/src/nmpatch/nmclient.repy", target_dir)
    copy_to_target("production_nat_new/src/nmpatch/nmclient_shims.mix", target_dir)
    copy_to_target("production_nat_new/src/nmpatch/sockettimeout.repy", target_dir)

  
  # Only copy the tests if they were requested.
  if repytest:
    # The test framework itself.
    copy_to_target("utf/*.py", target_dir)
    # The various tests.
    copy_to_target("repy/tests/*", target_dir)
    copy_to_target("nodemanager/tests/*", target_dir)
    copy_to_target("portability/tests/*", target_dir)  	
    copy_to_target("seash/tests/*", target_dir)
    copy_to_target("oddball/tests/*", target_dir)
    copy_to_target("seattlelib/tests/*", target_dir)
    copy_to_target("keydaemon/tests/*", target_dir)
    copy_to_target("utf/tests/*", target_dir)
    # jsamuel: This file, dist/update_crontab_entry.py, is directly included by
    # make_base_installers and appears to be a candidate for removal someday.
    # I assume zackrb needed this for installer testing.
    copy_to_target("dist/update_crontab_entry.py", target_dir)

    if USE_SHIMS:
      # Unit tests for shims
      copy_to_target("production_nat_new/src/unit_tests/*", target_dir)

  #set working directory to the test folder
  os.chdir(target_dir)


  # set up dynamic port information
  if RANDOMPORTS:
    print "\n[ Randomports option was chosen ]\n"+'-'*50
    portstouseasints = random.sample(range(52000, 53000), 3)
    portstouseasstr = []
    for portint in portstouseasints:
      portstouseasstr.append(str(portint))
    
    print "Randomly chosen ports: ",portstouseasstr
    testportfiller.replace_ports(portstouseasstr, portstouseasstr)

    # Replace the string <nodemanager_port> with a random port
    random_nodemanager_port = random.randint(53000, 54000)
    print "Chosen random nodemanager port: " + str(random_nodemanager_port)
    print '-'*50 + "\n"
    replace_string("<nodemanager_port>", str(random_nodemanager_port), "*nm*")
    replace_string("<nodemanager_port>", str(random_nodemanager_port), "*securitylayers*")
    
  else:
    # if this isn't specified, just use the default ports...
    testportfiller.replace_ports(['12345','12346','12347'], ['12345','12346','12347'])

    # Use default port 1224 for the nodemanager port if --random flag is not provided.
    replace_string("<nodemanager_port>", '1224', "*nm*")
    replace_string("<nodemanager_port>", '1224', "*securitylayers*")



  #call the process_mix function to process all mix files in the target directory
  process_mix("repypp.py", verbose)

  #go back to root project directory
  os.chdir(current_dir) 
예제 #4
0
def main():
  repytest = False
  RANDOMPORTS = False
	
  target_dir = None
  for arg in sys.argv[1:]:
    # -t means we will copy repy tests
    if arg == '-t':
      repytest = True

    # The user wants us to fill in the port numbers randomly.
    elif arg == '-randomports':
      RANDOMPORTS = True

    # Not a flag? Assume it's the target directory
    else:
      target_dir = arg

  # We need a target dir. If one isn't found in argv, quit.
  if target_dir is None:
    help_exit("Please pass the target directory as a parameter.")

  #store root directory
  current_dir = os.getcwd()

  # Make sure they gave us a valid directory
  if not( os.path.isdir(target_dir) ):
    help_exit("given foldername is not a directory")

  #set working directory to the test folder
  os.chdir(target_dir)	
  files_to_remove = glob.glob("*")

  #clean the test folder
  for f in files_to_remove: 
    if os.path.isdir(f):
      shutil.rmtree(f)		
    else:
      os.remove(f)

  #go back to root project directory
  os.chdir(current_dir) 

  #now we copy the necessary files to the test folder
  copy_to_target("repy/*", target_dir)
  copy_to_target("nodemanager/*", target_dir)
  copy_to_target("portability/*", target_dir)
  copy_to_target("seattlelib/*", target_dir)
  copy_to_target("seash/*", target_dir)
  copy_to_target("shims/*", target_dir)
  copy_to_target("fuse/lind_fuse.py", target_dir)
  copy_to_target("softwareupdater/*", target_dir)
  copy_to_target("autograder/nm_remote_api.mix", target_dir)
  copy_to_target("keydaemon/*", target_dir)
  copy_to_target("tools/*", target_dir)
  # The license must be included in anything we distribute.
  copy_to_target("LICENSE.TXT", target_dir)
  
  if repytest:
    # Only copy the tests if they were requested.
    copy_to_target("repy/tests/restrictions.*", target_dir)
    copy_to_target("utf/*.py", target_dir)
    copy_to_target("repy/testsV2/*", target_dir)
    #copy_to_target("nodemanager/tests/*", target_dir)
    #copy_to_target("portability/tests/*", target_dir)
    #copy_to_target("seash/tests/*", target_dir)
    copy_to_target("seattlelib/tests/*", target_dir)
    #copy_to_target("keydaemon/tests/*", target_dir)
    copy_to_target("dist/update_crontab_entry.py", target_dir)
    copy_to_target("shims/tests/*", target_dir)
    copy_to_target("fuse/test_fuse.sh", target_dir)

    # The web server is used in the software updater tests
    #copy_to_target("assignments/webserver/*", target_dir)
    #copy_to_target("softwareupdater/test/*", target_dir)


  #set working directory to the test folder
  os.chdir(target_dir)

  #call the process_mix function to process all mix files in the target directory
  process_mix("repypp.py")

  #install lind test files.   I'm in the target_dir...
  setup_lind_tests(".")

  # set up dynamic port information
  if RANDOMPORTS:
    portstouseasints = random.sample(range(52000, 53000), 3)
    portstouseasstr = []
    for portint in portstouseasints:
      portstouseasstr.append(str(portint))
    
    print "Randomly chosen ports: ",portstouseasstr
    testportfiller.replace_ports(portstouseasstr, portstouseasstr)
  else:
    # if this isn't specified, just use the default ports...
    testportfiller.replace_ports(['12345','12346','12347'], ['12345','12346','12347'])

  #go back to root project directory
  os.chdir(current_dir) 
예제 #5
0
def main():

    # Parse the options provided.
    helpstring = "python preparetest.py [-t] [-v] [-c] [-r] <target>"
    parser = optparse.OptionParser(usage=helpstring)

    parser.add_option("-t",
                      "--testfiles",
                      action="store_true",
                      dest="include_tests",
                      default=False,
                      help="Include files required to run the unit tests ")
    parser.add_option(
        "-v",
        "--verbose",
        action="store_true",
        dest="verbose",
        default=False,
        help="Show more output on failure to process a .mix file")
    parser.add_option("-c",
                      "--checkapi",
                      action="store_true",
                      dest="copy_checkapi",
                      default=False,
                      help="Include checkAPI files")
    parser.add_option(
        "-r",
        "--randomports",
        action="store_true",
        dest="randomports",
        default=False,
        help="Replace the default ports with random ports between \
                           52000 and 53000. ")

    (options, args) = parser.parse_args()

    # Extract the target directory.
    if len(args) == 0:
        help_exit("Please pass the target directory as a parameter.", parser)
    else:
        target_dir = args[0]

    # Make sure they gave us a valid directory
    if not (os.path.isdir(target_dir)):
        help_exit("Supplied target is not a directory", parser)

    # Set variables according to the provided options.
    repytest = options.include_tests
    RANDOMPORTS = options.randomports
    verbose = options.verbose
    copy_checkapi = options.copy_checkapi

    # Store current directory
    current_dir = os.getcwd()

    # Set working directory to the target
    os.chdir(target_dir)
    files_to_remove = glob.glob("*")

    # Empty the destination
    for entry in files_to_remove:
        if os.path.isdir(entry):
            shutil.rmtree(entry)
        else:
            os.remove(entry)

    # Return to previous working directory
    os.chdir(current_dir)

    # Create the two required directories
    repy_dir_dict = {
        'repyv1': os.path.join(target_dir, "repyV1"),
        'repyv2': os.path.join(target_dir, "repyV2")
    }

    for repy_dir in repy_dir_dict.values():
        if not os.path.exists(repy_dir):
            os.makedirs(repy_dir)

    # Copy the necessary files to the test folder
    copy_to_target("repy/*", target_dir)
    copy_to_target("repy/*", os.path.join(target_dir, "repyV2"))
    copy_to_target("repy/repyV1/*", os.path.join(target_dir, "repyV1"))
    copy_to_target("nodemanager/*", target_dir)
    copy_to_target("portability/*", target_dir)
    copy_to_target("portability/*", os.path.join(target_dir, "repyV2"))
    copy_to_target("seattlelib/*", target_dir)
    copy_to_target("seattlelib/dylink.r2py",
                   os.path.join(target_dir, "repyV2"))
    copy_to_target("seattlelib/textops.py", os.path.join(target_dir, "repyV2"))
    copy_to_target("nodemanager/servicelogger.py",
                   os.path.join(target_dir, "repyV2"))
    copy_to_target("seash/*", target_dir)
    copy_tree_to_target("seash/pyreadline/",
                        os.path.join(target_dir, 'pyreadline/'),
                        ignore=".svn")
    copy_tree_to_target("seash/modules/",
                        os.path.join(target_dir, 'modules/'),
                        ignore=".svn")
    copy_to_target("seattlegeni/xmlrpc_clients/*", target_dir)
    copy_to_target("affix/*", target_dir)
    #copy_to_target("shims/proxy/*", target_dir)
    copy_to_target("softwareupdater/*", target_dir)
    copy_to_target("autograder/nm_remote_api.mix", target_dir)
    copy_to_target("keydaemon/*", target_dir)
    copy_to_target("dist/update_crontab_entry.py", target_dir)
    # The license must be included in anything we distribute.
    copy_to_target("LICENSE.TXT", target_dir)

    # CheckAPI source
    if copy_checkapi:
        copy_to_target("checkapi/*", target_dir)

    if repytest:
        # Only copy the tests if they were requested.
        copy_to_target("repy/tests/restrictions.*", target_dir)
        copy_to_target("utf/*.py", target_dir)
        copy_to_target("utf/tests/*.py", target_dir)
        copy_to_target("repy/testsV2/*", target_dir)
        copy_to_target("nodemanager/tests/*", target_dir)
        copy_to_target("portability/tests/*", target_dir)
        copy_to_target("seash/tests/*", target_dir)
        copy_tree_to_target("seash/tests/modules/",
                            os.path.join(target_dir, 'modules/'),
                            ignore=".svn")
        copy_to_target("seattlelib/tests/*", target_dir)
        #copy_to_target("keydaemon/tests/*", target_dir)
        copy_to_target("shims/tests/*", target_dir)

        # The web server is used in the software updater tests
        #copy_to_target("assignments/webserver/*", target_dir)
        #copy_to_target("softwareupdater/test/*", target_dir)

    # Set working directory to the target
    os.chdir(target_dir)

    # Set up dynamic port information
    if RANDOMPORTS:
        print "\n[ Randomports option was chosen ]\n" + '-' * 50
        ports_as_ints = random.sample(range(52000, 53000), 5)
        ports_as_strings = []
        for port in ports_as_ints:
            ports_as_strings.append(str(port))

        print "Randomly chosen ports: ", ports_as_strings
        testportfiller.replace_ports(ports_as_strings, ports_as_strings)

        # Replace the string <nodemanager_port> with a random port
        random_nodemanager_port = random.randint(53000, 54000)
        print "Chosen random nodemanager port: " + str(random_nodemanager_port)
        print '-' * 50 + "\n"
        replace_string("<nodemanager_port>", str(random_nodemanager_port),
                       "*nm*")
        replace_string("<nodemanager_port>", str(random_nodemanager_port),
                       "*securitylayers*")

    else:
        # Otherwise use the default ports...
        testportfiller.replace_ports(
            ['12345', '12346', '12347', '12348', '12349'],
            ['12345', '12346', '12347', '12348', '12349'])

        # Use default port 1224 for the nodemanager port if --random flag is not provided.
        replace_string("<nodemanager_port>", '1224', "*nm*")
        replace_string("<nodemanager_port>", '1224', "*securitylayers*")

    os.chdir("repyV1")
    process_mix("repypp.py", verbose)

    # Change back to root project directory
    os.chdir(current_dir)
예제 #6
0
def main():
    helpstring = """This script is not meant to be run individually.
See https://seattle.poly.edu/wiki/BuildInstructions for details."""

    # Parse the options provided.
    parser = optparse.OptionParser(usage=helpstring)

    parser.add_option("-t",
                      "--testfiles",
                      action="store_true",
                      dest="include_tests",
                      default=False,
                      help="Include files required to run the unit tests ")
    parser.add_option(
        "-v",
        "--verbose",
        action="store_true",
        dest="verbose",
        default=False,
        help="Show more output on failure to process a .mix file")
    parser.add_option(
        "-r",
        "--randomports",
        action="store_true",
        dest="randomports",
        default=False,
        help=
        "Replace the default ports with random ports between 52000 and 53000. "
    )

    (options, args) = parser.parse_args()

    # Determine the target directory.
    # Use path/to/component/DEPENDENCIES/common/../../RUNNABLE
    # unless overridden by the user.
    if len(args) == 0:
        component_dir = os.path.dirname(
            os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
        target_dir = os.path.realpath(os.path.join(component_dir, "RUNNABLE"))
        if not os.path.exists(target_dir):
            os.makedirs(target_dir)

    else:
        # The user supplied a target directory. Make it an absolute path,
        # and check if it exists.
        target_dir = os.path.realpath(args[0])

        if not os.path.isdir(target_dir):
            help_exit(
                "Supplied target '" + target_dir +
                "' doesn't exist or is not a directory", parser)

    # Print let the world know we run
    print "Building into", target_dir

    # Set variables according to the provided options.
    repytest = options.include_tests
    RANDOMPORTS = options.randomports
    verbose = options.verbose

    # This script's parent directory is the root dir of all dependent
    # repositories, path/to/component/DEPENDENCIES/
    repos_root_dir = os.path.dirname(os.path.dirname(
        os.path.abspath(__file__)))

    # Set working directory to the target
    os.chdir(target_dir)
    files_to_remove = glob.glob("*")

    # Empty the destination
    for entry in files_to_remove:
        if os.path.isdir(entry):
            shutil.rmtree(entry)
        else:
            os.remove(entry)

    # Return to the grand-parent directory of the dependent repositories,
    # i.e. "/path/to/component/DEPENDENCIES/.."
    # We now have
    #   "." with the sources of the component we want to build,
    #   "scripts/" with the build config file, and
    #   "DEPENDENCIES/" with all the dependent repos.
    os.chdir(os.path.join(repos_root_dir, ".."))
    # Copy the necessary files to the respective target folders,
    # following the instructions in scripts/config_build.txt.
    config_file = open("scripts/config_build.txt")

    for line in config_file.readlines():
        # Ignore comments and blank lines
        if line.startswith("#") or line.strip() == '':
            continue

        # Anything non-comment and non-empty specifies a
        # source file or directory for us to use.
        if line.startswith("test"):
            # Build instructions for unit tests look like this:
            # "test ../relative/path/to/required/file_or_fileglob"
            if repytest:
                source_spec = line.split()[1].strip()
                try:
                    sub_target_dir = line.split()[2].strip()
                except IndexError:
                    sub_target_dir = ''
            else:
                # Tests weren't requested. Skip.
                continue
        else:
            # This is a non-test instruction.
            source_spec = line.split()[0].strip()
            try:
                sub_target_dir = line.split()[1].strip()
            except IndexError:
                sub_target_dir = ''

        os.chdir(target_dir)
        if not os.path.exists(sub_target_dir) and sub_target_dir:
            os.makedirs(sub_target_dir)

        os.chdir(os.path.join(repos_root_dir, ".."))
        copy_to_target(source_spec, target_dir + os.path.sep + sub_target_dir)

    # Set working directory to the target
    os.chdir(target_dir)

    # Set up dynamic port information
    if RANDOMPORTS:
        print "\n[ Randomports option was chosen ]\n" + '-' * 50
        ports_as_ints = random.sample(range(52000, 53000), 5)
        ports_as_strings = []
        for port in ports_as_ints:
            ports_as_strings.append(str(port))

        print "Randomly chosen ports: ", ports_as_strings
        testportfiller.replace_ports(ports_as_strings, ports_as_strings)

        # Replace the string <nodemanager_port> with a random port
        random_nodemanager_port = random.randint(53000, 54000)
        print "Chosen random nodemanager port: " + str(random_nodemanager_port)
        print '-' * 50 + "\n"
        replace_string("<nodemanager_port>", str(random_nodemanager_port),
                       "*nm*")
        replace_string("<nodemanager_port>", str(random_nodemanager_port),
                       "*securitylayers*")

    else:
        # Otherwise use the default ports...
        testportfiller.replace_ports(
            ['12345', '12346', '12347', '12348', '12349'],
            ['12345', '12346', '12347', '12348', '12349'])

        # Use default port 1224 for the nodemanager port if --random flag is not provided.
        replace_string("<nodemanager_port>", '1224', "*nm*")
        replace_string("<nodemanager_port>", '1224', "*securitylayers*")

    # If we have a repyV1 dir, we need to preprocess files that use the
    # `include` functionality there.
    try:
        os.chdir("repyV1")
        process_mix("repypp.py", verbose)
        # Change back to root project directory
        os.chdir(repos_root_dir)
    except OSError:
        # There was no repyV1 dir. Continue.
        pass

    print "Done building!"
예제 #7
0
def main():
  helpstring = """This script is not meant to be run individually.
See https://seattle.poly.edu/wiki/BuildInstructions for details."""

  # Parse the options provided. 
  parser = optparse.OptionParser(usage=helpstring)

  parser.add_option("-t", "--testfiles", action="store_true",
      dest="include_tests", default=False,
      help="Include files required to run the unit tests ")
  parser.add_option("-v", "--verbose", action="store_true",
      dest="verbose", default=False,
      help="Show more output on failure to process a .mix file")
  parser.add_option("-r", "--randomports", action="store_true", 
      dest="randomports", default=False,
      help="Replace the default ports with random ports between 52000 and 53000. ")

  (options, args) = parser.parse_args()

  # Determine the target directory.
  # Use path/to/component/DEPENDENCIES/common/../../RUNNABLE 
  # unless overridden by the user.
  if len(args) == 0:
    component_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    target_dir = os.path.realpath(os.path.join(component_dir, "RUNNABLE"))
    if not os.path.exists(target_dir):
      os.makedirs(target_dir)

  else:
    # The user supplied a target directory. Make it an absolute path, 
    # and check if it exists.
    target_dir = os.path.realpath(args[0])
    
    if not os.path.isdir(target_dir):
      help_exit("Supplied target '" + target_dir + 
          "' doesn't exist or is not a directory", parser)

  # Print let the world know we run
  print "Building into", target_dir

  # Set variables according to the provided options.
  repytest = options.include_tests
  RANDOMPORTS = options.randomports
  verbose = options.verbose


  # This script's parent directory is the root dir of all dependent 
  # repositories, path/to/component/DEPENDENCIES/ 
  repos_root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

  # Set working directory to the target
  os.chdir(target_dir)
  files_to_remove = glob.glob("*")

  # Empty the destination
  for entry in files_to_remove: 
    if os.path.isdir(entry):
      shutil.rmtree(entry)
    else:
      os.remove(entry)


  # Return to the grand-parent directory of the dependent repositories, 
  # i.e. "/path/to/component/DEPENDENCIES/.."
  # We now have
  #   "." with the sources of the component we want to build,
  #   "scripts/" with the build config file, and
  #   "DEPENDENCIES/" with all the dependent repos.
  os.chdir(os.path.join(repos_root_dir, ".."))
  # Copy the necessary files to the respective target folders, 
  # following the instructions in scripts/config_build.txt.
  config_file = open("scripts/config_build.txt")
  
  for line in config_file.readlines():
    # Ignore comments and blank lines
    if line.startswith("#") or line.strip() == '':
      continue

    # Anything non-comment and non-empty specifies a 
    # source file or directory for us to use.
    if line.startswith("test"):
      # Build instructions for unit tests look like this:
      # "test ../relative/path/to/required/file_or_fileglob"
      if repytest:
        source_spec = line.split()[1].strip()
        try:
          sub_target_dir = line.split()[2].strip()
        except IndexError:
          sub_target_dir = ''
      else:
        # Tests weren't requested. Skip.
        continue
    else:
      # This is a non-test instruction.
      source_spec = line.split()[0].strip()
      try:
         sub_target_dir =  line.split()[1].strip()
      except IndexError:
         sub_target_dir = ''
    
    os.chdir(target_dir)
    if not os.path.exists(sub_target_dir) and sub_target_dir:
      os.makedirs(sub_target_dir)
    
    os.chdir(os.path.join(repos_root_dir, ".."))
    copy_to_target(source_spec, target_dir + os.path.sep + sub_target_dir)
 
  
  # Set working directory to the target
  os.chdir(target_dir)

  # Set up dynamic port information
  if RANDOMPORTS:
    print "\n[ Randomports option was chosen ]\n"+'-'*50
    ports_as_ints = random.sample(range(52000, 53000), 5)
    ports_as_strings = []
    for port in ports_as_ints:
      ports_as_strings.append(str(port))
    
    print "Randomly chosen ports: ", ports_as_strings
    testportfiller.replace_ports(ports_as_strings, ports_as_strings)

    # Replace the string <nodemanager_port> with a random port
    random_nodemanager_port = random.randint(53000, 54000)
    print "Chosen random nodemanager port: " + str(random_nodemanager_port)
    print '-'*50 + "\n"
    replace_string("<nodemanager_port>", str(random_nodemanager_port), "*nm*")
    replace_string("<nodemanager_port>", str(random_nodemanager_port), "*securitylayers*")

  else:
    # Otherwise use the default ports...
    testportfiller.replace_ports(['12345','12346','12347', '12348', '12349'], ['12345','12346','12347', '12348', '12349'])

    # Use default port 1224 for the nodemanager port if --random flag is not provided.
    replace_string("<nodemanager_port>", '1224', "*nm*")
    replace_string("<nodemanager_port>", '1224', "*securitylayers*")

  # If we have a repyV1 dir, we need to preprocess files that use the 
  # `include` functionality there.
  try:
    os.chdir("repyV1")
    process_mix("repypp.py", verbose)
    # Change back to root project directory
    os.chdir(repos_root_dir)
  except OSError:
    # There was no repyV1 dir. Continue.
    pass

  print "Done building!"
예제 #8
0
def main():
    # Parse the options provided.
    helpstring = "python preparetest.py [-t] [-v] [-c] [-r] <target>"
    parser = optparse.OptionParser(usage=helpstring)

    parser.add_option("-t",
                      "--testfiles",
                      action="store_true",
                      dest="include_tests",
                      default=False,
                      help="Include files required to run the unit tests ")
    parser.add_option(
        "-v",
        "--verbose",
        action="store_true",
        dest="verbose",
        default=False,
        help="Show more output on failure to process a .mix file")
    parser.add_option("-c",
                      "--checkapi",
                      action="store_true",
                      dest="copy_checkapi",
                      default=False,
                      help="Include checkAPI files")
    parser.add_option(
        "-r",
        "--randomports",
        action="store_true",
        dest="randomports",
        default=False,
        help=
        "Replace the default ports with random ports between 52000 and 53000. "
    )

    (options, args) = parser.parse_args()

    # Extract the target directory.
    if len(args) == 0:
        help_exit("Please pass the target directory as a parameter.", parser)
    else:
        target_dir = args[0]

    # Make sure they gave us a valid directory
    if not os.path.isdir(target_dir):
        help_exit("Supplied target is not a directory", parser)

    # Set variables according to the provided options.
    repytest = options.include_tests
    RANDOMPORTS = options.randomports
    verbose = options.verbose
    copy_checkapi = options.copy_checkapi

    # This script's parent directory is the root dir of all repositories
    repos_root_dir = os.path.dirname(os.getcwd())

    # Set working directory to the target
    os.chdir(target_dir)
    files_to_remove = glob.glob("*")

    # Empty the destination
    for entry in files_to_remove:
        if os.path.isdir(entry):
            shutil.rmtree(entry)
        else:
            os.remove(entry)

    # Create directories for each Repy version under the target
    repy_dir = {
        "v1": os.path.join(target_dir, "repyV1"),
        "v2": os.path.join(target_dir, "repyV2")
    }

    for dir_name in repy_dir.values():
        if not os.path.exists(dir_name):
            os.makedirs(dir_name)

    # Return to the repo root
    os.chdir(repos_root_dir)

    # Copy the necessary files to the respective target folders:

    lines = [line.rstrip('\n') for line in open('config_build.txt')]
    alist = list(line for line in lines if line)
    length = len(alist)
    count = 0
    while (count < length):
        repo = alist[count]
        alist0 = repo.split(' ', 1)[0]
        if alist0 != "test" and alist0 != "#":
            copy_to_target(alist[count], target_dir)
            count = count + 1
        elif alist0 != "#" and alist0 == "test" and repytest:
            repo = alist[count]
            alist1 = repo.split(' ', 1)[1]
            copy_to_target(alist1, target_dir)
            count = count + 1
        else:
            count = count + 1
            continue

    # Set working directory to the target
    os.chdir(target_dir)

    # Set up dynamic port information
    if RANDOMPORTS:
        print "\n[ Randomports option was chosen ]\n" + '-' * 50
        ports_as_ints = random.sample(range(52000, 53000), 5)
        ports_as_strings = []
        for port in ports_as_ints:
            ports_as_strings.append(str(port))

        print "Randomly chosen ports: ", ports_as_strings
        testportfiller.replace_ports(ports_as_strings, ports_as_strings)

        # Replace the string <nodemanager_port> with a random port
        random_nodemanager_port = random.randint(53000, 54000)
        print "Chosen random nodemanager port: " + str(random_nodemanager_port)
        print '-' * 50 + "\n"
        replace_string("<nodemanager_port>", str(random_nodemanager_port),
                       "*nm*")
        replace_string("<nodemanager_port>", str(random_nodemanager_port),
                       "*securitylayers*")

    else:
        # Otherwise use the default ports...
        testportfiller.replace_ports(
            ['12345', '12346', '12347', '12348', '12349'],
            ['12345', '12346', '12347', '12348', '12349'])

        # Use default port 1224 for the nodemanager port if --random flag is not provided.
        replace_string("<nodemanager_port>", '1224', "*nm*")
        replace_string("<nodemanager_port>", '1224', "*securitylayers*")

    os.chdir("repyV1")
    process_mix("repypp.py", verbose)

    # Change back to root project directory
    os.chdir(repos_root_dir)
예제 #9
0
	copy_to_target(source_spec, target_dir)
  
  
  # Set working directory to the target
  os.chdir(target_dir)

  # Set up dynamic port information
  if RANDOMPORTS:
    print "\n[ Randomports option was chosen ]\n"+'-'*50
    ports_as_ints = random.sample(range(52000, 53000), 5)
    ports_as_strings = []
    for port in ports_as_ints:
      ports_as_strings.append(str(port))
    
    print "Randomly chosen ports: ", ports_as_strings
    testportfiller.replace_ports(ports_as_strings, ports_as_strings)

    # Replace the string <nodemanager_port> with a random port
    random_nodemanager_port = random.randint(53000, 54000)
    print "Chosen random nodemanager port: " + str(random_nodemanager_port)
    print '-'*50 + "\n"
    replace_string("<nodemanager_port>", str(random_nodemanager_port), "*nm*")
    replace_string("<nodemanager_port>", str(random_nodemanager_port), "*securitylayers*")

  else:
    # Otherwise use the default ports...
    testportfiller.replace_ports(['12345','12346','12347', '12348', '12349'], ['12345','12346','12347', '12348', '12349'])

    # Use default port 1224 for the nodemanager port if --random flag is not provided.
    replace_string("<nodemanager_port>", '1224', "*nm*")
    replace_string("<nodemanager_port>", '1224', "*securitylayers*")
예제 #10
0
def main():
    repytest = False
    RANDOMPORTS = False
    verbose = False

    target_dir = None

    # Parse the options provided.
    parser = optparse.OptionParser()

    parser.add_option("-t",
                      "--include-test-files",
                      action="store_true",
                      dest="include_tests",
                      help="Include the test " +
                      "files in the output directory.")
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      help="Show more output on failure")
    parser.add_option("-r",
                      "--randomports",
                      action="store_true",
                      dest="randomports",
                      help="Fill in the ports randomly")

    (options, args) = parser.parse_args()

    # Set certain variables according to the options provided.
    if options.include_tests:
        repytest = True
    if options.randomports:
        RANDOMPORTS = True
    if options.verbose:
        verbose = True

    # Extract the target directory if available.
    if len(args) == 0:
        help_exit("Please pass the target directory as a parameter.", parser)
    else:
        target_dir = args[0]

    #store root directory
    current_dir = os.getcwd()

    # Make sure they gave us a valid directory
    if not (os.path.isdir(target_dir)):
        help_exit("given foldername is not a directory", parser)

    #set working directory to the test folder
    os.chdir(target_dir)
    files_to_remove = glob.glob("*")

    #clean the test folder
    for f in files_to_remove:
        if os.path.isdir(f):
            shutil.rmtree(f)
        else:
            os.remove(f)

    #go back to root project directory
    os.chdir(current_dir)

    #now we copy the necessary files to the test folder
    copy_to_target("repy/*", target_dir)
    copy_to_target("nodemanager/*", target_dir)
    copy_to_target("portability/*", target_dir)
    copy_to_target("seattlelib/*", target_dir)
    copy_to_target("seash/*", target_dir)
    copy_tree_to_target("seash/pyreadline/",
                        os.path.join(target_dir, 'pyreadline/'),
                        ignore=".svn")
    copy_tree_to_target("seash/modules/",
                        os.path.join(target_dir, 'modules/'),
                        ignore=".svn")
    copy_to_target("seattlegeni/xmlrpc_clients/*", target_dir)
    copy_to_target("softwareupdater/*", target_dir)
    copy_to_target("autograder/nm_remote_api.mix", target_dir)
    copy_to_target("keydaemon/*", target_dir)
    # The license must be included in anything we distribute.
    copy_to_target("LICENSE.TXT", target_dir)

    if USE_SHIMS:
        # Copy over the files needed for using shim.
        copy_to_target("production_nat_new/src/*", target_dir)
        copy_to_target("production_nat_new/src/nmpatch/nmmain.py", target_dir)
        copy_to_target("production_nat_new/src/nmpatch/nminit.mix", target_dir)
        copy_to_target("production_nat_new/src/nmpatch/nmclient.repy",
                       target_dir)
        copy_to_target("production_nat_new/src/nmpatch/nmclient_shims.mix",
                       target_dir)
        copy_to_target("production_nat_new/src/nmpatch/sockettimeout.repy",
                       target_dir)

    # Only copy the tests if they were requested.
    if repytest:
        # The test framework itself.
        copy_to_target("utf/*.py", target_dir)
        # The various tests.
        copy_to_target("repy/tests/*", target_dir)
        copy_to_target("nodemanager/tests/*", target_dir)
        copy_to_target("portability/tests/*", target_dir)
        copy_to_target("seash/tests/*", target_dir)
        copy_tree_to_target("seash/tests/modules/",
                            os.path.join(target_dir, 'modules/'),
                            ignore=".svn")
        copy_to_target("oddball/tests/*", target_dir)
        copy_to_target("seattlelib/tests/*", target_dir)
        copy_to_target("keydaemon/tests/*", target_dir)
        copy_to_target("utf/tests/*", target_dir)
        # jsamuel: This file, dist/update_crontab_entry.py, is directly included by
        # make_base_installers and appears to be a candidate for removal someday.
        # I assume zackrb needed this for installer testing.
        copy_to_target("dist/update_crontab_entry.py", target_dir)

        if USE_SHIMS:
            # Unit tests for shims
            copy_to_target("production_nat_new/src/unit_tests/*", target_dir)

    #set working directory to the test folder
    os.chdir(target_dir)

    # set up dynamic port information
    if RANDOMPORTS:
        print "\n[ Randomports option was chosen ]\n" + '-' * 50
        portstouseasints = random.sample(range(52000, 53000), 3)
        portstouseasstr = []
        for portint in portstouseasints:
            portstouseasstr.append(str(portint))

        print "Randomly chosen ports: ", portstouseasstr
        testportfiller.replace_ports(portstouseasstr, portstouseasstr)

        # Replace the string <nodemanager_port> with a random port
        random_nodemanager_port = random.randint(53000, 54000)
        print "Chosen random nodemanager port: " + str(random_nodemanager_port)
        print '-' * 50 + "\n"
        replace_string("<nodemanager_port>", str(random_nodemanager_port),
                       "*nm*")
        replace_string("<nodemanager_port>", str(random_nodemanager_port),
                       "*securitylayers*")

    else:
        # if this isn't specified, just use the default ports...
        testportfiller.replace_ports(['12345', '12346', '12347'],
                                     ['12345', '12346', '12347'])

        # Use default port 1224 for the nodemanager port if --random flag is not provided.
        replace_string("<nodemanager_port>", '1224', "*nm*")
        replace_string("<nodemanager_port>", '1224', "*securitylayers*")

    #call the process_mix function to process all mix files in the target directory
    process_mix("repypp.py", verbose)

    #go back to root project directory
    os.chdir(current_dir)
예제 #11
0
def main():
  # Parse the options provided. 
  helpstring = "python preparetest.py [-t] [-v] [-c] [-r] <target>"
  parser = optparse.OptionParser(usage=helpstring)

  parser.add_option("-t", "--testfiles", action="store_true",
      dest="include_tests", default=False,
      help="Include files required to run the unit tests ")
  parser.add_option("-v", "--verbose", action="store_true",
      dest="verbose", default=False,
      help="Show more output on failure to process a .mix file")
  parser.add_option("-c", "--checkapi", action="store_true", 
      dest="copy_checkapi", default=False,
      help="Include checkAPI files")
  parser.add_option("-r", "--randomports", action="store_true", 
      dest="randomports", default=False,
      help="Replace the default ports with random ports between 52000 and 53000. ")

  (options, args) = parser.parse_args()

  # Extract the target directory.
  if len(args) == 0:
    help_exit("Please pass the target directory as a parameter.", parser)
  else:
    target_dir = args[0]

  # Make sure they gave us a valid directory
  if not os.path.isdir(target_dir):
    help_exit("Supplied target is not a directory", parser)

  # Set variables according to the provided options.
  repytest = options.include_tests
  RANDOMPORTS = options.randomports
  verbose = options.verbose
  copy_checkapi = options.copy_checkapi


  # This script's parent directory is the root dir of all repositories
  repos_root_dir = os.path.dirname(os.getcwd())

  # Set working directory to the target
  os.chdir(target_dir)	
  files_to_remove = glob.glob("*")

  # Empty the destination
  for entry in files_to_remove: 
    if os.path.isdir(entry):
      shutil.rmtree(entry)
    else:
      os.remove(entry)

  # Create directories for each Repy version under the target
  repy_dir = {"v1" : os.path.join(target_dir, "repyV1"),
      "v2" : os.path.join(target_dir, "repyV2") }

  for dir_name in repy_dir.values():
    if not os.path.exists(dir_name):
      os.makedirs(dir_name)


  # Return to the repo root
  os.chdir(repos_root_dir)

  
  # Copy the necessary files to the respective target folders:
  file = open('file2.txt', 'r')

  alist = [line.rstrip('\n') for line in open('file2.txt')]
  length = len(alist)
  count =0
  while(count < length):
    copy_to_target(alist[count], target_dir)
    count=count + 1
  
   
  
  
  
  
  if repytest:
    # Only copy the tests if they were requested.
    copy_to_target("repy_v2/tests/restrictions.*", target_dir)
    copy_to_target("utf/*.py", target_dir)
    copy_to_target("utf/tests/*.py", target_dir)
    copy_to_target("repy_v2/testsV2/*", target_dir) # XXX Scheduled for merge with repy_v2/tests
    copy_to_target("nodemanager/tests/*", target_dir)
    copy_to_target("portability/tests/*", target_dir)
    copy_to_target("seash/tests/*", target_dir)
    copy_tree_to_target("seash/tests/modules/", os.path.join(target_dir, 'modules/'), ignore=".git")
    copy_to_target("seattlelib_v2/tests/*", target_dir)

    # The web server is used in the software updater tests
    #copy_to_target("assignments/webserver/*", target_dir)
    #copy_to_target("softwareupdater/test/*", target_dir)

  # Set working directory to the target
  os.chdir(target_dir)

  # Set up dynamic port information
  if RANDOMPORTS:
    print "\n[ Randomports option was chosen ]\n"+'-'*50
    ports_as_ints = random.sample(range(52000, 53000), 5)
    ports_as_strings = []
    for port in ports_as_ints:
      ports_as_strings.append(str(port))
    
    print "Randomly chosen ports: ", ports_as_strings
    testportfiller.replace_ports(ports_as_strings, ports_as_strings)

    # Replace the string <nodemanager_port> with a random port
    random_nodemanager_port = random.randint(53000, 54000)
    print "Chosen random nodemanager port: " + str(random_nodemanager_port)
    print '-'*50 + "\n"
    replace_string("<nodemanager_port>", str(random_nodemanager_port), "*nm*")
    replace_string("<nodemanager_port>", str(random_nodemanager_port), "*securitylayers*")

  else:
    # Otherwise use the default ports...
    testportfiller.replace_ports(['12345','12346','12347', '12348', '12349'], ['12345','12346','12347', '12348', '12349'])

    # Use default port 1224 for the nodemanager port if --random flag is not provided.
    replace_string("<nodemanager_port>", '1224', "*nm*")
    replace_string("<nodemanager_port>", '1224', "*securitylayers*")


  os.chdir("repyV1")
  process_mix("repypp.py", verbose)


  # Change back to root project directory
  os.chdir(repos_root_dir) 
예제 #12
0
def main():

    # Parse the options provided.
    helpstring = "python preparetest.py [-t] [-v] [-c] [-r] <target>"
    parser = optparse.OptionParser(usage=helpstring)

    parser.add_option(
        "-t",
        "--testfiles",
        action="store_true",
        dest="include_tests",
        default=False,
        help="Include files required to run the unit tests ",
    )
    parser.add_option(
        "-v",
        "--verbose",
        action="store_true",
        dest="verbose",
        default=False,
        help="Show more output on failure to process a .mix file",
    )
    parser.add_option(
        "-c", "--checkapi", action="store_true", dest="copy_checkapi", default=False, help="Include checkAPI files"
    )
    parser.add_option(
        "-r",
        "--randomports",
        action="store_true",
        dest="randomports",
        default=False,
        help="Replace the default ports with random ports between \
                           52000 and 53000. ",
    )

    (options, args) = parser.parse_args()

    # Extract the target directory.
    if len(args) == 0:
        help_exit("Please pass the target directory as a parameter.", parser)
    else:
        target_dir = args[0]

    # Make sure they gave us a valid directory
    if not (os.path.isdir(target_dir)):
        help_exit("Supplied target is not a directory", parser)

    # Set variables according to the provided options.
    repytest = options.include_tests
    RANDOMPORTS = options.randomports
    verbose = options.verbose
    copy_checkapi = options.copy_checkapi

    # Store current directory
    current_dir = os.getcwd()

    # Set working directory to the target
    os.chdir(target_dir)
    files_to_remove = glob.glob("*")

    # Empty the destination
    for entry in files_to_remove:
        if os.path.isdir(entry):
            shutil.rmtree(entry)
        else:
            os.remove(entry)

    # Return to previous working directory
    os.chdir(current_dir)

    # Create the two required directories
    repy_dir_dict = {"repyv1": os.path.join(target_dir, "repyV1"), "repyv2": os.path.join(target_dir, "repyV2")}

    for repy_dir in repy_dir_dict.values():
        if not os.path.exists(repy_dir):
            os.makedirs(repy_dir)

    # Copy the necessary files to the test folder
    copy_to_target("repy/*", target_dir)
    copy_to_target("repy/*", os.path.join(target_dir, "repyV2"))
    copy_to_target("repy/repyV1/*", os.path.join(target_dir, "repyV1"))
    copy_to_target("nodemanager/*", target_dir)
    copy_to_target("portability/*", target_dir)
    copy_to_target("portability/*", os.path.join(target_dir, "repyV2"))
    copy_to_target("seattlelib/*", target_dir)
    copy_to_target("seattlelib/dylink.repy", os.path.join(target_dir, "repyV2"))
    copy_to_target("seattlelib/textops.py", os.path.join(target_dir, "repyV2"))
    copy_to_target("nodemanager/servicelogger.py", os.path.join(target_dir, "repyV2"))
    copy_to_target("seash/*", target_dir)
    copy_tree_to_target("seash/pyreadline/", os.path.join(target_dir, "pyreadline/"), ignore=".svn")
    copy_tree_to_target("seash/modules/", os.path.join(target_dir, "modules/"), ignore=".svn")
    copy_to_target("seattlegeni/xmlrpc_clients/*", target_dir)
    copy_to_target("affix/*", target_dir)
    # copy_to_target("shims/proxy/*", target_dir)
    copy_to_target("softwareupdater/*", target_dir)
    copy_to_target("autograder/nm_remote_api.mix", target_dir)
    copy_to_target("keydaemon/*", target_dir)
    copy_to_target("dist/update_crontab_entry.py", target_dir)
    # The license must be included in anything we distribute.
    copy_to_target("LICENSE.TXT", target_dir)

    # CheckAPI source
    if copy_checkapi:
        copy_to_target("checkapi/*", target_dir)

    if repytest:
        # Only copy the tests if they were requested.
        copy_to_target("repy/tests/restrictions.*", target_dir)
        copy_to_target("utf/*.py", target_dir)
        copy_to_target("utf/tests/*.py", target_dir)
        copy_to_target("repy/testsV2/*", target_dir)
        copy_to_target("nodemanager/tests/*", target_dir)
        copy_to_target("portability/tests/*", target_dir)
        copy_to_target("seash/tests/*", target_dir)
        copy_tree_to_target("seash/tests/modules/", os.path.join(target_dir, "modules/"), ignore=".svn")
        copy_to_target("seattlelib/tests/*", target_dir)
        # copy_to_target("keydaemon/tests/*", target_dir)
        copy_to_target("shims/tests/*", target_dir)

        # The web server is used in the software updater tests
        # copy_to_target("assignments/webserver/*", target_dir)
        # copy_to_target("softwareupdater/test/*", target_dir)

    # Set working directory to the target
    os.chdir(target_dir)

    # Set up dynamic port information
    if RANDOMPORTS:
        print "\n[ Randomports option was chosen ]\n" + "-" * 50
        ports_as_ints = random.sample(range(52000, 53000), 5)
        ports_as_strings = []
        for port in ports_as_ints:
            ports_as_strings.append(str(port))

        print "Randomly chosen ports: ", ports_as_strings
        testportfiller.replace_ports(ports_as_strings, ports_as_strings)

        # Replace the string <nodemanager_port> with a random port
        random_nodemanager_port = random.randint(53000, 54000)
        print "Chosen random nodemanager port: " + str(random_nodemanager_port)
        print "-" * 50 + "\n"
        replace_string("<nodemanager_port>", str(random_nodemanager_port), "*nm*")
        replace_string("<nodemanager_port>", str(random_nodemanager_port), "*securitylayers*")

    else:
        # Otherwise use the default ports...
        testportfiller.replace_ports(
            ["12345", "12346", "12347", "12348", "12349"], ["12345", "12346", "12347", "12348", "12349"]
        )

        # Use default port 1224 for the nodemanager port if --random flag is not provided.
        replace_string("<nodemanager_port>", "1224", "*nm*")
        replace_string("<nodemanager_port>", "1224", "*securitylayers*")

    os.chdir("repyV1")
    process_mix("repypp.py", verbose)

    # Change back to root project directory
    os.chdir(current_dir)