print "Downloaded to", zipPath[0] #Extract to /tmp/Crowdin zip = ZipFile(zipPath[0]) extractDir = os.path.join(os.path.dirname(zipPath[0]), "Crowdin") zip.extractall(extractDir) print "Extracted to", extractDir print "Attempting to match Crowdin files with Android" #Get valid Crowdin folder mappings crowdinMappings = helper.GetCrowdinMappings(extractDir) #Get list of files to copy isSingleFolderUpdate = helper.IsSingleFolderUpdate(options.path) matchingFiles = helper.GetMatchingCrowdinFiles(languageCodes, crowdinMappings, not isSingleFolderUpdate) #Get res directory targetResDirectory = helper.GetResDirectory(options.path) #Copy the files if not len(matchingFiles): print "No matching files found" for k, v in matchingFiles.iteritems(): targetStringsXml = helper.GetTargetStringsXml(targetResDirectory, k) if not os.path.exists(os.path.dirname(targetStringsXml)): os.makedirs(os.path.dirname(targetStringsXml))
def test_GetMatchingCrowdinFiles_DifferentNarrowScope_ReturnsPathToDifferentNarrowScope(self): lc = ['en', 'fr', 'pt', 'es'] cm = {'fr':'/french', 'pt-PT' : '/narrowPortuguese', 'es-MX' : '/mexicanPath'} matches = helper.GetMatchingCrowdinFiles(lc, cm) self.assertEqual(matches['es'], '/mexicanPath')
def test_GetMatchingCrowdinFiles_NotInLanguageCodeButNarrowerScopeThanExisting_RemovesMatchedNarrow(self): lc = ['de'] cm = { 'de-NL' : '/Netherlands', 'de-MX': '/Mexico'} matches = helper.GetMatchingCrowdinFiles(lc, cm) self.assertEqual(matches['de'], '/Mexico') self.assertTrue('de-MX' not in matches)
def test_GetMatchingCrowdinFiles_NarrowScopeMatchedFirst(self): lc = {'zh-TW' , 'zh'} cm = { 'zh-TW':'/zhtwPath', 'zh-CN': '/zhcnPath' } matches = helper.GetMatchingCrowdinFiles(lc,cm, True) self.assertEqual('/zhcnPath', matches['zh'])
def test_GetMatchingCrowdinFiles_NoWideScopedLanguageCode_ReturnsPathToNarrowScope(self): lc = ['en', 'fr', 'pt'] cm = {'fr':'/french', 'pt-PT' : '/narrowPortuguese'} matches = helper.GetMatchingCrowdinFiles(lc, cm) self.assertEqual(matches['pt'], '/narrowPortuguese')
def test_GetMatchingCrowdinFiles_NonMatchingEnglish_NotReturnedInDictionary(self): lc = ['en', 'fr', 'sv-SE'] cm = {'fr':'/french'} matches = helper.GetMatchingCrowdinFiles(lc, cm) self.assertTrue('en' not in matches)
def test_GetMatchingCrowdinFiles_MatchingFrench_ReturnsPathToFrenchFile(self): lc = ['en', 'fr', 'sv-SE'] cm = {'fr':'/french'} matches = helper.GetMatchingCrowdinFiles(lc, cm) self.assertEqual(matches['fr'], "/french")
def test_GetMatchingCrowdinFiles_IncludeNewFolders_ReturnsNewFolders(self): lc = ['de'] cm = { 'de-NL' : '/Netherlands', 'de-MX': '/Mexico'} matches = helper.GetMatchingCrowdinFiles(lc, cm, True) self.assertEqual(matches['de'], '/Mexico') self.assertTrue('de-NL' in matches)