Skip to content

Commit

Permalink
Updated readme, refactored proto files to new directory, updated comp…
Browse files Browse the repository at this point in the history
…iler and made it generate python package descriptor.
  • Loading branch information
AeonLucid committed Jul 20, 2016
1 parent 6481de7 commit 3682394
Show file tree
Hide file tree
Showing 226 changed files with 292 additions and 216 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@

# Protoc files
out/
tmp/
tmp/
/pogo/assist.py
*.pyc
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ Use `homebrew` to install `protobuf ` with `brew install --devel protobuf`.
There are two ways to compile **POGOProtos**.

### Single file compilation (Recommended)
Single file compilation merges every directory to it's own `.proto` file.
As an example:

- Networking/Requests/Messages/*.proto
- Networking/Responses/*.proto

Becomes:

- POGOProtos.**Networking.Requests.Messages.proto**
- POGOProtos.**Networking.Responses.proto**

These new files are then compiled by `protoc` and placed in the output directory. This greatly reduces the amount of output files.

#### Command

Run `python compile_single.py` to compile everything to a single file.

#### Flags
Expand All @@ -35,6 +50,11 @@ Run `python compile_single.py` to compile everything to a single file.
- Add the `-d` or `--desc_file` flag to only generate a descriptor file, `POGOProtos.desc` will be written to the specified output directory.

### Recursive compilation

Recursive compilation loops through all directories and compiles every `.proto` file it finds to the specified output directory.

#### Command

Run `python compile.py` to recursively compile everything.

#### Flags
Expand Down
18 changes: 11 additions & 7 deletions compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
import os
import shutil
from helpers import compile_helper
from subprocess import call


Expand Down Expand Up @@ -58,17 +59,22 @@ def query_yes_no(question, default="yes"):

# Determine where to store
proj_root = os.path.abspath("../")
proto_path = os.path.abspath("pogo/")
proto_path = os.path.abspath("src/")
out_path = os.path.abspath(out_path)
tmp_out_path = out_path

# Output dir is actually different csharp because we modify it before compiling.
if lang == "csharp":
tmp_out_path = os.path.join(tmp_out_path, "POGOProtos")

if not default_out_path:
print 'Can we remove "%s"?' % out_path
print 'Can we remove "%s"?' % tmp_out_path
may_remove = query_yes_no("Please answer.", default="no")
else:
may_remove = True

if may_remove and os.path.exists(out_path):
shutil.rmtree(out_path)
if may_remove and os.path.exists(tmp_out_path):
shutil.rmtree(tmp_out_path)

# Find protofiles and compile
for root, dirnames, filenames in os.walk(proto_path):
Expand Down Expand Up @@ -104,8 +110,6 @@ def query_yes_no(question, default="yes"):

call(command, shell=True)

if lang == 'python':
for root, dirnames, filenames in os.walk(out_path):
open(os.path.join(root, '__init__.py'), 'w').close()
compile_helper.finish_compile(out_path, lang)

print("Done!")
20 changes: 9 additions & 11 deletions compile_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import shutil
import re
from helpers import compile_helper
from subprocess import call

# Add this to your path
Expand All @@ -23,7 +24,7 @@
default_out_path = out_path == "out"

# Determine where to store
proto_path = os.path.abspath("pogo")
proto_path = os.path.abspath("src")
tmp_path = os.path.abspath("tmp")
out_path = os.path.abspath(out_path)

Expand Down Expand Up @@ -56,6 +57,12 @@ def walk_files(main_file, path, package, imports=None):
if imports is None:
imports = []

if package == "POGOProtos":
print("Can't compile..")
print("File: '%s'" % path)
print("Please place the file in 'src/POGOProtos/' in a sub-directory.")
exit()

main_file.write('syntax = "proto3";\n')
main_file.write('package %s;\n\n' % package)

Expand All @@ -82,12 +89,6 @@ def walk_files(main_file, path, package, imports=None):

import_from_package = import_from_package_re.group(2).replace("/", ".")

if import_from_package == "":
import_from_package = "POGOProtos"

if not import_from_package == "POGOProtos":
import_from_package = "POGOProtos." + import_from_package

if import_from_package not in imports:
imports.append(import_from_package)

Expand Down Expand Up @@ -150,10 +151,7 @@ def walk_directory(path):
)

call(command, shell=True)

if lang == 'python':
for root, dirnames, filenames in os.walk(os.path.join(out_path, "POGOProtos")):
open(os.path.join(root, '__init__.py'), 'w').close()
compile_helper.finish_compile(out_path, lang)


print("Done!")
Empty file added helpers/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions helpers/compile_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python

import os


def finish_compile(out_path, lang):
if lang == 'python':
pogo_protos_path = os.path.join(out_path, "POGOProtos")

for root, dirnames, filenames in os.walk(pogo_protos_path):
init_path = os.path.join(root, '__init__.py')

with open(init_path, 'w') as init_file:
if pogo_protos_path is root:
init_file.write("'Generated'; import os; import sys; sys.path.append(os.path.dirname(os.path.realpath(__file__)))")
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
syntax = "proto3";
package POGOProtos.Data.Battle;

import "Data/Battle/BattleResults.proto";
import "Data/Battle/BattleActionType.proto";
import "Data/Battle/BattleParticipant.proto";
import "POGOProtos/Data/Battle/BattleResults.proto";
import "POGOProtos/Data/Battle/BattleActionType.proto";
import "POGOProtos/Data/Battle/BattleParticipant.proto";

message BattleAction {
.POGOProtos.Data.Battle.BattleActionType Type = 1;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
syntax = "proto3";
package POGOProtos.Data.Battle;

import "Data/Battle/BattlePokemonInfo.proto";
import "Data/Battle/BattleState.proto";
import "Data/Battle/BattleType.proto";
import "Data/Battle/BattleAction.proto";
import "Data/Player/PlayerPublicProfile.proto";
import "POGOProtos/Data/Battle/BattleState.proto";
import "POGOProtos/Data/Battle/BattleType.proto";
import "POGOProtos/Data/Battle/BattleAction.proto";

message BattleLog {
.POGOProtos.Data.Battle.BattleState state = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
syntax = "proto3";
package POGOProtos.Data.Battle;

import "Data/Battle/BattlePokemonInfo.proto";
import "Data/Player/PlayerPublicProfile.proto";
import "POGOProtos/Data/Battle/BattlePokemonInfo.proto";
import "POGOProtos/Data/Player/PlayerPublicProfile.proto";

message BattleParticipant {
.POGOProtos.Data.Battle.BattlePokemonInfo active_pokemon = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package POGOProtos.Data.Battle;

import "Data/PokemonData.proto";
import "POGOProtos/Data/PokemonData.proto";

message BattlePokemonInfo {
.POGOProtos.Data.PokemonData pokemon_data = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
syntax = "proto3";
package POGOProtos.Data.Battle;

import "Data/Gym/GymState.proto";
import "Data/Battle/BattleActionType.proto";
import "Data/Battle/BattleParticipant.proto";
import "POGOProtos/Data/Gym/GymState.proto";
import "POGOProtos/Data/Battle/BattleParticipant.proto";

message BattleResults {
.POGOProtos.Data.Gym.GymState gym_state = 1;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package POGOProtos.Data.Capture;

import "Enums/ActivityType.proto";
import "POGOProtos/Enums/ActivityType.proto";

message CaptureAward {
repeated .POGOProtos.Enums.ActivityType activity_type = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package POGOProtos.Data.Capture;

import "Inventory/ItemId.proto";
import "POGOProtos/Inventory/ItemId.proto";

message CaptureProbability {
repeated .POGOProtos.Inventory.ItemId pokeball_type = 1;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
syntax = "proto3";
package POGOProtos.Data.Gym;

import "Data/PokemonData.proto";
import "Data/Player/PlayerPublicProfile.proto";
import "POGOProtos/Data/PokemonData.proto";
import "POGOProtos/Data/Player/PlayerPublicProfile.proto";

message GymMembership {
.POGOProtos.Data.PokemonData pokemon_data = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
syntax = "proto3";
package POGOProtos.Data.Gym;

import "Map/Fort/FortData.proto";
import "Data/Gym/GymMembership.proto";
import "POGOProtos/Map/Fort/FortData.proto";
import "POGOProtos/Data/Gym/GymMembership.proto";

message GymState {
.POGOProtos.Map.Fort.FortData fort_data = 1;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package POGOProtos.Data.Player;

import "Enums/BadgeType.proto";
import "POGOProtos/Enums/BadgeType.proto";

message EquippedBadge {
.POGOProtos.Enums.BadgeType badge_type = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package POGOProtos.Data.Player;

import "Enums/Gender.proto";
import "POGOProtos/Enums/Gender.proto";

message PlayerAvatar {
int32 skin = 2;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package POGOProtos.Data.Player;

import "Data/Player/PlayerAvatar.proto";
import "POGOProtos/Data/Player/PlayerAvatar.proto";

message PlayerPublicProfile {
string name = 1;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package POGOProtos.Data;

import "Enums/BadgeType.proto";
import "POGOProtos/Enums/BadgeType.proto";

message PlayerBadge {
.POGOProtos.Enums.BadgeType badge_type = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
syntax = "proto3";
package POGOProtos.Data;

import "Enums/TutorialState.proto";
import "Data/Player/PlayerAvatar.proto";
import "Data/Player/DailyBonus.proto";
import "Data/Player/EquippedBadge.proto";
import "Data/Player/ContactSettings.proto";
import "Data/Player/Currency.proto";
import "POGOProtos/Enums/TutorialState.proto";
import "POGOProtos/Data/Player/PlayerAvatar.proto";
import "POGOProtos/Data/Player/DailyBonus.proto";
import "POGOProtos/Data/Player/EquippedBadge.proto";
import "POGOProtos/Data/Player/ContactSettings.proto";
import "POGOProtos/Data/Player/Currency.proto";

message PlayerData {
int64 creation_timestamp_ms = 1;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
syntax = "proto3";
package POGOProtos.Data;

import "Enums/PokemonId.proto";
import "Enums/PokemonMove.proto";
import "POGOProtos/Enums/PokemonId.proto";
import "POGOProtos/Enums/PokemonMove.proto";

message PokemonData {
fixed64 id = 1;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
syntax = "proto3";
package POGOProtos.Inventory;

import "Inventory/ItemId.proto";
import "Inventory/ItemType.proto";
import "POGOProtos/Inventory/ItemId.proto";
import "POGOProtos/Inventory/ItemType.proto";

message AppliedItem {
.POGOProtos.Inventory.ItemId item_id = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package POGOProtos.Inventory;

import "Inventory/AppliedItem.proto";
import "POGOProtos/Inventory/AppliedItem.proto";

message AppliedItems {
repeated .POGOProtos.Inventory.AppliedItem item = 4;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
syntax = "proto3";
package POGOProtos.Inventory;

import "Inventory/ItemId.proto";
import "Inventory/EggIncubatorType.proto";
import "POGOProtos/Inventory/ItemId.proto";
import "POGOProtos/Inventory/EggIncubatorType.proto";

message EggIncubator {
string id = 1;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package POGOProtos.Inventory;

import "Inventory/EggIncubator.proto";
import "POGOProtos/Inventory/EggIncubator.proto";

message EggIncubators {
.POGOProtos.Inventory.EggIncubator egg_incubator = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package POGOProtos.Inventory;

import "Inventory/InventoryItem.proto";
import "POGOProtos/Inventory/InventoryItem.proto";

message InventoryDelta {
int64 original_timestamp_ms = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package POGOProtos.Inventory;

import "Inventory/InventoryItemData.proto";
import "POGOProtos/Inventory/InventoryItemData.proto";

message InventoryItem {
int64 modified_timestamp_ms = 1;
Expand Down
Loading

0 comments on commit 3682394

Please sign in to comment.