Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions xfel/command_line/upload_mtz.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
.help = Id string of the destination folder. If the folder url is \
https://drive.google.com/drive/u/0/folders/1NlJkfL6CMd1NZIl6Duy23i4G1RM9cNH- , \
then the id is 1NlJkfL6CMd1NZIl6Duy23i4G1RM9cNH- .
lock_file = None
.type = path
.help = Path to lock file for coordinating concurrent uploads. \
If None, defaults to ~/.upload_mtz.lock. Set this to a writable location \
if the home directory is not accessible (e.g., on compute nodes).
}
input {
mtz_file = None
Expand Down Expand Up @@ -78,9 +83,14 @@ def _get_log_fname(mtz_fname):
class Locker:
""" See https://stackoverflow.com/a/60214222
"""
def __init__(self, lock_file_path=None):
if lock_file_path is None:
lock_file_path = os.path.expanduser('~/.upload_mtz.lock')
self.lock_file_path = lock_file_path

def __enter__(self):
try:
self.fp = open(os.path.expanduser('~/.upload_mtz.lock'), 'wb')
self.fp = open(self.lock_file_path, 'wb')
except FileNotFoundError:
self.fp = None
if fcntl and self.fp is not None:
Expand All @@ -98,7 +108,7 @@ class pydrive2_interface:
destination folder.
"""

def __init__(self, cred_file, folder_id):
def __init__(self, cred_file, folder_id, lock_file=None):
try:
from pydrive2.auth import ServiceAccountCredentials, GoogleAuth
from pydrive2.drive import GoogleDrive
Expand All @@ -111,11 +121,12 @@ def __init__(self, cred_file, folder_id):
)
self.drive = GoogleDrive(gauth)
self.top_folder_id = folder_id
self.lock_file = lock_file



def _fetch_or_create_folder(self, fname, parent_id):
with Locker():
with Locker(self.lock_file):
query = {
"q": "'{}' in parents and title='{}'".format(parent_id, fname),
"supportsTeamDrives": "true",
Expand Down Expand Up @@ -209,7 +220,8 @@ def run_with_preparsed(params):

drive = pydrive2_interface(
params.drive.credential_file,
params.drive.shared_folder_id
params.drive.shared_folder_id,
lock_file=params.drive.lock_file
)
folders = [dataset_root, version_str]
files = [log_path]
Expand Down
15 changes: 13 additions & 2 deletions xfel/ui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import absolute_import, division, print_function
import os
import os, sys
from iotbx.phil import parse
from libtbx.utils import Sorry

Expand Down Expand Up @@ -148,7 +148,6 @@
master_phil_scope = parse(master_phil_str + db_phil_str, process_includes=True)

settings_dir = os.path.join(os.path.expanduser('~'), '.cctbx.xfel')
settings_file = os.path.join(settings_dir, 'settings.phil')

known_dials_dispatchers = {
'cctbx.xfel.xtc_process': 'xfel.command_line.xtc_process',
Expand All @@ -167,6 +166,13 @@ def load_phil_scope_from_dispatcher(dispatcher):
return phil_scope

def load_cached_settings(scope=None, extract=True):
# Determine which settings file to use
settings_file = os.environ.get('CCTBX_XFEL_SETTINGS')
if settings_file is None:
settings_file = os.path.join(settings_dir, 'settings.phil')

print('Load settings from', settings_file)

if scope is None:
scope = master_phil_scope
if os.path.exists(settings_file):
Expand All @@ -186,6 +192,11 @@ def load_cached_settings(scope=None, extract=True):
return scope

def save_cached_settings(params):
# Save to the file specified by environment or default
settings_file = os.environ.get('CCTBX_XFEL_SETTINGS')
if settings_file is None:
settings_file = os.path.join(settings_dir, 'settings.phil')

if not os.path.exists(settings_dir):
os.makedirs(settings_dir)

Expand Down
2 changes: 2 additions & 0 deletions xfel/ui/components/submission_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ def __init__(self, queueing_system):
"queue interrogator not implemented for %s queueing system"%self.queueing_system)

def read_result(self, log_path):
if not log_path:
return "Error reading log file, no path to log"
result = easy_run.fully_buffered(command=self.command % log_path)
status = "\n".join(result.stdout_lines)
error = "\n".join(result.stderr_lines)
Expand Down
38 changes: 38 additions & 0 deletions xfel/ui/components/xfel_gui_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,44 @@ def __init__(self, parent,
output_box.AddGrowableCol(1, 1)
self.SetSizer(output_box)

class ComboButtonCtrl(CtrlBase):
''' Generic panel that will place a combo control, with a label and an
optional large button, and an optional bitmap button'''

def __init__(self, parent,
label='', label_size=(100, -1),
label_style='normal',
text_style=wx.TE_LEFT,
ctrl_size=(200, -1),
big_button=False,
big_button_label='Browse...',
big_button_size=wx.DefaultSize,
ghost_button=True,
value='', **kwargs):

CtrlBase.__init__(self, parent=parent, label_style=label_style, **kwargs)

output_box = wx.FlexGridSizer(1, 4, 0, 10)
self.txt = wx.StaticText(self, label=label, size=label_size)
self.txt.SetFont(self.font)
output_box.Add(self.txt)

self.ctr = wx.ComboBox(self, name=self.Name + "_ctr", style=text_style, size=ctrl_size)
self.ctr.SetValue(value)
output_box.Add(self.ctr, flag=wx.EXPAND)

self.btn_big = Button(self, name=self.Name + "_btn_big", label=big_button_label, size=big_button_size)
if ghost_button:
output_box.Add(self.btn_big, flag=wx.RESERVE_SPACE_EVEN_IF_HIDDEN)
else:
output_box.Add(self.btn_big)

if not big_button:
self.btn_big.Hide()

output_box.AddGrowableCol(1, 1)
self.SetSizer(output_box)

class TwoButtonCtrl(CtrlBase):
''' Generic panel that will place a text control, with a label and an
optional large button, and an optional bitmap button'''
Expand Down
Loading
Loading