# No shebang line, this module is meant to be imported
#
# Copyright 2014 Ambient Entertainment GmbH & Co. KG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Path Map Model
==============

Model for path maps, allowing for OS-dependent mapping of path prefixes to other
path prefixes.
"""

from pyfarm.master.application import db
from pyfarm.models.core.mixins import ReprMixin, UtilityMixins
from pyfarm.models.core.types import id_column
from pyfarm.models.core.cfg import (
    TABLE_PATH_MAP, MAX_PATH_LENGTH, TABLE_TAG)

class PathMap(db.Model, ReprMixin, UtilityMixins):
    __tablename__ = TABLE_PATH_MAP
    id = id_column(db.Integer)
    path_linux = db.Column(db.String(MAX_PATH_LENGTH), nullable=False,
                           doc="The path on linux platforms")
    path_windows = db.Column(db.String(MAX_PATH_LENGTH), nullable=False,
                             doc="The path on Windows platforms")
    path_osx = db.Column(db.String(MAX_PATH_LENGTH), nullable=False,
                         doc="The path on Mac OS X platforms")
    tag_id = db.Column(db.Integer,
                       db.ForeignKey("%s.id" % TABLE_TAG),
                       nullable=True,
                       doc="The tag an agent needs to have for this path map "
                           "to apply to it. "
                           "If this is NULL, this path map applies to all "
                           "agents, but is overridden by applying path maps "
                           "that do specify a tag.")
    tag = db.relationship("Tag",
                          backref=db.backref("path_maps", lazy="dynamic"),
                          doc="Relationship attribute for the tag this path map "
                              "applies to.")

@@ -103,18 +103,49 @@
  Co. KG%0A
+# Copyright 2015 Oliver Palmer%0A
 #%0A
-
 # Licens
@@ -1104,16 +1104,109 @@
 ixins):%0A
+    %22%22%22%0A    Defines a table which is used for cross-platform%0A    file path mappings.%0A    %22%22%22%0A
     __ta
@@ -1232,16 +1232,17 @@
 ATH_MAP%0A
+%0A
     id =
@@ -1264,16 +1264,17 @@
 nteger)%0A
+%0A
     path
@@ -1284,32 +1284,41 @@
 nux = db.Column(
+%0A        
 db.String(MAX_PA
@@ -1320,32 +1320,40 @@
 AX_PATH_LENGTH),
+%0A       
  nullable=False,
@@ -1353,35 +1353,16 @@
 =False,%0A
-                   
         
@@ -1388,32 +1388,33 @@
 nux platforms%22)%0A
+%0A
     path_windows
@@ -1418,32 +1418,41 @@
 ows = db.Column(
+%0A        
 db.String(MAX_PA
@@ -1454,32 +1454,40 @@
 AX_PATH_LENGTH),
+%0A       
  nullable=False,
@@ -1487,37 +1487,16 @@
 =False,%0A
-                     
         
@@ -1528,24 +1528,25 @@
 platforms%22)%0A
+%0A
     path_osx
@@ -1558,16 +1558,25 @@
 .Column(
+%0A        
 db.Strin
@@ -1594,16 +1594,24 @@
 LENGTH),
+%0A       
  nullabl
@@ -1619,33 +1619,16 @@
 =False,%0A
-                 
         
@@ -1665,16 +1665,17 @@
 forms%22)%0A
+%0A
     tag_
@@ -1685,24 +1685,33 @@
 = db.Column(
+%0A        
 db.Integer,%0A
@@ -1710,31 +1710,16 @@
 nteger,%0A
-               
         
@@ -1754,31 +1754,16 @@
 E_TAG),%0A
-               
         
@@ -1777,31 +1777,16 @@
 e=True,%0A
-               
         
@@ -1837,39 +1837,24 @@
  path map %22%0A
-               
             
@@ -1872,31 +1872,16 @@
 o it. %22%0A
-               
         
@@ -1933,31 +1933,16 @@
 o all %22%0A
-               
         
@@ -2008,31 +2008,16 @@
         
-       
-        
 %22that do
@@ -2038,22 +2038,22 @@
 .%22)%0A
+%0A
     
-tag = db.r
+#%0A    # R
 elat
@@ -2063,34 +2063,51 @@
 ship
-(%22Tag%22,
+s
 %0A    
+#%0A
     
-  
+tag = db.relationship(%0A
         
     
@@ -2094,32 +2094,39 @@
 onship(%0A        
+%22Tag%22,%0A
         backref=
@@ -2166,34 +2166,16 @@
 amic%22),%0A
-                  
         
@@ -2230,34 +2230,16 @@
 h map %22%0A
-                  
         

reformat PathMap