예제 #1
0
def init_res():

    if not os.path.exists(local_dir):
        os.mkdir(local_dir)
    print 'local_dir: %s' % local_dir

    for componet_path in find_file_dirs_iter(os.path.abspath(root_dir), 'AndroidManifest.xml'):
        res_dir = os.path.join(componet_path, 'res')
        if not os.path.exists(res_dir):
            continue

        values_dir = os.path.join(res_dir, 'values')
        if not os.path.exists(values_dir):
            continue

        subdir_name = filedir2name(os.path.relpath(componet_path, root_dir))
        gettext_dir = os.path.join(local_dir, subdir_name)
        if not os.path.exists(gettext_dir):
            os.mkdir(gettext_dir)

        program.main(('test', 'init', '--android', res_dir, '--gettext', gettext_dir, 'language', LANGUAGE_CODE))

        write_po_content_to_xlsx(gettext_dir, LANGUAGE_CODE)

    merge_component_xl(local_dir, 'totol.xlsx')
예제 #2
0
def init_res():

    if not os.path.exists(local_dir):
        os.mkdir(local_dir)
    print 'local_dir: %s' % local_dir

    for componet_path in find_file_dirs_iter(os.path.abspath(root_dir),
                                             'AndroidManifest.xml'):
        res_dir = os.path.join(componet_path, 'res')
        if not os.path.exists(res_dir):
            continue

        values_dir = os.path.join(res_dir, 'values')
        if not os.path.exists(values_dir):
            continue

        subdir_name = filedir2name(os.path.relpath(componet_path, root_dir))
        gettext_dir = os.path.join(local_dir, subdir_name)
        if not os.path.exists(gettext_dir):
            os.mkdir(gettext_dir)

        program.main(('test', 'init', '--android', res_dir, '--gettext',
                      gettext_dir, 'language', LANGUAGE_CODE))

        write_po_content_to_xlsx(gettext_dir, LANGUAGE_CODE)

    merge_component_xl(local_dir, 'totol.xlsx')
예제 #3
0
def import_res():
    subxlfilepaths = xlutils.separate_xl_content(TOTAL_XLSX_FILEPATH)
    print subxlfilepaths

    # delete all po file??
    # TODO: delete all po file??

    for subxlfile in subxlfilepaths:
        xlutils.upodate_component_xl_content2pofile(subxlfile)

        subxldir = os.path.dirname(subxlfile)
        relative_dir = os.path.relpath(subxldir, local_dir)
        componet_res_dir = os.path.join(root_dir,name2filedir(relative_dir), 'res')
        print "componet_dir: %s" % componet_res_dir

        program.main(('test', 'import', '--android', componet_res_dir,
        '--gettext', subxldir))
예제 #4
0
def import_res():
    subxlfilepaths = xlutils.separate_xl_content(TOTAL_XLSX_FILEPATH)
    print subxlfilepaths

    # delete all po file??
    # TODO: delete all po file??

    for subxlfile in subxlfilepaths:
        xlutils.upodate_component_xl_content2pofile(subxlfile)

        subxldir = os.path.dirname(subxlfile)
        relative_dir = os.path.relpath(subxldir, local_dir)
        componet_res_dir = os.path.join(root_dir, name2filedir(relative_dir),
                                        'res')
        print "componet_dir: %s" % componet_res_dir

        program.main(('test', 'import', '--android', componet_res_dir,
                      '--gettext', subxldir))
예제 #5
0
    def execute(self):
        cur_path = os.getcwd()
        with closing(TranslateDict(self.dictionary)) as dic:
            for subpath in Android_Component_SubPath:
                model_path = os.path.join(cur_path, subpath)
                res_path = os.path.join(model_path, RES_DIR)
                values_path = os.path.join(model_path, VALUES_DIR)

                local_path = os.path.join(model_path, LOCAL_DIR)
                print local_path
                if not os.path.exists(local_path):
                    os.mkdir(local_path)

                program.main(
                    ("just_do_it", "init", "--android", res_path, "--gettext", local_path, "language", self.language)
                )

                args = {"language_code": self.language, "dict": dic}
                os.path.walk(local_path, self._visit_po_file, args)
예제 #6
0
    def program(self, command=None, kwargs={}, expect=None):
        """Run android2po in this project's working directory.

        Return the program output.
        """
        args = ['a2po-test']
        if command:
            args.append(command)
        for k, v in kwargs.iteritems():
            if v is True or not v:
                args.append(k)
            else:
                if not isinstance(v, (list, tuple)):
                    # A tuple may be used to pass the same argument multiple
                    # times with different values.
                    v = [v]
                for w in v:
                    if isinstance(w, (list, tuple)):
                        # This is starting to get messy, but this allows the
                        # caller to generate "--arg val1 val2" by passing as
                        # the dict: {'arg': [['val1', 'val2']]}
                        args.append('%s' % k)
                        args.extend(w)
                    else:
                        # Otherwise, we set a single value, and we use "=",
                        # so that arguments that are defined as nargs='+'
                        # will not capture more than the value "w".
                        args.append("%s=%s" % (k, w))

        old_cwd = os.getcwd()
        os.chdir(self.dir)
        # Sometimes we might want to check a certain message was printed
        # out, so in addition to having nose capture the output, we
        # want to as well.
        old_stdout = sys.stdout
        stdout_capture = StringIO.StringIO()
        sys.stdout = Tee(sys.stdout, stdout_capture)
        # argparse likes to write to stderr, let it be handled like
        # normal stdout (i.e. captured by nose as well as us).
        old_stderr = sys.stderr
        sys.stderr = sys.stdout
        try:
            try:
                print "Running: %s" % " ".join(args)
                ret = a2po.main(args)
            except SystemExit, e:
                # argparse likes to raise this if arguments are invalid.
                raise SystemExitCaught('SystemExit raised by program: %s', e)
            else:
예제 #7
0
    def program(self, command=None, kwargs={}):
        """Run android2po in this project's working directory.

        Return the program output.
        """
        args = ['a2po-test']
        if command:
            args.append(command)
        for k, v in kwargs.iteritems():
            if v is True or not v:
                args.append(k)
            else:
                if not isinstance(v, (list, tuple)):
                    # A tuple may be used to pass the same argument multiple
                    # times with different values.
                    v = [v]
                for w in v:
                    if isinstance(w, (list, tuple)):
                        # This is starting to get messy, but this allows the
                        # caller to generate "--arg val1 val2" by passing as
                        # the dict: {'arg': [['val1', 'val2']]}
                        args.append('%s' % k)
                        args.extend(w)
                    else:
                        # Otherwise, we set a single value, and we use "=",
                        # so that arguments that are defined as nargs='+'
                        # will not capture more than the value "w".
                        args.append("%s=%s" % (k, w))

        old_cwd = os.getcwd()
        os.chdir(self.dir)
        # Sometimes we might want to check a certain message was printed
        # out, so in addition to having nose capture the output, we
        # want to as well.
        old_stdout = sys.stdout
        stdout_capture = StringIO.StringIO()
        sys.stdout = Tee(sys.stdout, stdout_capture)
        # argparse likes to write to stderr, let it be handled like
        # normal stdout (i.e. captured by nose as well as us).
        old_stderr = sys.stderr
        sys.stderr = sys.stdout
        try:
            try:
                print "Running: %s" % " ".join(args)
                ret = a2po.main(args)
            except SystemExit, e:
                # argparse likes to raise this if arguments are invalid.
                raise SystemExitCaught('SystemExit raised by program: %s', e)
            else: