def main():
    if appex.is_running_extension():
        file_paths = appex.get_file_paths()
        assert len(file_paths) == 1, 'Invalid file paths: {}'.format(file_paths)
        srce_path = file_paths[0]
        if '/tmp/' in srce_path:
            dest_path = srce_path.split('/tmp/')[-1]
        else:
            dest_path = srce_path.split('/Repositories/')[-1]
        dest_path = os.path.join(from_wc, dest_path)
        file_path, file_name = os.path.split(dest_path)
        if not os.path.exists(file_path):
            os.makedirs(file_path)
        if os.path.isdir(srce_path):
            shutil.rmtree(dest_path, ignore_errors=True)
            print(shutil.copytree(srce_path, dest_path))
        else:
            print(shutil.copy2(srce_path, dest_path))
        print('{} was copied to {}'.format(file_name, file_path))
    else:
        print('''* In Working Copy app select a repo, file, or directory to be
copied into Pythonista.  Click the Share icon at the upperight.  Click Run
Pythonista Script.  Pick this script and click the run button.  When you return
to Pythonista the files should be in the 'from Working Copy'
directory.'''.replace('\n', ' ').replace('.  ', '.\n* '))
Esempio n. 2
0
def main():

    if not is_running_extension():
        print('This script is intended to be run from the sharing extension.')
        return

    files = get_file_paths()

    if not files:
        alert('No files were specified')
        return

    for file in files:
        filename = path.basename(file)

        if not filename.endswith('.pdf'):
            showAlert('Only PDF are allowed', filename)
            continue

        pdf = ObjCClass('PDFDocument').alloc().initWithURL(nsurl(file))

        if pdf.isEncrypted():
            pwd = input_alert('Password', filename)
            if pdf.unlockWithPassword_(pwd):
                pdf.writeToFile_(file)
            else:
                showAlert("Wrong Password", filename)
        else:
            showAlert("This PDF is not encrypted", filename)
    finish()
Esempio n. 3
0
def main():
    if appex.is_running_extension():
        for file_path in appex.get_file_paths():
            print(file_path)