コード例 #1
0
 def show_option_list(self):
     print('*'*30)
     print(':: Android Builder ::')
     print('*'*30)
     print('\nSelect an option:')
     print('\t1: Build application')
     print('\t2: Custom build')
     print('\t3: Run application')
     print('\t4: Refresh build')
     print('\t5: Exit')
     choice = None
     while choice != 5:
         choice = input('Enter a choice [1-5]: ')
         try:
             choice = int(choice)
         except ValueError:
             Print.printRed(f"INVALID CHOICE: '{choice}'")
             continue
        
         # Manipulate user choice
         if choice == 1: # Build application
             os.system('clear')
             self.build_application()
             break
     
         elif choice == 2:
             pass
         elif choice == 3:
             pass
         elif choice == 4:
             pass
         elif choice == 5: # Exit
             continue
         else:
             print(f"INVALID CHOICE: '{choice}'")
コード例 #2
0
def _AddFullPattern(full_pattern, metre_name):
    if full_pattern in known_full_patterns:
        # TODO(shreevatsa): Figure out what exactly to do in this case
        Print('Error: full pattern already present')
        Print(metre_name)
        Print(full_pattern)
        Print(known_full_patterns[full_pattern])
        return False
    assert full_pattern not in known_full_patterns
    known_full_patterns[full_pattern] = {metre_name: True}
    return True
コード例 #3
0
def _AddPatternForMetre(metre_name, pada_patterns):
    if metre_name in pattern_for_metre:
        if pattern_for_metre[metre_name] != pada_patterns:
            Print('Mismatch for %s' % metre_name)
            Print(pattern_for_metre[metre_name])
            Print('   vs   ')
            Print(pada_patterns)
            assert False
        # Print('Not adding duplicate as already present: %s' % metre_name)
        return
    pattern_for_metre[metre_name] = pada_patterns
コード例 #4
0
def _AddArdhasamavrttaPattern(metre_name, odd_and_even_pada_patterns):
    """Given an ardha-sama-vṛtta's pattern, add it."""
    (odd_pada_pattern, even_pada_pattern) = odd_and_even_pada_patterns
    clean_odd = _CleanUpPattern(odd_pada_pattern)
    assert re.match(r'^[LG]*$', clean_odd)
    clean_even = _CleanUpPattern(even_pada_pattern)
    if clean_even.endswith('L'):
        Print('Not adding %s for now, as %s ends with laghu' %
              (metre_name, clean_even))
        return
    assert re.match(r'^[LG]*G$', clean_even), (metre_name, clean_even)
    _AddPatternForMetre(metre_name, [clean_odd, clean_even] * 2)

    patterns_odd = [clean_odd[:-1] + 'G', clean_odd[:-1] + 'L']
    patterns_even = [clean_even[:-1] + 'G', clean_even[:-1] + 'L']
    for (a, b, c, d) in itertools.product(patterns_odd,
                                          patterns_even,
                                          repeat=2):
        _AddFullPattern(a + b + c + d, metre_name)
    for (a, b) in itertools.product(patterns_odd, patterns_even):
        _AddHalfPattern(a + b, metre_name, {1, 2})
    for a in patterns_odd:
        _AddPadaPattern(a, metre_name, {1, 3})
    for b in patterns_even:
        _AddPadaPattern(b, metre_name, {2, 4})
コード例 #5
0
def _AddPatternForMetre(metre_name, pada_patterns):
    if metre_name in pattern_for_metre:
        if pattern_for_metre[metre_name] != pada_patterns:
            # Print('Mismatch for %s' % metre_name)
            # Print(pattern_for_metre[metre_name])
            # Print('   vs   ')
            # Print(pada_patterns)
            # assert False
            Print('Not overwriting as already present: %s' % metre_name)
        return
    pattern_for_metre[metre_name] = pada_patterns
コード例 #6
0
def set_up_logger(input_file_name):
    logger = logging.getLogger()
    log_file = tempfile.NamedTemporaryFile(prefix='read_gretil_%s_' %
                                           os.path.basename(input_file_name),
                                           delete=False)
    Print('Logging to %s' % log_file.name)
    handler = logging.FileHandler(log_file.name)
    handler.setFormatter(
        logging.Formatter(
            '%(levelname)s\t%(asctime)s %(filename)s:%(lineno)d] %(message)s'))
    logger.addHandler(handler)
    logger.setLevel(logging.DEBUG)
