-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
read_from_working_copy_app.py
38 lines (32 loc) · 1.42 KB
/
read_from_working_copy_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
# coding: utf-8
# Appex script to copy a git file, folder, or repo from the Working Copy app
import appex, os, shutil
from_wc = os.path.abspath(os.path.expanduser('from Working Copy'))
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* '))
if __name__ == '__main__':
main()