Skip to content
This repository has been archived by the owner on Jul 30, 2022. It is now read-only.

Commit

Permalink
Use / instead of - for the option prefix on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mhucka committed Jun 4, 2018
1 parent 09f641a commit 2a99024
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Turf (_TIND.io URL Fixer_) is a program to download records from the Caltech TIN

There are several hundred thousand records in [https://caltech.tind.io](https://caltech.tind.io). Some of the records contain links to other web resources. As a matter of regular maintenance, the links need to be checked periodically for validity, and preferably also updated to point to new destinations if the referenced resources have been relocated.

Turf is a small program that downloads records from [https://caltech.tind.io](https://caltech.tind.io), examines each one looking for URLs, deferences any found, and then finally prints a list of records together with old and new URLs. By default, if not given an explicit search string, Turf will do a search for all records that have one or more URLs in MARC field 856. Alternatively, it can be given a search query on the command line; in that case, the string should be a complete search URL as would be typed into a web browser address bar (or more practically, copied from the browser address bar after performing some exploratory searches in [https://caltech.tind.io](https://caltech.tind.io). Finally, as another alternative, it can read MARC XML input from a file when given the `-f` option.
Turf is a small program that downloads records from [https://caltech.tind.io](https://caltech.tind.io), examines each one looking for URLs, deferences any found, and then finally prints a list of records together with old and new URLs. By default, if not given an explicit search string, Turf will do a search for all records that have one or more URLs in MARC field 856. Alternatively, it can be given a search query on the command line; in that case, the string should be a complete search URL as would be typed into a web browser address bar (or more practically, copied from the browser address bar after performing some exploratory searches in [https://caltech.tind.io](https://caltech.tind.io). Finally, as another alternative, it can read MARC XML input from a file when given the `-f` option (`/f` on Windows).

✺ Installation instructions
---------------------------
Expand All @@ -36,7 +36,7 @@ Both of these installation approaches should automatically install some Python d
▶︎ Basic operation
------------------

Turf is a command-line application. On Linux and macOS systems, the installation _should_ place a new program on your shell's search path, so that you can start Turf with a simple shell command:
Turf is a command-line application. On Linux and macOS systems, the installation _should_ place a new program on your shell's search path, so that you can start Turf with a simple terminal command:
```
turf
```
Expand All @@ -56,14 +56,14 @@ When run without any arguments, Turf will execute a search in [https://caltech.t
turf 'https://caltech.tind.io/search?ln=en&p=856%3A%25&f=&sf=&so=d'
```

Turf won't write the results to a file unless told to do so using the `-o` option. It can write the results either in `.csv` or `.xlsx` format, and it inspects the file name to figure out which format to write. For example, the following will make it produce an Excel file as output:
Turf won't write the results to a file unless told to do so using the `-o` option (`/o` on Windows). It can write the results either in `.csv` or `.xlsx` format, and it inspects the file name to figure out which format to write. For example, the following will make it produce an Excel file as output:
```
turf -o results.xlsx
```

By default, Turf prints a message for every record it processes, so that the user can get a sense of what is happening. When told to save results to a file, however, it does _not_ write every record by default. Instead, by default, it saves only the records that contain URLs and for which the URLs are found to dereference to a different final destination. This behavior can be controlled via two flags, `-u` and `-a`. If given `-u`, Turf will write out records with URLs even if the URLs dereference to the same location. If given `-a`, Turf will write all records even if they don't have any URLs.
By default, Turf prints a message for every record it processes, so that the user can get a sense of what is happening. When told to save results to a file, however, it does _not_ write every record by default. Instead, by default, it saves only the records that contain URLs and for which the URLs are found to dereference to a different final destination. This behavior can be controlled via two flags, `-u` and `-a`. If given `-u` (`/u` on Windows), Turf will write out records with URLs even if the URLs dereference to the same location. If given `-a` (`/a` on Windows), Turf will write all records even if they don't have any URLs.

The difference between `-a` and `-u` is not evident from the default search performed by Turf because it only searches for records with URLs; however, the difference is easier to see when Turf is given a more general search such query such as the following
The difference between `-a` and `-u` (`/a` and `/u` on Windows) is not evident from the default search performed by Turf because it only searches for records with URLs; however, the difference is easier to see when Turf is given a more general search such query such as the following

```
https://caltech.tind.io/search?action_search=Search&rm=wrd&so=d
Expand All @@ -74,7 +74,7 @@ which will retrieve all records. The following screencast tries to demonstrate
[![demo](.graphics/turf-asciinema.png)](https://asciinema.org/a/kFvuHPMX51zhc95P1zDeqrmjQ)


Finally, the following table summarizes all the command line options available:
Finally, the following table summarizes all the command line options available. (Note: on Windows computers, `/` must be used instead of `-`):

| Short | Long form option | Meaning | Default |
|----------|---------------|----------------------|---------|
Expand Down
37 changes: 23 additions & 14 deletions turf/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
complete search URL as would be typed into a web browser address bar (or more
practically, copied from the browser address bar after performing some
exploratory searches in https://caltech.tind.io. Finally, as another
alternative, it can read MARC XML input from a file when given the -f option.
alternative, it can read MARC XML input from a file when given the -f option
(/f on Windows).
Authors
-------
Expand Down Expand Up @@ -77,28 +78,29 @@ def main(all=False, file=None, output=None, start_at='N', total='M',
on the command line, the string should be a complete search URL as would be
typed into a web browser address bar (or more practically, copied from the
browser address bar after performing some exploratory searches in
caltech.tind.io). If given a file using the -f option, the file should
contain MARC XML content.
caltech.tind.io). If given a file using the -f option (/f on Windows), the
file should contain MARC XML content.
By default, this program only writes out entries that have URLs in MARC field
856, and then only those whose URLs are found to dereference to a different
URL after following it. (That is, by default, it skips writing entries whose
URLs are not found to change after dereferencing.) If given the -u flag, it
will write out entries with URLs even if the URLs are unchanged after
dereferencing. If given the -a flag, it will write out all entries
retrieved, even those that have no URLs.
URLs are not found to change after dereferencing.) If given the -u flag
(/u on Windows), it will write out entries with URLs even if the URLs are
unchanged after dereferencing. If given the -a flag (/a on Windows), it will
write out all entries retrieved, even those that have no URLs.
If given the -t option, it will only fetch and process a total of that many
results instead of all results. If given the -s option, it will start at
that entry instead of starting at number 1; this is useful if searches are
being done in batches or a previous search is interrupted and you don't want
to restart from 1.
If given the -t option (/t on Windows), it will only fetch and process a total
of that many results instead of all results. If given the -s option, it will
start at that entry instead of starting at number 1; this is useful if searches
are being done in batches or a previous search is interrupted and you don't
want to restart from 1.
If given an output file, the results will be written to the file. The format
of the file will be deduced from the file name extension (.csv or .xlsx).
In the absence of a file name extension, it will default to XLSX format.
If not given an output file, the results will only be printed to the terminal.
'''
'''

# Our defaults are to do things like color the output, which means the
# command line flags make more sense as negated values (e.g., "nocolor").
Expand All @@ -123,7 +125,7 @@ def main(all=False, file=None, output=None, start_at='N', total='M',
raise SystemExit(color('"{}" does not appear to be an XML file'
.format(file), 'error', colorize))
if search:
if any(item.startswith('-') for item in search):
if any(item.startswith(('-', '/')) for item in search):
raise SystemExit(color('Command not recognized: {}'.format(search),
'error', colorize))
else:
Expand Down Expand Up @@ -183,6 +185,13 @@ def main(all=False, file=None, output=None, start_at='N', total='M',
if not quiet:
msg('Done.', 'info', colorize)


# If this is windows, we want the command-line args to use slash intead
# of hyphen.

if sys.platform.startswith('win'):
main.prefix_chars = '/'


# Miscellaneous utilities.
# ......................................................................
Expand Down

0 comments on commit 2a99024

Please sign in to comment.