コード例 #7
0
ファイル: main.py プロジェクト: jsdelivrbot/sanskrit-1
 def post(self):
     verse_text = self.request.get('verse_text')
     assert type(verse_text) == type('unicode literal')
     metre_name = self.request.get('metre_name')
     Print('Type of metre_name is ' +
           ('bytes' if type(metre_name) else 'unicode'))
     if isinstance(metre_name, bytes):
         metre_name = metre_name.decode('utf-8')
     print('Type of metre_name is now ', type(metre_name))
     (alignment, table) = find_alignment(verse_text, metre_name)
     ret = {'alignment': alignment, 'table': table}
     self.response.content_type = b'application/json'
     self.response.write(json.dumps(ret))
コード例 #8
0
 def print_task_end(self, task, process):
     if process.returncode != 0: 
         # Command was unsuccessful
         print("\n" + process.stdout + process.stderr)
         Print.printRed(f'  > [{task}]... FAIL')
         print('*'*30)
         return False
     elif not (process.stdout + process.stderr).strip():
         # Command was successful but did not produced any output
          Print.printGreen(' OK')
     else:
         # Command was successful but produced some output
         print("\n\n" + process.stdout + process.stderr)
         Print.printGreen(f'  > [{task}]... OK')
     return True
コード例 #9
0
            '%(levelname)s\t%(asctime)s %(filename)s:%(lineno)d] %(message)s'))
    logger.addHandler(handler)
    logger.setLevel(logging.DEBUG)


if __name__ == '__main__':
    args = get_args()
    input_file_name = args.input_file
    set_up_logger(input_file_name)

    text = codecs.open(input_file_name, 'r', 'utf-8').read()
    custom_splitter = read.split_gretil.mss_splitter if 'msubhs_u.htm' in input_file_name else None
    (verses, text) = read.split_gretil.split(text,
                                             custom_splitter=custom_splitter)
    # blocks = list(read.split_gretil.blocks_of_verses_in_text(verses, text))
    Print('There are %d verses.' % len(verses))

    identifier = identifier_pipeline.IdentifierPipeline()
    table = {}
    for (verse_number, verse) in enumerate(verses):
        verse_number += 1
        Print('\nVerse %d is:' % verse_number)
        Print('\n    '.join(('    ' + verse).splitlines()))
        Print('End Verse %d' % verse_number)
        ok_and_results = identifier.IdentifyFromText(verse)
        if not ok_and_results:  # None for lines that contain no syllables
            continue
        (perfect, results) = ok_and_results
        if not results:
            table['unknown'] = table.get('unknown', 0) + 1
            if args.print_unidentified_verses != 'none':
コード例 #10
0
 def __init__(self):
     global Print
     Print = Print()
     os.system('clear')
     self.do_initial_setup()
     self.show_option_list()
コード例 #11
0
    def build_application(self):
        builder = Builder()
        
        # Compile android raw resources
        Print.printBold('> Compiling <resources> using [aapt2]...', end='')
        process = builder.compile_resources()
        if not self.print_task_end("aapt2", process):
            return

        # Link AndroidManifest.xml and generate R.java
        Print.printBold('\n> Linking <resources> using [aapt2]...', end='')
        process = builder.link_resources()
        if not self.print_task_end("aapt2", process):
            return

        # Compile java source code
        Print.printBold("\n> Compiling <java> using [ecj]...", end='')
        process = builder.compile_source_code()
        if not self.print_task_end("ecj", process):
            return

        # Dex source code
        Print.printBold("\n> Dexing <class> using [d8]...", end='')
        process = builder.dex_source_code()
        if not self.print_task_end('d8', process):
            return

        # Create apk from resources.arsc and classes.dex
        Print.printBold("\n> Adding <dex> to <apk> using [zip]...", end='')
        process = builder.add_dex_to_apk()
        if not self.print_task_end('zip', process):
            return

        # Align and sign in apk
        Print.printBold("\n> Aligning and signing <apk> using [jarsigner & zipalign]...", end='')
        process = builder.sign_and_align_apk()
        if not self.print_task_end('jarsigner & zipalign', process):
            return

        # Prompt for installation of apk
        Print.printBold("\n> Installing <apk> using [am & DevColleague]...", end='')
        process = BuilderHelper().prompt_install()
        if not self.print_task_end('am & DevColleague', process):
            return