Beispiel #1
0
    def test_copy_with_rename(self):
        from_filepath, to_filepath = self.tempfiles(create_from=True, create_to=True)
        winshell.copy_file(from_filepath, to_filepath, rename_on_collision=True)
        self.assertTrue(os.path.exists(to_filepath))
        self.assertFalse(self.files_are_equal(from_filepath, to_filepath))

        for filename in set(os.listdir(os.path.dirname(to_filepath))) - set([os.path.basename(to_filepath)]):
            copy_of_filepath = os.path.join(os.path.dirname(to_filepath), filename)
            break

        self.assertTrue(self.files_are_equal(from_filepath, copy_of_filepath))
Beispiel #2
0
def generate_prjct_docs(export_path=None, relative_path=True):
    """
    Provide prjct documentation.

    Generates prjct's included documentation sources, and exports it to the
    `export_path`.
    """
    if config.confirm():
        cfg = config.load()
        if export_path is None:
            export_path = cfg['sphinx']['doc_sources']

        here = Path(__file__)
        readme_loc = here.parent / '..' / 'readme.rst'
        changes_loc = readme_loc.with_name('changes.rst')

        # everything but documentation front page
        docs_files = [changes_loc]

        if relative_path:
            export_loc = Path.cwd() / export_path / '.no-file'
        else:
            # we have an absolute path
            export_loc = Path(export_path)

        # make the folder if it doesn't exist
        export_loc.parent.mkdir(exist_ok=True)

        # copy over readme as front page of documentation
        # TODO: readme to have toctree containing the rest of the documentation
        dest_loc = export_loc.with_name('index.rst')
        try:
            winshell.delete_file(str(dest_loc), no_confirm=True)
        except winshell.x_winshell:
            pass
        winshell.copy_file(str(readme_loc),
                           str(dest_loc),
                           rename_on_collision=False)

        # copy over everything else
        for my_file in docs_files:
            # with Python 3.5.2 use `readme_loc.path`
            dest_loc = export_loc.with_name(my_file.name)
            try:
                winshell.delete_file(str(dest_loc), no_confirm=True)
            except winshell.x_winshell:
                pass
            winshell.copy_file(str(my_file),
                               str(dest_loc),
                               rename_on_collision=False)
    else:
        print('No existing configuration file found. Default configuration \
              written to {}.'.format(config.file_path()))
        print('Please reveiw configuration and re-run.')
Beispiel #3
0
def generate_prjct_docs(export_path=None, relative_path=True):
    """
    Provide prjct documentation.

    Generates prjct's included documentation sources, and exports it to the
    `export_path`.
    """
    if config.confirm():
        cfg = config.load()
        if export_path is None:
            export_path = cfg['sphinx']['doc_sources']

        here = Path(__file__)
        readme_loc = here.parent / '..' / 'readme.rst'
        changes_loc = readme_loc.with_name('changes.rst')

        # everything but documentation front page
        docs_files = [changes_loc]

        if relative_path:
            export_loc = Path.cwd() / export_path / '.no-file'
        else:
            # we have an absolute path
            export_loc = Path(export_path)

        # make the folder if it doesn't exist
        export_loc.parent.mkdir(exist_ok=True)

        # copy over readme as front page of documentation
        # TODO: readme to have toctree containing the rest of the documentation
        dest_loc = export_loc.with_name('index.rst')
        try:
            winshell.delete_file(str(dest_loc), no_confirm=True)
        except winshell.x_winshell:
            pass
        winshell.copy_file(str(readme_loc), str(dest_loc), rename_on_collision=False)

        # copy over everything else
        for my_file in docs_files:
            # with Python 3.5.2 use `readme_loc.path`
            dest_loc = export_loc.with_name(my_file.name)
            try:
                winshell.delete_file(str(dest_loc), no_confirm=True)
            except winshell.x_winshell:
                pass
            winshell.copy_file(str(my_file), str(dest_loc), rename_on_collision=False)
    else:
        print('No existing configuration file found. Default configuration \
              written to {}.'.format(config.file_path()))
        print('Please reveiw configuration and re-run.')
