Skip to content

Commit

Permalink
Merge pull request #46 from mytardis/develop
Browse files Browse the repository at this point in the history
Merging into master for v0.5.5 release.
  • Loading branch information
wettenhj authored Jun 12, 2016
2 parents ffc0a40 + ce5e1dc commit e597f22
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 23 deletions.
Binary file modified docs/source/images/SettingsFilters.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/source/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ Filters
is advisable to instruct MyData to ignore old datasets so that it focus on
uploading the recent datasets.

**Ignore files newer than**
MyData can ignore recently modified files. MyTardis does not yet support
file versioning, so once a file has been uploaded and verified, it will not
be replaced by a newer version. Therefore, it is important to ensure that
a file doesn't get uploaded while it is still being modified.

.. _settings-dialog-advanced:

Expand Down
2 changes: 1 addition & 1 deletion mydata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
import sys

__version__ = "0.5.5-beta1"
__version__ = "0.5.5"


try:
Expand Down
9 changes: 7 additions & 2 deletions mydata/controllers/uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ def Run(self):
dataFileDirectory = \
self.folderModel.GetDataFileDirectory(self.dataFileIndex)

thirtySeconds = 30
if (time.time() - os.path.getmtime(dataFilePath)) <= thirtySeconds:
ignoreNewFiles = self.settingsModel.IgnoreNewFiles()
ignoreNewFilesMinutes = self.settingsModel.GetIgnoreNewFilesMinutes()
ignoreNewFilesSeconds = 0
if ignoreNewFiles:
ignoreNewFilesSeconds = ignoreNewFilesMinutes * 60
if (time.time() - os.path.getmtime(dataFilePath)) <= \
ignoreNewFilesSeconds:
message = "Not uploading file, in case it is still being modified."
logger.warning(message.replace('file', dataFilePath))
self.uploadModel.SetMessage(message)
Expand Down
37 changes: 24 additions & 13 deletions mydata/media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ def __init__(self):
self.iconsCache = {}

