<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Android Simulator for building a project and launching
# the Android Emulator or on the device
#
import os, sys, subprocess, shutil, time, signal, string, platform, re, glob
import run, avd, prereq
from os.path import splitext
from compiler import Compiler
from os.path import join, splitext, split, exists
from shutil import copyfile

template_dir = os.path.abspath(os.path.dirname(sys._getframe(0).f_code.co_filename))
sys.path.append(os.path.join(template_dir,'..'))
sys.path.append(os.path.join(template_dir,'../common'))

from tiapp import *
from android import Android
from androidsdk import AndroidSDK
from deltafy import Deltafy, Delta
from css import csscompiler
import localecompiler

ignoreFiles = ['.gitignore', '.cvsignore', '.DS_Store'];
ignoreDirs = ['.git','.svn','_svn', 'CVS'];
android_avd_hw = [['hw.camera', 'yes'],['hw.gps','yes']]
res_skips = ['style']

RA_TEMPLATE="""
/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by 
 * Appcelerator from the resource data it found.  It
 * should not be modified by hand.
 */

package %s;

import java.util.HashMap;

public final class RA 
{

%s
    static {
%s
    }
    
%s    
}"""

def parse_r(fn):
    """
    parse an Android R file and returns a map of resources where each
    value is another map of the resource key/values
    """
    f = open(fn).read()
    map = {}
    cur = None
    package = None
    for line in f.splitlines():
        if cur == None:
            if line.startswith('package '):
                package = line[8:-1]
                continue
            idx = line.find('public static final class ')
            if idx != -1:
                part = line[idx+26:-2]
                if part in res_skips: continue
                cur = part
                map[cur]={}
        elif line.find('}')!=-1:
            cur = None
        else:
            idx = line.find('final int ')
            res = line[idx+10:-1]
            k,v = res.split("=")
            map[cur][k]=v
    return package,map

def generate_appc_r(package,map):
    prefix = ''
    content = ''
    defines = ''
    for k in map:
        values = map[k]
        prefix+="    private static final HashMap<String,Integer> _%s = new HashMap<String,Integer>();\n" % k
        defines+="    public static final Integer get%s(String key){\n" % k.capitalize()
        defines+="       return _%s.get(key);\n" % k
        defines+="    }\n"
        for kk in values:
            content+="        _%s.put(\"%s\",%s);\n" % (k,kk,values[kk])
    return RA_TEMPLATE % (package,prefix,content,defines)  

def dequote(s):
	if s[0:1] == '"':
		return s[1:-1]
	return s

def pipe(args1,args2):
	p1 = subprocess.Popen(args1, stdout=subprocess.PIPE)
	p2 = subprocess.Popen(args2, stdin=p1.stdout, stdout=subprocess.PIPE)<commit_msg>only split on = when a constant is found<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Android Simulator for building a project and launching
# the Android Emulator or on the device
#
import os, sys, subprocess, shutil, time, signal, string, platform, re, glob
import run, avd, prereq
from os.path import splitext
from compiler import Compiler
from os.path import join, splitext, split, exists
from shutil import copyfile

template_dir = os.path.abspath(os.path.dirname(sys._getframe(0).f_code.co_filename))
sys.path.append(os.path.join(template_dir,'..'))
sys.path.append(os.path.join(template_dir,'../common'))

from tiapp import *
from android import Android
from androidsdk import AndroidSDK
from deltafy import Deltafy, Delta
from css import csscompiler
import localecompiler

ignoreFiles = ['.gitignore', '.cvsignore', '.DS_Store'];
ignoreDirs = ['.git','.svn','_svn', 'CVS'];
android_avd_hw = [['hw.camera', 'yes'],['hw.gps','yes']]
res_skips = ['style']

RA_TEMPLATE="""
/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by 
 * Appcelerator from the resource data it found.  It
 * should not be modified by hand.
 */

package %s;

import java.util.HashMap;

public final class RA 
{

%s
    static {
%s
    }
    
%s    
}"""

def parse_r(fn):
    """
    parse an Android R file and returns a map of resources where each
    value is another map of the resource key/values
    """
    f = open(fn).read()
    map = {}
    cur = None
    package = None
    for line in f.splitlines():
        if cur == None:
            if line.startswith('package '):
                package = line[8:-1]
                continue
            idx = line.find('public static final class ')
            if idx != -1:
                part = line[idx+26:-2]
                if part in res_skips: continue
                cur = part
                map[cur]={}
        elif line.find('}')!=-1:
            cur = None
        else:
            idx = line.find('final int ')
            if idx != -1:
                res = line[idx+10:-1]
                k,v = res.split("=")
                map[cur][k]=v
    return package,map

def generate_appc_r(package,map):
    prefix = ''
    content = ''
    defines = ''
    for k in map:
        values = map[k]
        prefix+="    private static final HashMap<String,Integer> _%s = new HashMap<String,Integer>();\n" % k
        defines+="    public static final Integer get%s(String key){\n" % k.capitalize()
        defines+="       return _%s.get(key);\n" % k
        defines+="    }\n"
        for kk in values:
            content+="        _%s.put(\"%s\",%s);\n" % (k,kk,values[kk])
    return RA_TEMPLATE % (package,prefix,content,defines)  

def dequote(s):
	if s[0:1] == '"':
		return s[1:-1]
	return s

def pipe(args1,args2):
	p1 = subprocess.Popen(args1, stdout=subprocess.PIPE)
	p2 = subprocess.Popen(args2, stdin=p1.stdout, stdout=subprocess.PIPE)
{'fraction_non_alphanumeric': 0.13868362261556968, 'fraction_numerical': 0.00807698917339749, 'mean_word_length': 2.54014598540146, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '91248', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1905, 'n_words': 539}