Commits

Anonymous committed 3b2edce

remove analize crappy feature

Comments (0)

Files changed (1)

  • +21 -62
    sr
     * search pattern in files
     * search pattern in files and replace it with another pattern
 Oops. One another thing that this program can now:
-    * analize the languages of the project
 """
 
 import os
     What to search (default)
  -r, --replace
     What replace with (only with search option)
- -a, --analize
-    Analize the project tree
 
 Example: sr --python User"""
 
                       help='what to search')
     parser.add_option('-r', '--replace', dest='replace',
                       help='what replace with')
-    parser.add_option('-a', '--analize', dest='analize', action='store_true',
-                      help='analize files')
     parser.add_option('-i', '--ignore-case', action='store_true',
                       default=False, help='ignore case')
     parser.add_option('-v', '--verbose', action='store_true',
         print 'allow exts:', config.allow_exts
         print 'disallow exts:', config.disallow_exts
 
-    if opts.analize:
-        config.targets = ['']
-        config.mode = 'analize'
+    if not opts.search:
+        if opts.replace:
+            parser.error('Replace option could be specified only with search option')
+        if not args:
+            parser.error('No options for search')
+        config.search = args[0]
+        if len(args) == 1:
+            config.targets = ['']
+        else:
+            config.targets = args[1:]
     else:
-        if not opts.search:
-            if opts.replace:
-                parser.error('Replace option could be specified only with search option')
-            if not args:
-                parser.error('No options for search')
-            config.search = args[0]
-            if len(args) == 1:
-                config.targets = ['']
-            else:
-                config.targets = args[1:]
+        config.search = opts.search
+        if args:
+            config.targets = args
         else:
-            config.search = opts.search
-            if args:
-                config.targets = args
-            else:
-                config.targets = ['']
+            config.targets = ['']
 
-        if opts.replace:
-            config.replace = opts.replace
-            config.mode = 'replace'
+    if opts.replace:
+        config.replace = opts.replace
+        config.mode = 'replace'
 
-        flags = 0
-        if opts.ignore_case:
-            flags |= re.I
-        config.search = re.compile(config.search, flags)
+    flags = 0
+    if opts.ignore_case:
+        flags |= re.I
+    config.search = re.compile(config.search, flags)
 
 
 def relpath(path):
             os.unlink(tmp_path)
 
 
-def analize(path):
-    """
-    Detect the type of file and remember it for statistics.
-    """
-
-    base, name = os.path.split(path)
-    XXX, ext = os.path.splitext(name)
-    for ftype, extensions in TYPES().iteritems():
-        if ext in extensions:
-            config.stat.setdefault(ftype, 0)
-            config.stat[ftype] += 1
-    config.stat['all'] += 1
-
 
 def process_file(path):
     """
         return search(path)
     elif config.mode == 'replace':
         return search_replace(path)
-    elif config.mode == 'analize':
-        return analize(path)
 
 
 def walk_files():
             return search.sub(replacer, text)
 
 
-def show_analize():
-    """
-    Analize the gathered information and show the summary.
-    """
-
-    sorted_stat = sorted(config.stat.items(), reverse=True,
-                         cmp=lambda a, b: cmp(a[1], b[1]))
-    all = config.stat['all']
-    for ftype, number in sorted_stat:
-        ratio = (number / float(all)) * 100
-        print '%s: %0.2f%% [%d]' % (ftype, ratio, number)
-
-
-
 if __name__ == '__main__':
     if 'SRDEBUG' in os.environ:
         loglevel = logging.DEBUG
     walked = []
     for path in walk_files():
         process_file(path)
-
-    if config.mode == 'analize':
-        show_analize()
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.