Commits

3k  committed 5ff710f

added the -c option

  • Participants
  • Parent commits 0a57c5b
  • Tags 1.1.1

Comments (0)

Files changed (5)

 pilpal version history
 ======================
 
+1.1.1
+-----
+
+* Added -c option to console script
+
 1.1.0
 -----
 
 : ._.':_;`.__;: ._.'`.__,_;`.__;
 : :           : :
 :_;           :_;
-                   version 1.1.0
+                   version 1.1.1
 
 Overview
 ========
                         extension
   -y, --yes             automatically create a new file if source file does
                         not exist
+  -c, --create          create the given source file and exit
   -s, --silent          disable update messages
   -k, --key-help        list available keyboard shortcuts and exit
   -v, --version         show program's version number and exit
     help="defaults to the basename of the source file with .png extension")
 parser.add_argument("-y", "--yes", action="store_true", dest="force_create",
     help="automatically create a new file if source file does not exist")
+parser.add_argument("-c", "--create", action="store_true", dest="just_create",
+    help="create the given source file and exit")
 parser.add_argument("-s", "--silent", action="store_true", dest="silent",
     help="disable update messages")
 parser.add_argument("-k", "--key-help", nargs=0, action=KeyboardHelpAction,
     sys.path.append(here)
     image_file = os.path.join(here, image_file)
     if not os.path.exists(input_file):
+        if args.just_create:
+            pp.create_script(input_file, image_file, args.silent)
+            sys.exit()
         if not args.force_create:
             s = raw_input("Do you want to create '{0}'? [y/n]: ".format(input_file))
             if s == "y":
-                pp.create_script(input_file, image_file)
+                pp.create_script(input_file, image_file, args.silent)
             else:
                 sys.exit()
         else:
-            pp.create_script(input_file, image_file)
+            pp.create_script(input_file, image_file, args.silent)
 
     pp.initialize(input_file, image_file, args.silent)
     pp.observer.start()

File pilpal/__init__.py

 #
 
 __author__ = "Károly Kiripolszky"
-__version__ = "1.1.0"
+__version__ = "1.1.1"
 
 __all__ = ["pilpal", "geom"]
 

File pilpal/pilpal.py

 output_file = None
 evt_queue = None
 msg_queue = None
+initialized = False
 
 
 #
 # Public interface
 #
 
-def create_script(path, image_file):
+def create_script(path, image_file, silent=False):
     """Creates a template script at the given path.
     """
     try:
         open(path, "w+").write(SCRIPT_TEMPLATE.format(image_file))
-        print("".join((Observer.LOG_NORMAL, "created module: ", path)))
+        if not silent:
+            print("".join((Observer.LOG_NORMAL, "created module: ", path)))
     except IOError:
-        print("*** Error creating file: {0}. Exiting.".format(path))
+        if not silent:
+            print("*** Error creating file: {0}. Exiting.".format(path))
         raise SystemExit()
 
 
 def initialize(input_file, image_file=None, silent=False):
     """Creates necessary objects, sets up pilpal.
     """
+    if initialized:
+        return False
     global observer, root, msg_queue, evt_queue
     msg_queue = Queue()
     evt_queue = Queue()
     for kbcfg in KEY_MAPPINGS:
         root.bind_all(kbcfg[0], kbcfg[1])
     observer.daemon = True
+    return True
+