Stamp backer(Python)

  • boxmein
    10th Apr 2011 Former Staff 1 Permalink

    For future people, this does the same thing as reloading stamps in the Stamp Browser menu. There is no need for this script.



    Anyways.. here's the script.


    import os
    from argparse import ArgumentParser

    parser = ArgumentParser(description="Generate stamps.def from stamp files. TPT does that out of the box too.")

    parser.add_argument("-b", "--nobackup",
    action="store_true", help="Don't backup stamps.def before running.")

    parser.add_argument("-w", "--nowait",
    action="store_true", help="Don't wait for input after running.")

    parser.add_argument("-q", "--quiet",
    action="store_true", help="Shut up")

    args = parser.parse_args()
    qp = lambda s: None if args.quiet else print(s)

    # Backup
    if not args.nobackup:
    with open("stamps/stamps.def", 'r') as f:
    with open("stamps/stamps.def~", 'w') as g:
    for line in f:
    g.write(line)

    # True stuff
    dirlist = os.listdir(os.getcwd() + os.sep + "stamps" + os.sep)
    dirlist.remove("stamps.def")

    with open('stamps/stamps.def', 'w') as f:
    for i in range(0, len(dirlist)-1):
    f.write(dirlist[i].rstrip(".stm"))
    qp (repr(dirlist[i]) + " added to stamps.def")
    qp ("Success.")

    if not args.nowait:
    input()
    # 2011 original, 2013 rewritten for Python 3 support and arguments.
    # by boxmein. Use as you wish.
    Edited once by boxmein. Last: 28th Jul 2013
  • cctvdude99
    10th Apr 2011 Member 0 Permalink
    @boxmein (View Post)
    Cool. NVM - You posted a link. How do I use it? I've never used python.
  • boxmein
    10th Apr 2011 Former Staff 0 Permalink
    1. You download python and install. 2. You double-click the file.
  • pegosh2
    10th Apr 2011 Member 0 Permalink
    @boxmein (View Post)
    Awesome awesome awesome. Must try.
  • Simon
    10th Apr 2011 Administrator 0 Permalink
    When we (finally) get the python console working, this would be an awesome addon and you could even give it a GUI.
    Doesn't look like that's going to be any time soon, though :(
  • boxmein
    10th Apr 2011 Former Staff 0 Permalink
    Thank you, Simon. :)


    I just discovered my lack of ability on making wxPython GUIs. Or c++'s gui-s. Anyone?
  • snowfire777
    10th Apr 2011 Banned 0 Permalink
    This post is hidden because the user is banned
  • boxmein
    10th Apr 2011 Former Staff 0 Permalink
    Who added that pre thing to my first post? lol. ok, whatever ^^
    Edit: Okay.
  • Simon
    10th Apr 2011 Administrator 0 Permalink
    @boxmein (View Post)
    That was me, I thought going to mediafire to download a single 16-line file was a little unnecessary.
  • snowfire777
    10th Apr 2011 Banned 0 Permalink
    This post is hidden because the user is banned
Locked by jacob1: necro