Commits

Anonymous committed 58f7138

add clean and compile_pyc commands

  • Participants
  • Parent commits 3fbd272

Comments (0)

Files changed (6)

 # built documents.
 #
 # The short X.Y version.
-version = '0.5'
+version = '0.5.2'
 # The full version, including alpha/beta/rc tags.
-release = '0.5'
+release = '0.5.2'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
     actions:
       bshell:
         run shell use bpython
+
+      clean:
+        Clean the specify filename extention files from the directory.
+        :param pretend: Instead  of  actually performing the clean,just print it
+
+        -d, --directory               string    .
+        -e, --extention               string    .pyc
+        --no-pretend
+        --no-verbose
+
+      compile_pyc:
+        Compile all python files in the directory into bytecode files.
+                
+
+        -d, --directory               string    .
+        --no-verbose
+
                 
 
       runfcgi:
 
 Add Custom action
 -----------------------
-**Flask-Actions** uses werkzeug management script utilities,you'd rather dive into it's documentation :`Werkzeug Documentation - Management Script Utilities <http://werkzeug.pocoo.org/documentation/dev/script.html#writing-actions/>`_
+**Flask-Actions** uses werkzeug management script utilities,you'd rather dive into it's documentation :`Werkzeug Documentation - Management Script Utilities <http://werkzeug.pocoo.org/documentation/dev/script.html#writing-actions>`_
 
 here is an simple example::
 

flaskext/actions/actions.py

 """
 import sys,os
 from werkzeug import script
+import utils
 
 def runfcgi(application, before_daemon=None):
     def action( hostname            =   ('h', ''),
     return action
 
 def run_twisted_server(app):
-    def action(port=('p', 8000), reactor_type=('r', 1)):
+    def action(port=('p', 8000), reactor_type=('r', 0)):
         """run application use twisted http server
-        @reactor_type: [default 1]
-            1       epoll   reactor
-            2       poll    reactor
-            3       kqueue  reactor
-            4       iocp    reactor
-            other   select  reactor
+        :param reactor_type: [default 0]
+                            0       default reactor
+                            1       epoll   reactor
+                            2       poll    reactor
+                            3       kqueue  reactor
+                            4       iocp    reactor
+                            other   select  reactor
         """
         try:
-            if reactor_type == 1:
+            if reactor_type ==0:
+                pass
+            elif reactor_type == 1:
                 from twisted.internet import epollreactor
                 epollreactor.install()
             elif reactor_type == 2:
         except ImportError:
             print "You need to install twisted"
             sys.exit()
+        from twisted.internet import reactor
+        from twisted.application import internet, service
+        from twisted.web import server, wsgi
 
-        application = service.Application('twisted-wsgi') # call this anything you like
+        #application = service.Application('twisted-wsgi') # call this anything you like
         resource = wsgi.WSGIResource(reactor, reactor.getThreadPool(), app)
         factory = server.Site(resource)
         reactor.listenTCP(int(port),factory)
         embed({"app": app})
     return action
 
+def compile_pyc(app,use_verbose=True):
+    def action(directory=('d','.'),verbose=use_verbose):
+        """Compile all python files in the directory into bytecode files.
+        """
+        import py_compile 
+        for root, dirs, files in os.walk(directory):
+            for file in files:
+                ext = os.path.splitext(file)[1]
+                if ext==".py":
+                    full_path = os.path.abspath(os.path.join(root, file))
+                    if verbose:
+                        print "%sc" % full_path
+                    py_compile.compile(full_path)
+
+    return action
+
+def clean(app,use_pretend=True,use_verbose=True):
+    def action(directory=('d','.'),extention=('e','.pyc'),pretend=use_pretend,verbose=use_verbose):
+        """
+        Clean the specify filename extention files from the directory.
+        :param pretend: Instead  of  actually performing the clean,just print it
+        """
+        check = lambda s: s.endswith(extention)
+        if pretend:
+            print "The following files are supposed to be delete:"
+        else:
+            print "the following files are removed:"
+        for dirpath, dirnames, filenames in os.walk(directory):
+            for filename in filter(check, filenames):
+                fullpath = os.path.abspath(os.path.join(dirpath, filename))
+                if verbose:
+                        print "%s" % fullpath
+                if not pretend:
+                    os.remove(fullpath)
+    return action
+
+def generate_secret_key(app):
+    def action(length=('l',32)):
+        """creates a new secret key"""
+        print utils.generate_secret_key(length)
+    return action
+
+
 class Manager(object):
     def __init__(self, application):
         self.application = application
                                     use_reloader=True, threaded=True, hostname='0.0.0.0',
                                     port=7777, use_debugger=True),
                 'bshell'    :   bshell(application),
+                'compile_pyc' : compile_pyc(application),
+                'clean'       : clean(application),
+                'generate_secret_key':generate_secret_key(application),
                 'runtwisted'  :   run_twisted_server(application),
 
         }

flaskext/actions/flask_admin.py

 import random
 import string
 from werkzeug import script
-
-KEY_LENGTH = 32
-KEY_CHARS = string.letters + string.digits + string.punctuation
+import utils
 
 def preprocess_file(path, **values):
     f = open(path, 'r')
             os.rename(path_join(fn), path_join(fn.replace('_tmpl', '')))
 
     # Update configuration file
-    key = repr(''.join(random.choice(KEY_CHARS) for _ in xrange(KEY_LENGTH)))
+    key = utils.generate_secret_key()
     preprocess_file(path_join('settings.py'), project=proj_name,secretkey=key)
 
     os.chmod(path_join('manage.py'),

flaskext/actions/utils.py

+# -*- encoding:utf-8 -*-
+import string
+import random
+KEY_CHARS = string.letters + string.digits + string.punctuation
+
+def generate_secret_key(length=32):
+    return  ''.join(random.choice(KEY_CHARS) for _ in xrange(length))
+
 
 setup(
     name='Flask-Actions',
-    version='0.5.1',
+    version='0.5.2',
     url='http://blog.flyzen.com',
     license='BSD',
     author='Young King',