<commit_before>#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""
Copyright (c) 2009 <NAME> <http://www.holtwick.it>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

CHANGELOG:

0.1 
- Initial release

0.2 (2009-09-04)
- Dealloc can contain custom data
- Adds missing dealloc correctly

0.3 (2009-09-11)
- viewDidUnload support

0.4 (2009-12-18)
- Joined with version of 'freewizard' with leading underscore support
- Some refactoring to make the source more readable
- Added XPUBLIC to mark public methods
- Alphabetical sorting of blocks
- Added MIT license

0.5 (2010-01-05)
- More refactoring
- Now work also when no properties are defined
- Prefix XPUBLIC also in Interface file to prepare for more intelligent
  handling of those marked methods in future
- Removed unsexy whitesapce 

0.6 (2010-01-06)
- Removed the prepending XPUBLIC from interface file because Interface
  Builder was not able to handle it  
- IBAction methods are always considered public (I don't see a case where
  they are not
- Static methods are also considered public

0.7 (2010-02-07)
- Fix for Apple Script calls
- Handle comment correctly
- New FORCE_METHODS setting 

0.8 (2010-02-15)
- Moved @synthesize to the end of files
- Moved @property to the end of files

0.9 (2010-03-14)
- Methods which start with 'initWith' are considered public
- Added XPROPERTY(..) for individual property definitions, e.g.
  XPROPERTY(readonly) id test;
- Removed XATOMIC and XREADONLY
- Code cleanup

0.10
- Now also works as build script
- Only handle files if different file times
- Only change files that contain X... macros
- Nonatomic can be turned of as default
- Strip trailing spaces
- Multiple file and path arguments
- Added XDELEGATE

0.11
- Fix: Can handle missing spaces around asterisk

TODO:

- Work with more implementations etc. in one file and match name
  => Currently just one implementation per file
- NSCoder support 
  => Create all needed stuff
- XPRIVATE 
  => Put them into a category in the implementation file
- Support for categories

"""

import re
import os
import os.path
import shutil
import pprint
import datetime
import subprocess

### CONFIG BEGIN 

DEBUG = 0

BACKUP_FOLDER = 'BACKUP-XOBJC'
FORCE_METHODS = True
STRIP_TRAILING_SPACES = True
NONATOMIC = ""

# NONATOMIC = "nonatomic, "

try:
    from xobjc_settings import *
except:
    pass

### CONFIG END 

rxInterface = re.compile("""
    .*?
    @interface (?P<interface> .*?) 
     \{
    (?P<varblock> .*? )
    \}
    (?P<properties> .*?)
    @end
    .*?
    """, re.VERBOSE | re.M | re.DOTALL)

rxImplementation = re.compile("""
    .*?
    \@implementation\s+(?P<name>[a-zA-Z0-9_]+)
    (?P<body> .*?)
    \@end
    """, re.VERBOSE | re.M | re.DOTALL)
<commit_msg>External settings did not work, therefore removed<commit_after>#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""
Copyright (c) 2009 <NAME> <http://www.holtwick.it>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

CHANGELOG:

0.1 
- Initial release

0.2 (2009-09-04)
- Dealloc can contain custom data
- Adds missing dealloc correctly

0.3 (2009-09-11)
- viewDidUnload support

0.4 (2009-12-18)
- Joined with version of 'freewizard' with leading underscore support
- Some refactoring to make the source more readable
- Added XPUBLIC to mark public methods
- Alphabetical sorting of blocks
- Added MIT license

0.5 (2010-01-05)
- More refactoring
- Now work also when no properties are defined
- Prefix XPUBLIC also in Interface file to prepare for more intelligent
  handling of those marked methods in future
- Removed unsexy whitesapce 

0.6 (2010-01-06)
- Removed the prepending XPUBLIC from interface file because Interface
  Builder was not able to handle it  
- IBAction methods are always considered public (I don't see a case where
  they are not
- Static methods are also considered public

0.7 (2010-02-07)
- Fix for Apple Script calls
- Handle comment correctly
- New FORCE_METHODS setting 

0.8 (2010-02-15)
- Moved @synthesize to the end of files
- Moved @property to the end of files

0.9 (2010-03-14)
- Methods which start with 'initWith' are considered public
- Added XPROPERTY(..) for individual property definitions, e.g.
  XPROPERTY(readonly) id test;
- Removed XATOMIC and XREADONLY
- Code cleanup

0.10
- Now also works as build script
- Only handle files if different file times
- Only change files that contain X... macros
- Nonatomic can be turned of as default
- Strip trailing spaces
- Multiple file and path arguments
- Added XDELEGATE

0.11
- Fix: Can handle missing spaces around asterisk
- External settings did not work, therefore removed

TODO:

- Work with more implementations etc. in one file and match name
  => Currently just one implementation per file
- NSCoder support 
  => Create all needed stuff
- XPRIVATE 
  => Put them into a category in the implementation file
- Support for categories

"""

import re
import os
import os.path
import shutil
import pprint
import datetime
import subprocess

### CONFIG BEGIN 

DEBUG = 0
# BACKUP_FOLDER = 'BACKUP-XOBJC'
BACKUP_FOLDER = '/Users/dirk/work/_build/BACKUP-XOBJC'
FORCE_METHODS = False #True
STRIP_TRAILING_SPACES = True
NONATOMIC = ""
# NONATOMIC = "nonatomic, "

### CONFIG END 

rxInterface = re.compile("""
    .*?
    @interface (?P<interface> .*?) 
     \{
    (?P<varblock> .*? )
    \}
    (?P<properties> .*?)
    @end
    .*?
    """, re.VERBOSE | re.M | re.DOTALL)

rxImplementation = re.compile("""
    .*?
    \@implementation\s+(?P<name>[a-zA-Z0-9_]+)
    (?P<body> .*?)
    \@end
    """, re.VERBOSE | re.M | re.DOTALL)

{'fraction_non_alphanumeric': 0.08113509192645883, 'fraction_numerical': 0.025579536370903277, 'mean_word_length': 3.724354940213971, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '993739', 'n_tokens_mistral': 2411, 'n_tokens_neox': 2205, 'n_words': 980}