Skip to content

Commit d5e1f5b

Browse files
committed
mass reformatting
1 parent 91a06b9 commit d5e1f5b

File tree

72 files changed

+8549
-8286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+8549
-8286
lines changed

load.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,49 @@
1212

1313
isCommit = re.compile("^[0-9a-fA-F]{40}$")
1414

15-
HEADERS = {
16-
'User-Agent': 'cwlviewer-load/0.0.1',
17-
'Accept': 'application/json'
18-
}
15+
HEADERS = {"User-Agent": "cwlviewer-load/0.0.1", "Accept": "application/json"}
1916

2017

2118
def parse_gitinfos(sourceFp):
2219
doc = json.load(sourceFp)
2320
for wf in doc["content"]:
2421
yield wf["retrievedFrom"]
2522

23+
2624
def is_not_commit(gitinfo):
2725
return not isCommit.match(gitinfo["branch"])
2826

27+
2928
def make_requests(gitinfos):
3029
for git in gitinfos:
3130
# dict_keys(['repoUrl', 'branch', 'path', 'packedId', 'url', 'rawUrl', 'type'])
32-
req = {
33-
"url": git["repoUrl"],
34-
"branch": git["branch"],
35-
"path": git["path"]
36-
}
31+
req = {"url": git["repoUrl"], "branch": git["branch"], "path": git["path"]}
3732
if git["packedId"]:
3833
req["packedId"] = git["packedId"]
3934
yield req
4035

36+
4137
def send(base, req):
4238
url = urljoin(base, "/workflows")
4339
r = requests.post(url, data=req, allow_redirects=False, headers=HEADERS)
44-
print("Posted: %s" % req)
40+
print("Posted: %s" % req, file=sys.stderr)
4541
if r.status_code == 202:
46-
location = urljoin(url, r.headers["Location"])
47-
print(" queued: %s" % location)
42+
location = urljoin(url, r.headers["Location"])
43+
print(" queued: %s" % location, file=sys.stderr)
4844
# need to check later
4945
return location
5046
if r.status_code == 303:
51-
print (" done: %s" % r.headers["Location"])
52-
return None # Already there, all OK
53-
print("Unhandled HTTP status code: %s %s" %
54-
(r.status_code, r.text))
47+
print(" done: %s" % r.headers["Location"], file=sys.stderr)
48+
return None # Already there, all OK
49+
print(f"Unhandled HTTP status code: {r.status_code} {r.text}", file=sys.stderr)
50+
print(req)
51+
5552

5653
def send_requests(base, requests):
5754
for req in requests:
5855
yield send(base, req)
5956

57+
6058
def is_running(location):
6159
if not location:
6260
return True
@@ -68,23 +66,26 @@ def is_running(location):
6866
if j["cwltoolStatus"] == "RUNNING":
6967
return True
7068
elif j["cwltoolStatus"] == "ERROR":
71-
print("Failed %s: %s" % (location, j["message"]))
69+
print(f"Failed {location}: {j['message']}", file=sys.stderr)
7270
return False
7371
else:
74-
raise Exception("Unhandled queue status: %s %s" % (queued.status_code, queued.text))
72+
raise Exception(f"Unhandled queue status: {queued.status_code} {queued.text}")
73+
7574

76-
MAX_CONCURRENT=6 # Maximum number in queue
77-
SLEEP=0.5 # wait SLEEP seconds if queue is full
75+
MAX_CONCURRENT = 2 # Maximum number in queue
76+
SLEEP = 0.5 # wait SLEEP seconds if queue is full
7877

79-
def trim_queue(queue):
78+
79+
def trim_queue(queue):
8080
new_queue = []
8181
for q in queue:
8282
if is_running(q):
83-
#print("Still running %s" % q)
83+
# print("Still running %s" % q)
8484
new_queue.append(q)
85-
print("Trimmed queue from %s to %s" % (len(queue), len(new_queue)))
85+
print(f"Trimmed queue from {len(queue)} to {len(new_queue)}", file=sys.stderr)
8686
return new_queue
8787

