#!/usr/bin/python

# Importing globOS because linux sucks, wow that was a bad one.
import glob, os, sys

def main():
    args = sys.argv

    if len(args) > 1:
        print(args[1])
        test = symlink()
        test.scan()
        test.parse()
        test.filter(args[1])



    else:
        symlink.help()
        

class symlink:

    def scan(self):

        # Look for symlinkfiles inside the directories
        symlinkFiles = glob.glob('./*/.symlinks')

        paths = []

        # Loop through the symlinkfiles and parse them
        for symlinkFile in symlinkFiles:
            
            # Get the absolute path for the symlink (Bash convention)
            path = os.path.abspath(symlinkFile)

            # Print the path (Can't be bothered to remove some debugging stuff right now, since I'm still 
            #print(path)
            paths.append(path)

        # Save pathsIf y
        self.paths = paths

        return (paths)

    def parse(self, paths=False):
        
        # Check if there are paths provided
        if not paths:
            paths = self.paths

        self.links = []


        # Loop over the paths
        for path in paths:

            # Get the absolute base path for the directory
            baseDir = os.path.split (path)[0] + '/'

            # Open the symlink file
            content = open(path, 'r').read()

            # Split the big blob of text into seperate rule we can parse
            symlinks = content.split('\n')[0:-1]


            # Loop through the rules and parse them
            for symlink in symlinks:
                users = []
                if symlink.find('|') != -1:
                    s = symlink.split('|')
                    print (s)
                    link = s[0]
                    
                    if s[1].find(',') != -1:
                        for user in s[1].split(','):
                            users.append(user.lower)

                else:
                    link = symlink


                if link.find('=>'):
                    
                    # Split the symlink into a file and destination
                    s = link.split('=>')

                    # Get the absolute path, without the home directory refered to as ~. (Bash convention)
                    file = os.path.abspath(os.path.expanduser(os.path.join(baseDir, s[0])))
                    dest = os.path.abspath(os.path.expanduser(s[1]))

                    self.links.append((file, dest, users))

        return self.links

    def filter(self, user):
        links = []
        for link in self.links:
            if user.lower in link[2] or not len(link[2]) > 0:
                links.append(link)
                print('Yes')
            else:
                print('No')

            print(link)

        self.links = links

        print (self.links)
        
        return links


    def link(self):

        # If the destination doesn't exist yet, create the symlink
        if not os.path.lexists(dest):

            # Debug code
            print ('Linking ' + file + ' to ' + dest)

            # Finally create the symlink
            os.symlink(file, dest) 
        else:

            # Throw a nice error
            print ('File already exists')
            print ('--------------------')


    def help():
        print ('Lorem')


# Call the middle function
if __name__ == "__main__":
        main()


@@ -1577,24 +1577,25 @@
 n symlinks:%0A
+%0A
             
@@ -1613,51 +1613,173 @@
  %5B%5D%0A
-                if symlink.find('%7C') != -1:
+%0A                # Check if there is an %22%7C%22 indicating that there are users%0A                if symlink.find('%7C') != -1:%0A%0A                    # Split the user part of
 %0A   
@@ -1817,16 +1817,50 @@
 lit('%7C')
+%0A%0A                    # Debug code
 %0A       
@@ -1882,16 +1882,17 @@
 int (s)%0A
+%0A
         
@@ -1960,37 +1960,56 @@
     
-if s%5B1%5D.find(',') != -1:%0A    
+# Loop over all users and add them to the array%0A
     
@@ -2073,28 +2073,24 @@
             
-    
 users.append
@@ -2100,16 +2100,18 @@
 er.lower
+()
 )%0A%0A     
@@ -2791,16 +2791,18 @@
 er.lower
+()
  in link
@@ -3007,17 +3007,16 @@
    print
- 
 (self.li

Fix the profile system