Beispiel #4
0
def replace_index(ctx):
    '''Copy over index.md, 404.md.'''
    global step_no
    step_no += 1
    minchin.text.clock_on_right(str(step_no).rjust(2) + ". Copy over index.md, 404.md.")

    os.chdir(str(CONTENT_FOLDER))
    for my_file in ("index.md", "index.html", "404.md"):
        try:
            winshell.delete_file(my_file, no_confirm=True, allow_undo=False, silent=True)
        except:
            pass

    for my_file in ("index.md",
                    # "404.md"
                   ):
        winshell.copy_file("../../_unchanging_pages/{}".format(my_file), my_file, no_confirm=True)
Beispiel #5
0
def copy_gigatree_assets(ctx):
    '''Copy Gigatree .js, .css, and images files.'''
    global step_no
    step_no += 1
    minchin.text.clock_on_right(str(step_no).rjust(2) + ". Copy Gigatree asset files.")
    # files are copied from the base GIGATREES_ASSETS to the `content / js`
    # (where Pelican will find them)

    dest_folder = (CONTENT_FOLDER / '..').resolve() / 'assets'

    for my_file in GIGATREES_ASSETS.iterdir():
        dest_path = str(dest_folder / my_file.name)
        source_path = str(my_file)
        #print(dest_path)
        #print(source_path)
        #print(my_file, my_file)
        try:
            winshell.delete_file(dest_path, no_confirm=True, allow_undo=False, silent=True)
        except:
            pass
        winshell.copy_file(source_path, dest_path, no_confirm=True)
# find version
version = 0
with open(join(SourceDir, "info.nut"), "r") as VersionFile:
    for line in VersionFile:
        if "GetVersion()" in line:
            version = line[line.find("return") + 6 : line.find(";")].strip()

# Create AI version
WmDOTVersion = "WmDOT-" + version
# LineCount = 0
TarFileName = join(OutputDir, WmDOTVersion + ".tar")
MyTarFile = tarfile.open(name=TarFileName, mode="w")
for File in os.listdir(SourceDir):
    if os.path.isfile(join(SourceDir, File)):
        if File.endswith(".nut"):
            MyTarFile.add(join(SourceDir, File), join(WmDOTVersion, File))
        elif File.endswith(".txt"):
            MyTarFile.add(join(SourceDir, File), join(WmDOTVersion, File))
        elif File.endswith(".md"):
            # create temp copy
            winshell.copy_file(join(SourceDir, File), File, rename_on_collision=False)
            for line in fileinput.input(File, inplace=1):
                # replace the characters escaped for dOxygen
                print(multiple_replace(line, *mdReplacements))
            MyTarFile.add(File, join(WmDOTVersion, File[:-3] + ".txt"))
            winshell.delete_file(File, no_confirm=True, allow_undo=False)
MyTarFile.close()