88+
8889
def main(jsonfile="-", base="http://view.commonwl.org:8082/", *args):
8990
if jsonfile == "-":
9091
source = sys.stdin
@@ -96,23 +97,23 @@ def main(jsonfile="-", base="http://view.commonwl.org:8082/", *args):
9697
gitinfos = parse_gitinfos(source)
9798
if "--no-commits" in args:
9899
gitinfos = filter(is_not_commit, gitinfos)
99-
100+
100101
requests = make_requests(gitinfos)
101102
queued = []
102103
for q in send_requests(base, requests):
103104
if q:
104-
queued.append(q)
105+
queued.append(q)
105106
while len(queued) >= MAX_CONCURRENT:
106107
time.sleep(SLEEP)
107-
queued = trim_queue(queued)
108+
queued = trim_queue(queued)
108109
# Finish the rest of the queue
109110
while queued:
110111
queued = trim_queue(queued)
111112

113+
112114
if __name__ == "__main__":
113115
if "-h" in sys.argv:
114116
print("load.py [jsonfile] [baseurl] [--no-commits]")
115117
sys.exit(1)
116118

117119
main(*sys.argv[1:])
118-

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@
214214
</execution>
215215
</executions>
216216
</plugin>
217+
<plugin>
218+
<groupId>com.spotify.fmt</groupId>
219+
<artifactId>fmt-maven-plugin</artifactId>
220+
<version>2.19</version>
221+
<executions>
222+
<execution>
223+
<goals>
224+
<goal>format</goal>
225+
</goals>
226+
</execution>
227+
</executions>
228+
</plugin>
217229
</plugins>
218230
</build>
219231

src/main/java/org/commonwl/view/CwlViewerApplication.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
@EnableTransactionManagement
3232
public class CwlViewerApplication {
3333

34-
public static void main(String[] args) {
35-
SpringApplication.run(CwlViewerApplication.class, args);
36-
}
37-
}
34+
public static void main(String[] args) {
35+
SpringApplication.run(CwlViewerApplication.class, args);
36+
}
37+
}

src/main/java/org/commonwl/view/GlobalControllerErrorHandling.java

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.commonwl.view;
2121

2222
import java.util.Collections;
23-
2423
import org.commonwl.view.workflow.MultipleWorkflowsException;
2524
import org.commonwl.view.workflow.RepresentationNotFoundException;
2625
import org.commonwl.view.workflow.WorkflowNotFoundException;
@@ -33,51 +32,53 @@
3332

