Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mantidproject
mantid
Commits
7fb7b1d5
Commit
7fb7b1d5
authored
9 years ago
by
Alex Buts
Browse files
Options
Downloads
Patches
Plain Diff
Re #11886 Should fix unit test on Unix
and better logic behind replacing sample file.
parent
55038a04
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Mantid/scripts/Inelastic/Direct/ISISDirecInelasticConfig.py
+16
-18
16 additions, 18 deletions
...ntid/scripts/Inelastic/Direct/ISISDirecInelasticConfig.py
Code/Mantid/scripts/test/ISISDirecInelasticConfigTest.py
+8
-5
8 additions, 5 deletions
Code/Mantid/scripts/test/ISISDirecInelasticConfigTest.py
with
24 additions
and
23 deletions
Code/Mantid/scripts/Inelastic/Direct/ISISDirecInelasticConfig.py
+
16
−
18
View file @
7fb7b1d5
...
...
@@ -4,6 +4,7 @@ import shutil
import
re
import
copy
from
datetime
import
date
import
time
# the list of instruments this configuration is applicable to
INELASTIC_INSTRUMENTS
=
[
'
MAPS
'
,
'
LET
'
,
'
MERLIN
'
,
'
MARI
'
,
'
HET
'
]
...
...
@@ -207,34 +208,26 @@ class MantidConfigDirectInelastic(object):
#
def
script_need_replacing
(
self
,
source_script_name
,
target_script_name
):
"""
Method specifies conditions when existing reduction file should be replaced
by sample file
by
a
sample file
.
"""
if
self
.
_force_change_script
:
return
True
#
m
is
s
ing file should always be replaced
#
non-ex
is
t
ing file should always be replaced
if
not
os
.
path
.
isfile
(
target_script_name
):
return
True
# if user already started -- do not replace his config
#except when changes are forced
now_is
=
date
.
today
()
#Always replace sample file if it has not been touched
start_date
=
self
.
_user
.
get_start_date
()
if
now_is
>
start_date
:
return
False
#
time_targ
=
os
.
path
.
getmtime
(
target_script_name
)
time_source
=
os
.
path
.
getmtime
(
source_script_name
)
# we may want better granularity in a future
# source_mod_date = date.fromtimestamp(time_source)
# targ_mod_date = date.fromtimestamp(time_targ)
if
time_targ
<
time_source
:
# this time is set up to the file, copied from the repository
sample_file_time
=
time
.
mktime
(
start_date
.
timetuple
())
targ_file_time
=
os
.
path
.
getmtime
(
target_script_name
)
if
sample_file_time
==
targ_file_time
:
return
True
else
:
else
:
# somebody have modified the target file. Leave it alone
return
False
#
def
copy_reduction_sample
(
self
,
InstrName
,
CycleID
,
rb_folder
):
"""
Method copies sample reduction script from user script repository
to user folder.
"""
Method copies sample reduction script from user script repository
to user folder.
"""
source_file
=
self
.
_sample_reduction_file
(
InstrName
)
...
...
@@ -254,8 +247,13 @@ class MantidConfigDirectInelastic(object):
os
.
remove
(
full_target
)
shutil
.
copyfile
(
full_source
,
full_target
)
os
.
chmod
(
full_target
,
0777
)
if
platform
.
system
()
!=
'
Windows
'
:
os
.
system
(
'
chown
'
+
self
.
_fedid
+
'
:
'
+
self
.
_fedid
+
'
'
+
full_target
)
# Set up the file creation and modification dates to the users start date
start_date
=
self
.
_user
.
get_start_date
()
file_time
=
time
.
mktime
(
start_date
.
timetuple
())
os
.
utime
(
full_target
,(
file_time
,
file_time
))
def
get_data_folder_name
(
self
,
instr
,
cycle_ID
):
...
...
This diff is collapsed.
Click to expand it.
Code/Mantid/scripts/test/ISISDirecInelasticConfigTest.py
+
8
−
5
View file @
7fb7b1d5
...
...
@@ -227,7 +227,7 @@ class ISISDirectInelasticConfigTest(unittest.TestCase):
os
.
makedirs
(
user1RootDir
)
#
user1
=
UserProperties
()
user1
.
set_user_properties
(
'
MARI
'
,
'
39
990124
'
,
'
CYCLE
39
991
'
,
rbdir2
)
user1
.
set_user_properties
(
'
MARI
'
,
'
20
990124
'
,
'
CYCLE
20
991
'
,
rbdir2
)
mcf
.
init_user
(
user1ID
,
user1
)
source_file
=
self
.
makeFakeSourceReductionFile
(
mcf
)
...
...
@@ -247,11 +247,14 @@ class ISISDirectInelasticConfigTest(unittest.TestCase):
target_file
=
mcf
.
_target_reduction_file
(
instr
,
cycle_id
)
full_target_file
=
os
.
path
.
join
(
full_rb_path
,
target_file
)
self
.
assertTrue
(
os
.
path
.
exists
(
full_target_file
))
# target file does not need replacing
# Fresh target file should always be replaced
self
.
assertTrue
(
mcf
.
script_need_replacing
(
source_file
,
full_target_file
))
# modify target file access time:
access_time
=
os
.
path
.
getmtime
(
full_target_file
)
now
=
time
.
time
()
os
.
utime
(
full_target_file
,(
access_time
,
now
))
# should not replace modified target file
self
.
assertFalse
(
mcf
.
script_need_replacing
(
source_file
,
full_target_file
))
# make new fake configuration file
new_source
=
self
.
makeFakeSourceReductionFile
(
mcf
,
'
New
'
)
self
.
assertTrue
(
mcf
.
script_need_replacing
(
new_source
,
full_target_file
))
#--------------------------------------------------------------------
# clean up
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment