uniqx avatar uniqx committed e7886b6

cosmetic refactoring

Comments (0)

Files changed (1)

 #! /usr/bin/env python
 # -*- coding: utf-8 -*-
 #
-#  Copyright (C) 2011 uniqx
-#   Metalab, 1010 Vienna, Austria
+# Copyright (C) 2011 uniqx
+#  Metalab, 1010 Vienna, Austria
 #
-#  This program is free software: you can redistribute it and/or modify
-#  it under the terms of the GNU Affero General Public License as published
-#  by the Free Software Foundation, either version 3 of the License, or
-#  (at your option) any later version.
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
 #
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#  GNU Affero General Public License for more details.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
 #
-#  You should have received a copy of the GNU Affero General Public License
-#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
 import os
        pyld [-i INTERVAL] [-n] [-r RECORD] FILE...
 
 DESCRIPTION
-       pyld is a live coding tool for python. It is designed to run as a daemon
-       so you may use your favourite editor for coding. pyld executes a python
-       script and monitors it constantly. When a change to the script file is
-       detected pyld will attempt to monkey-patch the running script. Also a
-       copy of the script will be added to a version history archive if changes
-       are detected.
+       pyld is a live coding tool for python. It is designed to run as a
+       daemon so you may use your favourite editor for coding. pyld
+       executes a python script and monitors it constantly. When a change
+       to the script file is detected pyld will attempt to monkey-patch
+       the running script. Also a copy of the script will be added to a
+       version history archive if changes are detected.
 
        FILE
-              The file(s) which should be executed and monitored for changes.
-              If a file does not exist, pyld will still look for the file and
-              execute/monitor it when it is created.
+              The file(s) which should be executed and monitored for
+              changes. If a file does not exist, pyld will still look for
+              the file and execute/monitor it when it is created.
 
       -i INTERVAL, --interval INTERVAL
-              The interval for scanning the files in seconds. e.g. 0.1 will
-              result in 10 scans per second. default: 0.33
+              The interval for scanning the files in seconds.
+              e.g. 0.1 will result in 10 scans per second. default: 0.33
 
       -n, --no-record
-              Instructs pyld to do not record your live session to a tar file.
-              If -r is set, the -n option will be ignored.
+              Instructs pyld to do not record your live session to a tar
+              file. If -r is set, the -n option will be ignored.
 
       -r RECORD, --record RECORD
-              Records your live session to a tar file. Defaults to create a
-              archive with a with the name of the current folder and a time-
-              stamp. If -r is set, the -n option will be ignored.
+              Records your live session to a tar file. Defaults to create
+              a archive with a with the name of the current folder and a
+              time stamp. If -r is set, the -n option will be ignored.
 '''
 
 def __print_error_msg(err_msg):
 
 
 
-def check_file(handle):
-  '''checks if a file has changed and calls refresh_file if necessary.
+def __check_file(handle):
+  '''checks if a file has changed and calls __refresh_file if necessary.
 
   :param dict handle: meta data for a monitored python script
   '''
 
     mtime = os.path.getmtime(handle['path'])
     if handle['mtime'] < mtime:
-      refresh_file(handle,mtime)
+      __refresh_file(handle,mtime)
   else:
     print handle['path'], 'does not exits'
     handle['init'] = False
 
-def refresh_file(handle,mtime):
+def __refresh_file(handle,mtime):
   '''refresh script file and execute it.
 
   :param dict handle: meta data for a monitored python script
 
   # unload if already initialized
   if handle['init']:
-    exec_code_object(handle,'unload')
+    __exec_code_object(handle,'unload')
 
   # (re)read the file
-  read_and_compile_script(handle)
+  __read_and_compile_script(handle)
 
   # initialize if not yet initialized
   if not handle['init']:
-    exec_code_object(handle,'init')
+    __exec_code_object(handle,'init')
     handle['init'] = True
 
   # exec reload
-  exec_code_object(handle,'reload')
+  __exec_code_object(handle,'reload')
 
   # update modification time
   handle['mtime'] = mtime
         pass
 
 
-def exec_code_object(handle,target):
+def __exec_code_object(handle,target):
   '''executes a prepared code object that is stored inside the handle already.
   if no code object for the given target exists, calling this function will
   have no effect, but won't fail either.
       pass
 
 
-def read_and_compile_script(handle):
+def __read_and_compile_script(handle):
   '''reads a script file, parses it and creates code objects for
   of the relevant part from a script.
 
   :param dict handle: meta data for a monitored python script
   '''
 
-  src = read_text_file(handle['path'])
+  src = __read_text_file(handle['path'])
 
   for block in ast.parse(src).body:
 
         handle['code_object_unload'] = compile(ast.Module(block.body),os.path.split(handle['path'])[-1],'exec')
 
 
-def read_text_file(path):
+def __read_text_file(path):
   '''reads a text file and returns it as a string'''
 
   ret = ''
   while running:
 
     for handle in observe_handles:
-      check_file(handle)
+      __check_file(handle)
 
     time.sleep(interval)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.