3433
/**
3534
* Handles exception handling across the application.
36-
* <p>
37-
* Because of Spring Boot's content negotiation these handlers are needed when
38-
* the error is returned with an otherwise "non acceptable" content type (e.g.
39-
* Accept: image/svg+xml but we have to say 404 Not Found)
4035
*
36+
* <p>Because of Spring Boot's content negotiation these handlers are needed when the error is
37+
* returned with an otherwise "non acceptable" content type (e.g. Accept: image/svg+xml but we have
38+
* to say 404 Not Found)
4139
*/
4240
@ControllerAdvice
4341
public class GlobalControllerErrorHandling {
4442

45-
/**
46-
* Workflow can not be found
47-
* @return A plain text error message
48-
*/
49-
@ExceptionHandler(WorkflowNotFoundException.class)
50-
public ResponseEntity<?> handleNotFound() {
51-
final HttpHeaders headers = new HttpHeaders();
52-
headers.setContentType(MediaType.TEXT_PLAIN);
53-
return new ResponseEntity<>("Workflow or git commit could not be found", headers, HttpStatus.NOT_FOUND);
54-
}
55-
56-
/**
57-
* More than one workflow (or workflow parts) found
58-
*
59-
* @return A text/uri-list of potential representations
60-
*/
61-
@ExceptionHandler(MultipleWorkflowsException.class)
62-
public ResponseEntity<?> handleMultipleWorkflows(MultipleWorkflowsException ex) {
63-
final HttpHeaders headers = new HttpHeaders();
64-
headers.setContentType(MediaType.parseMediaType("text/uri-list"));
65-
return new ResponseEntity<>(ex.toString(), headers, HttpStatus.MULTIPLE_CHOICES);
66-
}
43+
/**
44+
* Workflow can not be found
45+
*
46+
* @return A plain text error message
47+
*/
48+
@ExceptionHandler(WorkflowNotFoundException.class)
49+
public ResponseEntity<?> handleNotFound() {
50+
final HttpHeaders headers = new HttpHeaders();
51+
headers.setContentType(MediaType.TEXT_PLAIN);
52+
return new ResponseEntity<>(
53+
"Workflow or git commit could not be found", headers, HttpStatus.NOT_FOUND);
54+
}
6755

68-
/**
69-
* Workflow exists but representation is not found eg Generic git workflow
70-
* asking for raw workflow URL
71-
*
72-
* @return A plain text error message
73-
*/
74-
@ExceptionHandler(RepresentationNotFoundException.class)
75-
public ResponseEntity<?> handleNoRepresentation() {
76-
final HttpHeaders headers = new HttpHeaders();
77-
headers.setVary(Collections.singletonList("Accept"));
78-
headers.setContentType(MediaType.TEXT_PLAIN);
79-
return new ResponseEntity<>("The workflow exists but the requested representation could not be found",
80-
headers, HttpStatus.NOT_ACCEPTABLE);
81-
}
56+
/**
57+
* More than one workflow (or workflow parts) found
58+
*
59+
* @return A text/uri-list of potential representations
60+
*/
61+
@ExceptionHandler(MultipleWorkflowsException.class)
62+
public ResponseEntity<?> handleMultipleWorkflows(MultipleWorkflowsException ex) {
63+
final HttpHeaders headers = new HttpHeaders();
64+
headers.setContentType(MediaType.parseMediaType("text/uri-list"));
65+
return new ResponseEntity<>(ex.toString(), headers, HttpStatus.MULTIPLE_CHOICES);
66+
}
8267

68+
/**
69+
* Workflow exists but representation is not found eg Generic git workflow asking for raw workflow
70+
* URL
71+
*
72+
* @return A plain text error message
73+
*/
74+
@ExceptionHandler(RepresentationNotFoundException.class)
75+
public ResponseEntity<?> handleNoRepresentation() {
76+
final HttpHeaders headers = new HttpHeaders();
77+
headers.setVary(Collections.singletonList("Accept"));
78+
headers.setContentType(MediaType.TEXT_PLAIN);
79+
return new ResponseEntity<>(
80+
"The workflow exists but the requested representation could not be found",
81+
headers,
82+
HttpStatus.NOT_ACCEPTABLE);
83+
}
8384
}

src/main/java/org/commonwl/view/PageController.java

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,38 @@
2828
@Controller
2929
public class PageController {
3030

31-
/**
32-
* Main page of the application
33-
* @param model The model for the home page where the workflow form is added
34-
* @return The view for this page
35-
*/
36-
@GetMapping("/")
37-
public String homePage(Model model, @RequestParam(value = "url", required = false) String defaultURL) {
38-
model.addAttribute("workflowForm", new WorkflowForm(defaultURL));
39-
return "index";
40-
}
31+
/**
32+
* Main page of the application
33+
*
34+
* @param model The model for the home page where the workflow form is added
35+
* @return The view for this page
36+
*/
37+
@GetMapping("/")
38+
public String homePage(
39+
Model model, @RequestParam(value = "url", required = false) String defaultURL) {
40+
model.addAttribute("workflowForm", new WorkflowForm(defaultURL));
41+
return "index";
42+
}
4143

42-
/**
43-
* About page
44-
* @param model The model for the about page
45-
* @return The view for this page
46-
*/
47-
@GetMapping("/about")
48-
public String about(Model model) {
49-
return "about";
50-
}
51-
52-
/**
53-
* API documentation page
54-
* @param model The model for the API documentation page
55-
* @return The view for this page
56-
*/
57-
@GetMapping("/apidocs")
58-
public String apiDocumentation(Model model) {
59-
return "apidocs";
60-
}
44+
/**
45+
* About page
46+
*
47+
* @param model The model for the about page
48+
* @return The view for this page
49+
*/
50+
@GetMapping("/about")
51+
public String about(Model model) {
52+
return "about";
53+
}
6154

55+
/**
56+
* API documentation page
57+
*
58+
* @param model The model for the API documentation page
59+
* @return The view for this page
60+
*/
61+
@GetMapping("/apidocs")
62+
public String apiDocumentation(Model model) {
63+
return "apidocs";
64+
}
6265
}

0 commit comments

Comments
 (0)