Kevin Veroneau avatar Kevin Veroneau committed c98141a Draft

Initial import of existing code.

Comments (0)

Files changed (2)

+import win32com.client
+
+class ProductStudio(object):
+    def __init__(self, product=''):
+        self.psdir = win32com.client.Dispatch("ProductStudio.Directory")
+        self.psdir.Connect("domain.com")
+        self.prod = self.psdir.GetProductByName(product)
+        self.ds = self.prod.Connect()
+    def query(self, psq):
+        q = win32com.client.Dispatch("ProductStudio.Query")
+        q.CountOnly = False
+        q.DatastoreItemType = -100
+        lst = win32com.client.Dispatch("ProductStudio.DataStoreItemList")
+        lst.Query = q
+        lst.Datastore = self.ds
+        q.SelectionCriteria = psq
+        fields = self.ds.FieldDefinitions
+        q.QueryFields.Clear()
+        q.QueryFields.Add(fields("Title"))
+        q.QuerySortFields.Add(fields("ID"), 0)
+        lst.Execute()
+        items = []
+        for item in lst.DatastoreItems:
+            items.append({'bugid':item.Fields("ID")(),
+                          'title':item.Fields("Title")(),
+                          'opened_by':item.Fields("Opened By")(),
+                          'status':item.Fields("Status")(),
+                          'created_on':item.Fields("Opened Date")()})
+        return items
+    def _equals(self, equals):
+        psq = ""
+        for column in equals:
+            psq += "<Expression Column='%s' Operator='equals'>" % column
+            psq += "<String>%s</String>" % equals[column]
+            psq += "</Expression>"
+        return psq
+    def make_query(self, equals={}):
+        psq = "<Query>"
+        if not isinstance(equals, dict):
+            psq += "<Group GroupOperator='or'>"
+            for row in equals:
+                psq += self._equals(row)
+            psq += "</Group>"
+        else:
+            psq += self._equals(equals)
+        psq += "</Query>"
+        return psq
+
+class Bug(object):
+    def __init__(self, datastore, path):
+        self.lst = win32com.client.Dispatch("ProductStudio.DataStoreItemList")
+        self.lst.Datastore = datastore
+        self.lst.CreateBlank(-100)
+        self.item = self.lst.DatastoreItems.Add()
+        self.fields = self.item.Fields
+        treeid = self._get_treeid(datastore.RootNode, path)
+        self.fields["TreeID"].Value = treeid
+    def __setitem__(self, key, value):
+        self.fields[key].Value = value
+    def __getitem__(self, key):
+        return self.fields[key].Value
+    def is_valid(self):
+        self.errors = []
+        for field in self.fields:
+            if field.Validity != 0:
+                self.errors.append(field.Name)
+        if self.errors != []:
+            return False
+        return True
+    def save(self):
+        if self.is_valid():
+            self.item.Save()
+            return self.fields["ID"].Value
+        return 0
+    def _get_treeid(self, node, path):
+        if len(path) == 0:
+            return node.ID
+        name = path.split("\\")[0]
+        for subnode in node.Nodes:
+            if subnode.Name == name:
+                try:
+                    subsub = path.split("\\", 1)[1]
+                except IndexError:
+                    return subnode.ID
+                return self._get_treeid(subnode, subsub)
+from setuptools import setup
+
+setup(name='python-productstudio', version='1.0',
+      description='Product Studio Python class',
+      author='Kevin Veroneau', author_email='kveroneau@gmail.com',
+      url='https://bitbucket.org/kveroneau/python-productstudio',
+      license='GPL',
+      description='A Python class to easily connect and work with Microsoft\'s Product Studio.',
+     )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.