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

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

""" 

:Author: Daniel Mohr 

:Email: daniel.mohr@dlr.de 

:Date: 2021-03-09, 2021-07-01, 2021-12-06 (last change). 

:License: GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007. 

""" 

 

import argparse 

import getpass 

import os 

import os.path 

import tempfile 

 

 

def argument_parser(): 

""" 

:Author: Daniel Mohr 

:Email: daniel.mohr@dlr.de 

:Date: 2021-12-06 (last change). 

""" 

epilog = "" 

epilog += "Author: Daniel Mohr\n" 

epilog += "Date: 2021-07-01\n" 

epilog += "License: GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007." 

epilog += "\n\n" 

description = 'json_schema_from_schema_org is a script ' \ 

'to define json-ld based on schema.org as a json schema.' 

parser = argparse.ArgumentParser( 

description=description, 

epilog=epilog, 

formatter_class=argparse.RawDescriptionHelpFormatter) 

parser.add_argument( 

'vocabulary', 

nargs='+', 

type=str, 

help='For these words from schema.org the output is generated.', 

metavar='word') 

parser.add_argument( 

'-indent', 

nargs=1, 

type=int, 

required=False, 

default=[4], 

dest='indent', 

help='In the output the elements will be indented ' + 

'by this number of spaces. default: 4', 

metavar='i') 

cachefilename = 'schemaorg-current-https.jsonld.bz2' 

parser.add_argument( 

'-cachefilename', 

nargs=1, 

type=str, 

required=False, 

default=[cachefilename], 

dest='cachefilename', 

help='We need data from schema.org. ' 

'If you set cachefilename to an empty string, nothing is cached. ' 

'If the file ends with common extension for compression, ' 

'this comperession is used (e. g.: .gz, .lzma, .xz, .bz2). ' 

'The file is created in the cachefilepath (see this option). ' 

'default: "%s"' % cachefilename, 

metavar='f') 

cachefilepath = os.path.join( 

tempfile.gettempdir(), 

'json_schema_from_schema_org_' + getpass.getuser()) 

parser.add_argument( 

'-cachefilepath', 

nargs=1, 

type=str, 

required=False, 

default=[cachefilepath], 

dest='cachefilepath', 

help='This path is used for the cachefilename. ' 

'If necessary, this directory will be created ' 

'(not the directory tree!). ' 

'default: "%s"' % cachefilepath, 

metavar='p') 

return parser