Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

""" 

LibGAP Workspace Support 

 

The single purpose of this module is to provide the location of the 

libgap saved workspace and a time stamp to invalidate saved 

workspaces. 

""" 

 

import os 

import glob 

from sage.env import GAP_ROOT_DIR 

from sage.interfaces.gap import GAP_BINARY 

from sage.interfaces.gap_workspace import gap_workspace_file 

 

 

def timestamp(): 

""" 

Return a time stamp for (lib)gap 

 

OUTPUT: 

 

Float. Unix timestamp of the most recently changed GAP/LibGAP file(s). In particular, the 

timestamp increases whenever a gap package is added. 

 

EXAMPLES:: 

 

sage: from sage.libs.gap.saved_workspace import timestamp 

sage: timestamp() # random output 

1406642467.25684 

sage: type(timestamp()) 

<... 'float'> 

""" 

libgap_dir = os.path.dirname(__file__) 

libgap_files = glob.glob(os.path.join(libgap_dir, '*')) 

gap_packages = glob.glob(os.path.join(GAP_ROOT_DIR, 'pkg', '*')) 

files = libgap_files + [GAP_BINARY] + gap_packages 

if len(files) == 0: 

print('Unable to find LibGAP files.') 

return float('inf') 

return max(map(os.path.getmtime, files)) 

 

 

def workspace(name='workspace'): 

""" 

Return the filename of the gap workspace and whether it is up to date. 

 

INPUT: 

 

- ``name`` -- string. A name that will become part of the 

workspace filename. 

 

OUTPUT: 

 

Pair consisting of a string and a boolean. The string is the 

filename of the saved libgap workspace (or that it should have if 

it doesn't exist). The boolean is whether the workspace is 

up-to-date. You may use the workspace file only if the boolean is 

``True``. 

 

EXAMPLES:: 

 

sage: from sage.libs.gap.saved_workspace import workspace 

sage: ws, up_to_date = workspace() 

sage: ws 

'/.../gap/libgap-workspace-...' 

sage: isinstance(up_to_date, bool) 

True 

""" 

workspace = gap_workspace_file("libgap", name) 

try: 

workspace_mtime = os.path.getmtime(workspace) 

except OSError: 

# workspace does not exist 

return (workspace, False) 

return (workspace, workspace_mtime >= timestamp())