• sreyemnayr

    Here's the re-worked script, which throws as many of those dummies at the top of each file as it needs to stop the madness.

    EDIT: There are some problems with this method as well, as it bounces the lines indicating the encoding style, which breaks a bunch of stuff... I ended up having to regex replace them back to the top, but will work this script out to do it better later. Just be aware that this will happen!

    # Change these:
    pylib_path1 = '/path/to/PythonistaKit.framework/pylib'
    pylib_path2 = '/path/to/PythonistaKit.framework/pylib_ext'
    import shutil
    import os
    import subprocess
    def check_is_executable(file_path):
        file_output = subprocess.check_output(['file', file_path])
        if 'executable' in file_output:
            return True, file_output
        return False, file_output
    def fix_executable(file_path):
        with open(file_path, 'r') as f:
            source = f.read()
        with open(file_path, 'w') as f:
            f.write('#\input texinfo\n' + source)
        is_executable, out = check_is_executable(file_path)
        return not is_executable
    def fix_pylib(pylib_path, dry_run=False):
        for path, dirs, files in os.walk(pylib_path):
            for filename in files:
                full_path = full_path = os.path.join(path, filename)
                is_executable, file_output = check_is_executable(full_path)
                if is_executable:
                    extension = os.path.splitext(full_path)[1].lower()
                    if extension == '.py' or extension == '.pym' or filename == 'command_template':
                        if dry_run:
                            print '### Executable found: %s' % (filename,)
                            print 'Fixing %s...' % (filename,)
                            fixed = False
                            counter = 0
                            while not fixed:
                                fixed = fix_executable(full_path)
                                counter = counter + 1
                            print 'Fixed with '+str(counter)+' dummy lines.'
                        print '### Executable found, but does not seem to be Python code: %s' % (full_path,)
    if __name__ == '__main__':

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!