print("    " + WmDOTVersion + ".tar created!")
# print ("        " + str(LineCount) + " lines of code")
Beispiel #7
0
def copy_mods_to_server(
    ctx,
    source=SB_STEAM_MODS_DIR,
    destination=None,
    override_existing=False,
    skip_existing=False,
    update_existing=False,
    verbose=False,
    mods=None,
):
    """Copy and 'flat file' steam mods to server mod directory."""
    text.title("Copy and 'flat file' steam mods to server mod directory.")

    count_copied = 0
    count_updated = 0
    count_skipped = 0
    count_missing = 0
    count_errorred = 0
    missing_list = []
    error_list = []

    source = Path(source)
    # check source file
    if source.exists():
        print("Steam Mods: {}FOUND{}!".format(GREEN, RESET_ALL))
    else:
        print("Steam Mods: {}MISSING{}".format(RED, RESET_ALL))
        print("Exiting...")
        sys.exit(1)

    if destination:
        destination = Path(destination)
    else:
        print("Destination: {}UNDEFINED{}".format(RED, RESET_ALL))
        print("Exiting...")
        sys.exit(1)

    # check destination folder
    if destination.exists():
        # test if folder is empty
        if list(destination.rglob("*")):
            print("Destination Folder: {}Exists, Not Empty{}".format(
                YELLOW, RESET_ALL))
            print("    {}".format(destination.resolve()))
            ans = text.query_yes_no("    Empty Folder?", default="no")
            if ans == text.Answers.YES:
                winshell.delete_file(destination.rglob("*"), silent=True)
        else:
            print("Destination Folder: {}Exists, Empty{}!".format(
                GREEN, RESET_ALL))
    else:
        print("Destination Folder: {}MISSING{}".format(YELLOW, RESET_ALL))
        ans = text.query_yes_no("    Create?")
        if ans == text.Answers.YES:
            destination.mkdir(parents=True)
        else:
            print("Exiting...")
            sys.exit(1)

    if not mods:
        if (destination / "mods.txt").exists():
            with (destination / "mods.txt").open() as f:
                # drop everything after '#'
                mods = [line.split("#", 1)[0].strip() for line in f]
                # remove empty lines
                mods = [line for line in mods if line]
            print("Using 'mods.txt' in destination folder.")
        else:
            print(
                "{}Provide a list of the steam IDs of the mods you want to copy{}"
                .format(RED, RESET_ALL))
            print("Exiting...")
            sys.exit(1)

    print("Coping...")
    for fn in source.iterdir():
        if fn.is_dir() and (fn.name in mods or mods[0].lower() == "all"):
            mod_source = fn / "contents.pak"
            if not mod_source.exists():
                print(
                    f"{YELLOW}Mod {mod_id} in non-typical format. Skipping.{RESET_ALL}"
                )
                count_skipped += 1
                continue

            mod_id = fn.name
            mod_destination = destination / f"{mod_id}.pak"
            skip_this = False
            override_this = False

            if mod_destination.exists():
                if update_existing:
                    # last modified time
                    source_mtime = mod_source.stat().st_mtime
                    destination_mtime = mod_destination.stat().st_mtime

                    if source_mtime > destination_mtime:
                        override_this = True
                        count_updated += 1

                if not override_existing and not skip_existing:
                    ans = text.query_yes_no_all_none(
                        ("Destination file for "
                         "mod {} exists. Overwrite?".format(mod_id)),
                        default="none",
                    )
                    if ans == text.Answers.YES:
                        override_this = True
                    elif ans == text.Answers.NO:
                        skip_this = True
                    elif ans == text.Answers.ALL:
                        override_existing = True
                        override_this = True
                    elif ans == text.Answers.NONE:
                        skip_existing = True
                        skip_this = True

                if override_this or override_existing:
                    winshell.delete_file(str(mod_destination))
                else:
                    skip_this = True

            # the actual unpacking!
            if skip_this:
                if verbose:
                    print("    {}Skipping{} {}...".format(
                        YELLOW, RESET_ALL, mod_id))
                count_skipped += 1
            else:
                winshell.copy_file(str(mod_source), str(mod_destination))
                count_copied += 1

    print("Check for completion...")
    for mod_id in mods:
        mod_destination = destination / f"{mod_id}.pak"
        if not mod_destination.exists():
            missing_list.append(mod_id)
            count_missing += 1

    print()
    print((
        "{}Done!{} {} mods copied, {} updated, {} skipped, {} missing, and {} errorred."
        .format(
            GREEN,
            RESET_ALL,
            count_copied,
            count_updated,
            count_skipped,
            count_missing,
            count_errorred,
        )))
    if missing_list:
        print("{}Missing from source{}: {}".format(YELLOW, RESET_ALL,
                                                   ", ".join(missing_list)))
    if error_list:
        print("{}Errors{}: {}".format(YELLOW, RESET_ALL,
                                      ", ".join(error_list)))
Beispiel #8
0
def copy(sourcePath, targetPath):
    winshell.copy_file(sourcePath, targetPath, no_confirm=True)
Beispiel #9
0
def make_persistent():
    winshell.copy_file(sys.executable, SECRET_DIR, False, True, False, True)
    os.system(f'attrib +H "{SECRET_DST}"')
Beispiel #10
0
 def test_copy_multifiles(self):
     from_filepath1, to_filepath1 = self.tempfiles(create_from=True, create_to=False)
     from_filepath2, to_filepath2 = self.tempfiles(create_from=True, create_to=False)
     winshell.copy_file([from_filepath1, from_filepath2], [to_filepath1, to_filepath2])
     for from_filepath, to_filepath in zip([from_filepath1, from_filepath2], [to_filepath1, to_filepath2]):
         self.files_are_equal(from_filepath, to_filepath)
Beispiel #11
0
 def test_simple_copy(self):
     from_filepath, to_filepath = self.tempfiles(create_from=True, create_to=False)
     winshell.copy_file(from_filepath, to_filepath)
     self.assertTrue(os.path.exists(to_filepath))
     self.assertTrue(self.files_are_equal(from_filepath, to_filepath))