Skip to content

Commit

Permalink
Merge pull request #5 from samdmarshall/error-support
Browse files Browse the repository at this point in the history
fixing bug in loading some source files
  • Loading branch information
samdmarshall authored Dec 19, 2016
2 parents f3c3135 + b234fe3 commit 4052ddb
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,4 @@ lint: check

# ---

.PHONY: danger lint ci report test build clean install-tools install-deps check
.PHONY: danger lint ci report test build clean install-tools install-deps check
2 changes: 1 addition & 1 deletion install_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pyobjc-core >= 2.5.1
pyobjc-framework-Cocoa >= 2.5.1
pbPlist >= 1.0
pbPlist >= 1.0.3
langcodes >= 1.2.0
12 changes: 11 additions & 1 deletion nslocalizer/Executor/Executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import os
import re
import sys
from ..Helpers.Logger import Logger
from ..Helpers.FileOperations import FileOperations
from ..Language import Language
Expand Down Expand Up @@ -102,6 +103,8 @@ def findUnusedStrings(cls, project, targets) -> list:

for source_code_file in code_files:
data = FileOperations.getData(source_code_file)
if data is None:
continue
matches = re.findall(r'NSLocalizedString\(@?\"(.*?)\",', data)
Logger.write().debug('%s: %i results' % (os.path.basename(source_code_file), len(matches)))
known_strings.update(matches)
Expand All @@ -121,7 +124,14 @@ def generateLanguages(cls, project) -> (Language, {Language}):

if cls.base_language is None and cls.additional_languages is None:
cls.additional_languages = set([language for language in languages if language.code != 'Base'])
cls.base_language = languages.difference(cls.additional_languages).pop()
if len(cls.additional_languages) == len(languages):
Logger.write().info('Could not find a "Base" language, assuming "English"...')
cls.additional_languages = set([language for language in languages if language.code != 'en'])
if len(cls.additional_languages) == len(languages):
Logger.write().error('Unable to locate the "Base" language, please assign one in the project file!')
sys.exit(1)
other_languages = languages.difference(cls.additional_languages)
cls.base_language = other_languages.pop()
cls.base_language.findStrings()

return (cls.base_language, cls.additional_languages)
22 changes: 12 additions & 10 deletions nslocalizer/Helpers/FileOperations.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.

import os
import sys
from pbPlist import pbParser

Expand All @@ -36,14 +37,15 @@ class FileOperations(object):
@classmethod
def getData(cls, file_path) -> object:
data = None
try:
encoding = pbParser.GetFileEncoding(file_path)
file_descriptor = pbParser.OpenFileWithEncoding(file_path, encoding)
data = file_descriptor.read()
file_descriptor.close()
except IOError as exception: # pragma: no cover
print('I/O error({0}): {1}'.format(exception.errno, exception.strerror))
except: # pragma: no cover
print('Unexpected error:'+str(sys.exc_info()[0]))
raise
if os.path.isfile(file_path) is True:
try:
encoding = pbParser.GetFileEncoding(file_path)
file_descriptor = pbParser.OpenFileWithEncoding(file_path, encoding)
data = file_descriptor.read()
file_descriptor.close()
except IOError as exception: # pragma: no cover
print('I/O error({0}): {1}'.format(exception.errno, exception.strerror))
except: # pragma: no cover
print('Unexpected error:'+str(sys.exc_info()[0]))
raise
return data
2 changes: 1 addition & 1 deletion nslocalizer/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@

from . import version_info

__version__ = '0.1 ('+version_info.remote_origin+' @ '+version_info.commit_hash+')'
__version__ = '1.0.1 ('+version_info.remote_origin+' @ '+version_info.commit_hash+')'
2 changes: 1 addition & 1 deletion nslocalizer/version_info.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
remote_origin = '[email protected]:samdmarshall/nslocalizer.git'
commit_hash = 'e994cee'
commit_hash = 'ccd8733'
2 changes: 2 additions & 0 deletions nslocalizer/xcodeproj/pbProj/PBX_Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,5 @@
kPBX_XCBUILDCONFIG_baseConfigurationReference = 'baseConfigurationReference'

kPBX_XCCONFIGURATION_buildConfigurations = 'buildConfigurations'

kPBX_XCVersionGroup_currentVersion = 'currentVersion'
2 changes: 2 additions & 0 deletions nslocalizer/xcodeproj/pbProj/PBX_Lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
from . import PBXZipArchiveReference
from . import XCBuildConfiguration
from . import XCConfigurationList
from . import XCVersionGroup

PBX_TYPE_TABLE = {
'PBXAggregateTarget': PBXAggregateTarget.PBXAggregateTarget,
Expand Down Expand Up @@ -102,6 +103,7 @@
'PBXZipArchiveReference': PBXZipArchiveReference.PBXZipArchiveReference,
'XCBuildConfiguration': XCBuildConfiguration.XCBuildConfiguration,
'XCConfigurationList': XCConfigurationList.XCConfigurationList,
'XCVersionGroup': XCVersionGroup.XCVersionGroup,
}

def PBX_Type_Resolver(identifier, dictionary):
Expand Down
40 changes: 40 additions & 0 deletions nslocalizer/xcodeproj/pbProj/XCVersionGroup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2016, Samantha Marshall (http://pewpewthespells.com)
# All rights reserved.
#
# https://github.com/samdmarshall/nslocalizer
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# 3. Neither the name of Samantha Marshall nor the names of its contributors may
# be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.

from . import PBX_Constants
from .PBXItem import PBX_Base_Reference

class XCVersionGroup(PBX_Base_Reference):
def __init__(self, identifier, dictionary):
super(self.__class__, self).__init__(identifier, dictionary)
def resolveGraph(self, project):
super(self.__class__, self).resolveGraph(project)
self.resolveGraphNodesForArray(PBX_Constants.kPBX_REFERENCE_children, project)
self.resolveGraphNodeForKey(PBX_Constants.kPBX_XCVersionGroup_currentVersion, project)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ pylint >= 1.6.1

pyobjc-core >= 2.5.1
pyobjc-framework-Cocoa >= 2.5.1
pbPlist >= 1.0
pbPlist >= 1.0.3
langcodes >= 1.2.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

setup(
name = 'nslocalizer',
version = '1.0',
version = '1.0.1',
description = 'Tool for finding missing and unused NSLocalizdStrings',
url = 'https://github.com/samdmarshall/nslocalizer',
author = 'Samantha Marshall',
Expand Down

0 comments on commit 4052ddb

Please sign in to comment.