Mercurial > repos > eric-rasche > apollo
comparison fetch_organism_jbrowse.py @ 7:f9a6e151b3b4 draft
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
author | eric-rasche |
---|---|
date | Tue, 27 Jun 2017 04:05:17 -0400 |
parents | d4ae83dedb14 |
children |
comparison
equal
deleted
inserted
replaced
6:8f76685cdfc8 | 7:f9a6e151b3b4 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 from __future__ import print_function | |
2 import os | 3 import os |
4 import sys | |
5 import time | |
3 import argparse | 6 import argparse |
4 from webapollo import WAAuth, WebApolloInstance, GuessOrg, OrgOrGuess | 7 import filecmp |
8 import os.path | |
5 import logging | 9 import logging |
6 import subprocess | 10 import subprocess |
11 from webapollo import WAAuth, WebApolloInstance, GuessOrg, OrgOrGuess | |
7 logging.basicConfig(level=logging.INFO) | 12 logging.basicConfig(level=logging.INFO) |
8 log = logging.getLogger(__name__) | 13 log = logging.getLogger(__name__) |
14 | |
15 | |
16 def are_dir_trees_equal(dir1, dir2): | |
17 """ | |
18 Compare two directories recursively. Files in each directory are | |
19 assumed to be equal if their names and contents are equal. | |
20 | |
21 @param dir1: First directory path | |
22 @param dir2: Second directory path | |
23 | |
24 @return: True if the directory trees are the same and | |
25 there were no errors while accessing the directories or files, | |
26 False otherwise. | |
27 | |
28 # http://stackoverflow.com/questions/4187564/recursive-dircmp-compare-two-directories-to-ensure-they-have-the-same-files-and/6681395#6681395 | |
29 """ | |
30 | |
31 dirs_cmp = filecmp.dircmp(dir1, dir2) | |
32 if len(dirs_cmp.left_only) > 0 or len(dirs_cmp.right_only) > 0 or \ | |
33 len(dirs_cmp.funny_files) > 0: | |
34 print(('LEFT', dirs_cmp.left_only)) | |
35 print(('RIGHT', dirs_cmp.right_only)) | |
36 print(('FUNNY', dirs_cmp.funny_files)) | |
37 return False | |
38 (_, mismatch, errors) = filecmp.cmpfiles( | |
39 dir1, dir2, dirs_cmp.common_files, shallow=False) | |
40 if len(mismatch) > 0 or len(errors) > 0: | |
41 print(mismatch) | |
42 print(errors) | |
43 return False | |
44 for common_dir in dirs_cmp.common_dirs: | |
45 new_dir1 = os.path.join(dir1, common_dir) | |
46 new_dir2 = os.path.join(dir2, common_dir) | |
47 if not are_dir_trees_equal(new_dir1, new_dir2): | |
48 return False | |
49 return True | |
9 | 50 |
10 | 51 |
11 if __name__ == '__main__': | 52 if __name__ == '__main__': |
12 parser = argparse.ArgumentParser(description='Sample script to add an attribute to a feature via web services') | 53 parser = argparse.ArgumentParser(description='Sample script to add an attribute to a feature via web services') |
13 WAAuth(parser) | 54 WAAuth(parser) |
24 org = wa.organisms.findOrganismByCn(org_cn) | 65 org = wa.organisms.findOrganismByCn(org_cn) |
25 | 66 |
26 if not os.path.exists(args.target_dir): | 67 if not os.path.exists(args.target_dir): |
27 os.makedirs(args.target_dir) | 68 os.makedirs(args.target_dir) |
28 | 69 |
70 if not os.path.exists(os.path.join(org['directory'], 'seq')): | |
71 sys.stderr.write("Missing seq directory BEFORE copy") | |
72 sys.exit(1) | |
73 | |
29 cmd = [ | 74 cmd = [ |
30 'cp', '-R', | 75 'rsync', '-avr', |
31 org['directory'], | 76 org['directory'].rstrip('/') + '/', |
77 os.path.join(args.target_dir, 'data', '') | |
78 ] | |
79 # We run this OBSESSIVELY because my org had a hiccup where the origin | |
80 # (silent) cp -R failed at one point. This caused MANY HEADACHES. | |
81 # | |
82 # Our response is to run this 3 times (in case the issue is temporary), | |
83 # with delays in between. And ensure that we have the correct number of | |
84 # files / folders before and after. | |
85 sys.stderr.write(' '.join(cmd)) | |
86 sys.stderr.write('\n') | |
87 sys.stderr.write(subprocess.check_output(cmd)) | |
88 if not are_dir_trees_equal( | |
89 os.path.join(org['directory'].rstrip('/')), | |
32 os.path.join(args.target_dir, 'data') | 90 os.path.join(args.target_dir, 'data') |
33 ] | 91 ): |
34 subprocess.check_call(cmd) | 92 # Not good |
93 time.sleep(5) | |
94 sys.stderr.write('\n') | |
95 sys.stderr.write(' '.join(cmd)) | |
96 sys.stderr.write('\n') | |
97 sys.stderr.write(subprocess.check_output(cmd)) | |
98 if not are_dir_trees_equal( | |
99 os.path.join(org['directory'].rstrip('/'), 'data'), | |
100 os.path.join(args.target_dir, 'data') | |
101 ): | |
102 time.sleep(5) | |
103 sys.stderr.write('\n') | |
104 sys.stderr.write(' '.join(cmd)) | |
105 sys.stderr.write('\n') | |
106 sys.stderr.write(subprocess.check_output(cmd)) | |
107 if not are_dir_trees_equal( | |
108 os.path.join(org['directory'].rstrip('/'), 'data'), | |
109 os.path.join(args.target_dir, 'data') | |
110 ): | |
111 sys.stderr.write('FAILED THREE TIMES TO COPY. SOMETHING IS WRONG WRONG WRONG.') | |
112 sys.exit(2) |