# pylint: disable=too-many-arguments
def GetIcon(self, name, vendor="Aha-Soft", style=IconStyle.NORMAL,
size=None, extension=None):
def GetIconPath(self, name, vendor="Aha-Soft", style=IconStyle.NORMAL,
size=None, extension=None):
"""
Get path to icon.
"""
if not size:
size = self.defaultIconSize
cacheKey = '%s-%s-%s' % (name, IconStyle.STRINGS[style], size)
if style == IconStyle.NORMAL:
iconStyleFolderName = "png-normal"
elif style == IconStyle.HOT:
Expand All @@ -67,21 +66,33 @@ def GetIcon(self, name, vendor="Aha-Soft", style=IconStyle.NORMAL,
else:
raise Exception("Unsupported icon style was requested: %s"
% IconStyle.STRINGS[style])
iconSubdir = "icons" + size
if vendor == "Aha-Soft":
return os.path.join(self.mediaPath, vendor, iconStyleFolderName,
iconSubdir, "%s.png" % name)
else:
if not extension:
extension = "ico"
return os.path.join(self.mediaPath, "%s.%s" % (name, extension))

# pylint: disable=too-many-arguments
def GetIcon(self, name, vendor="Aha-Soft", style=IconStyle.NORMAL,
size=None, extension=None):
"""
Get icon, possibly from cache.
"""
if not size:
size = self.defaultIconSize
cacheKey = '%s-%s-%s' % (name, IconStyle.STRINGS[style], size)
iconPath = self.GetIconPath(name, vendor, style, size, extension)

if cacheKey not in self.iconsCache:
iconSubdir = "icons" + size
if vendor == "Aha-Soft":
self.iconsCache[cacheKey] = \
wx.Image(os.path.join(self.mediaPath, vendor,
iconStyleFolderName,
iconSubdir, "%s.png" % name),
wx.BITMAP_TYPE_PNG).ConvertToBitmap()
wx.Image(iconPath, wx.BITMAP_TYPE_PNG).ConvertToBitmap()
else:
if not extension:
extension = "ico"
self.iconsCache[cacheKey] = \
wx.Image(os.path.join(self.mediaPath,
"%s.%s" % (name, extension)),
wx.BITMAP_TYPE_ANY).ConvertToBitmap()
wx.Image(iconPath, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
return self.iconsCache[cacheKey]

MYDATA_ICONS = Icons()
41 changes: 36 additions & 5 deletions mydata/models/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def __init__(self, configPath):
self.ignore_old_datasets = False
self.ignore_interval_number = 0
self.ignore_interval_unit = "months"
self.ignore_new_files = True
self.ignore_new_files_minutes = 1

self.folder_structure = "Username / Dataset"
self.dataset_grouping = ""
Expand Down Expand Up @@ -208,6 +210,8 @@ def LoadSettings(self, configPath=None, checkForUpdates=True):
self.ignore_old_datasets = False
self.ignore_interval_number = 0
self.ignore_interval_unit = "months"
self.ignore_new_files = True
self.ignore_new_files_minutes = 1

# Advanced tab
self.folder_structure = "Username / Dataset"
Expand Down Expand Up @@ -263,6 +267,16 @@ def LoadSettings(self, configPath=None, checkForUpdates=True):
self.ignore_interval_number = \
configParser.getint(configFileSection,
"ignore_interval_number")
if configParser.has_option(configFileSection,
"ignore_new_files"):
self.ignore_new_files = \
configParser.getboolean(configFileSection,
"ignore_new_files")
if configParser.has_option(configFileSection,
"ignore_new_files_minutes"):
self.ignore_new_files_minutes = \
configParser.getint(configFileSection,
"ignore_new_files_minutes")
if configParser.has_option(configFileSection,
"max_upload_threads"):
self.max_upload_threads = \
Expand Down Expand Up @@ -363,7 +377,7 @@ def LoadSettings(self, configPath=None, checkForUpdates=True):
for setting in settingsFromServer:
self.__dict__[setting['key']] = setting['value']
if setting['key'] in (
"ignore_old_datasets",
"ignore_old_datasets", "ignore_new_files",
"validate_folder_structure",
"start_automatically_on_login",
"upload_invalid_user_folders",
Expand All @@ -376,6 +390,7 @@ def LoadSettings(self, configPath=None, checkForUpdates=True):
(setting['value'] == "True")
if setting['key'] in (
"timer_minutes", "ignore_interval_number",
"ignore_new_files_minutes",
"max_upload_threads", "max_upload_retries"):
self.__dict__[setting['key']] = int(setting['value'])
if setting['key'] in (
Expand Down Expand Up @@ -638,6 +653,18 @@ def GetIgnoreOldDatasetIntervalUnit(self):
def SetIgnoreOldDatasetIntervalUnit(self, ignoreOldDatasetIntervalUnit):
self.ignore_interval_unit = ignoreOldDatasetIntervalUnit

def IgnoreNewFiles(self):
return self.ignore_new_files

def SetIgnoreNewFiles(self, ignoreNewFiles):
self.ignore_new_files = ignoreNewFiles

def GetIgnoreNewFilesMinutes(self):
return self.ignore_new_files_minutes

def SetIgnoreNewFilesMinutes(self, ignoreNewFilesMinutes):
self.ignore_new_files_minutes = ignoreNewFilesMinutes

def GetMaxUploadThreads(self):
return self.max_upload_threads

Expand Down Expand Up @@ -712,8 +739,9 @@ def SaveToDisk(self, configPath=None):
"folder_structure",
"dataset_grouping", "group_prefix",
"ignore_old_datasets", "ignore_interval_number",
"ignore_interval_unit", "max_upload_threads",
"max_upload_retries",
"ignore_interval_unit",
"ignore_new_files", "ignore_new_files_minutes",
"max_upload_threads", "max_upload_retries",
"validate_folder_structure", "locked", "uuid",
"start_automatically_on_login",
"upload_invalid_user_folders"]
Expand Down Expand Up @@ -764,8 +792,9 @@ def SaveFieldsFromDialog(self, settingsDialog, configPath=None,
settingsDialog.GetIgnoreOldDatasetIntervalNumber())
self.SetIgnoreOldDatasetIntervalUnit(
settingsDialog.GetIgnoreOldDatasetIntervalUnit())
self.SetMaxUploadThreads(settingsDialog.GetMaxUploadThreads())
self.SetMaxUploadRetries(settingsDialog.GetMaxUploadRetries())
self.SetIgnoreNewFiles(settingsDialog.IgnoreNewFiles())
self.SetIgnoreNewFilesMinutes(
settingsDialog.GetIgnoreNewFilesMinutes())

# Advanced tab
self.SetFolderStructure(settingsDialog.GetFolderStructure())
Expand All @@ -777,6 +806,8 @@ def SaveFieldsFromDialog(self, settingsDialog, configPath=None,
settingsDialog.StartAutomaticallyOnLogin())
self.SetUploadInvalidUserFolders(
settingsDialog.UploadInvalidUserFolders())
self.SetMaxUploadThreads(settingsDialog.GetMaxUploadThreads())
self.SetMaxUploadRetries(settingsDialog.GetMaxUploadRetries())

self.SetLocked(settingsDialog.Locked())

Expand Down
2 changes: 1 addition & 1 deletion mydata/models/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def GetActiveNetworkInterfaces():
if match and currentInterface:
activeInterfaces.append(currentInterface)
elif sys.platform.startswith("linux"):
proc = subprocess.Popen(["route"],
proc = subprocess.Popen(["/sbin/route"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
startupinfo=DEFAULT_STARTUP_INFO,
Expand Down
4 changes: 3 additions & 1 deletion mydata/utils/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import wx

from mydata.logs import logger
from mydata.media import MYDATA_ICONS


# pylint: disable=too-few-public-methods
Expand All @@ -26,7 +27,8 @@ def Notify(message, subtitle=None, title="MyData"):
return
if sys.platform.startswith("linux"):
try:
args = ["MyData", message]
icon = MYDATA_ICONS.GetIconPath("favicon", vendor="MyTardis")
args = ["-i", icon, title, message]
proc = subprocess.Popen(["notify-send"] + args,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
Expand Down
80 changes: 80 additions & 0 deletions mydata/views/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Disabling some Pylint checks for now...
# pylint: disable=missing-docstring
# pylint: disable=too-many-lines
# pylint: disable=too-many-statements
# pylint: disable=no-member

from datetime import datetime
Expand Down Expand Up @@ -573,6 +574,37 @@ def __init__(self, parent,
self.filtersPanelSizer.Add(wx.StaticText(self.filtersPanel,
wx.ID_ANY, ""))

self.ignoreFilesNewerThanCheckBox = \
wx.CheckBox(self.filtersPanel, wx.ID_ANY,
"Ignore files newer than:")
self.Bind(wx.EVT_CHECKBOX, self.OnIgnoreNewFilesCheckBox,
self.ignoreFilesNewerThanCheckBox)
self.filtersPanelSizer.Add(self.ignoreFilesNewerThanCheckBox,
flag=wx.ALIGN_RIGHT | wx.ALL, border=5)

self.ignoreFilesIntervalPanel = wx.Panel(self.filtersPanel)
self.ignoreFilesPanelSizer = wx.BoxSizer(wx.HORIZONTAL)
self.ignoreFilesIntervalPanel.SetSizer(self.ignoreFilesPanelSizer)

self.ignoreFilesNewerThanSpinCtrl = \
wx.SpinCtrl(self.ignoreFilesIntervalPanel, wx.ID_ANY,
"1", min=0, max=999)
self.Bind(wx.EVT_SPINCTRL, self.OnIgnoreNewFilesSpinCtrl,
self.ignoreFilesNewerThanSpinCtrl)
self.ignoreFilesNewerThanSpinCtrl.Enable(False)
self.ignoreFilesPanelSizer.Add(self.ignoreFilesNewerThanSpinCtrl,
flag=wx.EXPAND | wx.ALL, border=5)
self.showingSingularMinutes = True
self.ignoreFilesIntervalUnitLabel = \
wx.StaticText(self.ignoreFilesIntervalPanel, wx.ID_ANY, "minute")
self.ignoreFilesPanelSizer.Add(self.ignoreFilesIntervalUnitLabel,
flag=wx.EXPAND | wx.ALL, border=5)

self.filtersPanelSizer.Add(self.ignoreFilesIntervalPanel, flag=wx.EXPAND,
border=5)
self.filtersPanelSizer.Add(wx.StaticText(self.filtersPanel,
wx.ID_ANY, ""))

self.filtersPanel.Fit()
self.settingsTabsNotebook.AddPage(self.filtersPanel, "Filters")

Expand Down Expand Up @@ -999,6 +1031,18 @@ def GetIgnoreOldDatasetIntervalUnit(self):
def SetIgnoreOldDatasetIntervalUnit(self, ignoreOldDatasetIntervalUnit):
self.intervalUnitsComboBox.SetValue(ignoreOldDatasetIntervalUnit)

def IgnoreNewFiles(self):
return self.ignoreFilesNewerThanCheckBox.GetValue()

def SetIgnoreNewFiles(self, ignoreNewFiles):
self.ignoreFilesNewerThanCheckBox.SetValue(ignoreNewFiles)

def GetIgnoreNewFilesMinutes(self):
return self.ignoreFilesNewerThanSpinCtrl.GetValue()

def SetIgnoreNewFilesMinutes(self, ignoreNewFilesMinutes):
self.ignoreFilesNewerThanSpinCtrl.SetValue(ignoreNewFilesMinutes)

# Advanced tab

def GetFolderStructure(self):
Expand Down Expand Up @@ -1154,6 +1198,16 @@ def UpdateFieldsFromModel(self, settingsModel):
self.showingSingularUnits = True
self.SetIgnoreOldDatasetIntervalUnit(
settingsModel.GetIgnoreOldDatasetIntervalUnit())
self.SetIgnoreNewFiles(settingsModel.IgnoreNewFiles())
self.SetIgnoreNewFilesMinutes(settingsModel.GetIgnoreNewFilesMinutes())
if settingsModel.IgnoreNewFiles():
self.ignoreFilesNewerThanSpinCtrl.Enable(True)
if int(settingsModel.GetIgnoreNewFilesMinutes()) == 1:
self.showingSingularMinutes = True
self.ignoreFilesIntervalUnitLabel.SetLabel("minute")
else:
self.showingSingularMinutes = False
self.ignoreFilesIntervalUnitLabel.SetLabel("minutes")

# Advanced tab
self.SetFolderStructure(settingsModel.GetFolderStructure())
Expand Down Expand Up @@ -1254,6 +1308,32 @@ def OnIgnoreOldDatasetsSpinCtrl(self, event):
self.showingSingularUnits = False
event.Skip()

def OnIgnoreNewFilesCheckBox(self, event):
if event.IsChecked():
self.ignoreFilesNewerThanSpinCtrl.SetValue(1)
self.ignoreFilesNewerThanSpinCtrl.Enable(True)
if not self.showingSingularMinutes:
self.showingSingularMinutes = True
self.ignoreFilesIntervalUnitLabel.SetLabel("minute")
else:
self.ignoreFilesNewerThanSpinCtrl.SetValue(0)
self.ignoreFilesNewerThanSpinCtrl.Enable(False)
if not self.showingSingularMinutes:
self.showingSingularMinutes = False
self.ignoreFilesIntervalUnitLabel.SetLabel("minutes")
event.Skip()

def OnIgnoreNewFilesSpinCtrl(self, event):
if event.GetInt() == 1:
if not self.showingSingularMinutes:
self.ignoreFilesIntervalUnitLabel.SetLabel("minute")
self.showingSingularMinutes = True
else:
if self.showingSingularMinutes:
self.ignoreFilesIntervalUnitLabel.SetLabel("minutes")
self.showingSingularMinutes = False
event.Skip()

# pylint: disable=no-self-use
def OnHelp(self, event):
"""
Expand Down

0 comments on commit e597f22

Please sign in to comment.